Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
marco76tv committed Oct 3, 2024
1 parent 87f8728 commit ed8d810
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 102 deletions.
5 changes: 3 additions & 2 deletions Actions/SaveTransAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Modules\Lang\Actions;

use Exception;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\File;
use Modules\Xot\Actions\Array\SaveArrayAction;
Expand All @@ -24,14 +25,14 @@ public function execute(string $key, int|string|array|null $data): void
$cont = [];
}
$piece = implode('.', array_slice(explode('.', $key), 1));
if ('' !== $piece) {
if ($piece !== '') {
Arr::set($cont, $piece, $data);
} else {
$cont = $data;
}

if (! is_array($cont)) {
throw new \Exception('Error in SaveTransAction');
throw new Exception('Error in SaveTransAction');
}

app(SaveArrayAction::class)->execute(data: $cont, filename: $filename);
Expand Down
16 changes: 8 additions & 8 deletions Casts/LangField.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class LangField implements CastsAttributes
/**
* Cast the given value.
*
* @param BaseModelLang $model
* @param string $key
* @param array $attributes
* @param BaseModelLang $model
* @param string $key
* @param array $attributes
*/
public function get($model, $key, $value, $attributes)
{
Expand All @@ -24,11 +24,11 @@ public function get($model, $key, $value, $attributes)
/**
* Prepare the given value for storage.
*
* @param BaseModelLang $model
* @param string $key
* @param array $attributes
* @param string $key
* @param string $value
* @param BaseModelLang $model
* @param string $key
* @param array $attributes
* @param string $key
* @param string $value
*/
public function set($model, $key, $value, $attributes): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
/*
* Class CreateLangPostsTable.
*/
return new class extends XotBaseMigration {
return new class extends XotBaseMigration
{
protected ?string $model_class = Post::class;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
/*
* Class CreateTranslationsTable.
*/
return new class extends XotBaseMigration {
return new class extends XotBaseMigration
{
// protected ?string $model_class = Post::class;
/**
* db up.
Expand Down
7 changes: 4 additions & 3 deletions Datas/TranslationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Modules\Lang\Datas;

use Exception;
use Illuminate\Support\Facades\File;
use Spatie\LaravelData\Data;

Expand All @@ -25,8 +26,8 @@ public function getFilename(): string
{
$hints = app('translator')->getLoader()->namespaces();
$path = collect($hints)->get($this->namespace);
if (null === $path) {
throw new \Exception('['.__LINE__.']['.class_basename($this).']');
if ($path === null) {
throw new Exception('['.__LINE__.']['.class_basename($this).']');
}

return app(\Modules\Xot\Actions\File\FixPathAction::class)->execute($path.'/'.$this->lang.'/'.$this->group.'.php');
Expand All @@ -40,7 +41,7 @@ public function getData(): array
$data = File::getRequire($filename);
}
if (! is_array($data)) {
throw new \Exception('['.__LINE__.']['.class_basename($this).']');
throw new Exception('['.__LINE__.']['.class_basename($this).']');
}

return $data;
Expand Down
2 changes: 1 addition & 1 deletion Http/Livewire/Lang/Change.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function mount(): void
$this->url = Request::getRequestUri();
$langs = Arr::map($langs, function (array $item, $key) {
$url = LaravelLocalization::getLocalizedURL($key, $this->url, [], true);
if (false !== $url) {
if ($url !== false) {
$url = Str::of($url)->replace(url(''), '')->toString();
}
$item['url'] = $url;
Expand Down
2 changes: 1 addition & 1 deletion Models/Contracts/HasTranslationsContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface HasTranslationsContract
public function getTranslation(string $key, string $locale, bool $useFallbackLocale = true): mixed;

/**
* @param int|array|string|null $value
* @param int|array|string|null $value
*/
public function setTranslation(string $key, string $locale, $value): self;
}
74 changes: 38 additions & 36 deletions Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,43 @@
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;

use function is_string;

/**
* Modules\Lang\Models\Post.
*
* @property int $id
* @property int|null $user_id
* @property string|null $post_type
* @property int|null $post_id
* @property string|null $lang
* @property string|null $title
* @property string|null $subtitle
* @property string|null $guid
* @property string|null $txt
* @property string|null $image_src
* @property string|null $image_alt
* @property string|null $image_title
* @property string|null $meta_description
* @property string|null $meta_keywords
* @property int|null $author_id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property int|null $category_id
* @property string|null $image
* @property string|null $content
* @property int|null $published
* @property string|null $created_by
* @property string|null $updated_by
* @property string|null $url
* @property array|null $url_lang
* @property array|null $image_resize_src
* @property string|null $linked_count
* @property string|null $related_count
* @property string|null $relatedrev_count
* @property string|null $linkable_type
* @property int|null $views_count
* @property Model|\Eloquent $linkable
* @property int $id
* @property int|null $user_id
* @property string|null $post_type
* @property int|null $post_id
* @property string|null $lang
* @property string|null $title
* @property string|null $subtitle
* @property string|null $guid
* @property string|null $txt
* @property string|null $image_src
* @property string|null $image_alt
* @property string|null $image_title
* @property string|null $meta_description
* @property string|null $meta_keywords
* @property int|null $author_id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property int|null $category_id
* @property string|null $image
* @property string|null $content
* @property int|null $published
* @property string|null $created_by
* @property string|null $updated_by
* @property string|null $url
* @property array|null $url_lang
* @property array|null $image_resize_src
* @property string|null $linked_count
* @property string|null $related_count
* @property string|null $relatedrev_count
* @property string|null $linkable_type
* @property int|null $views_count
* @property Model|Eloquent $linkable
*
* @method static Builder|Post newModelQuery()
* @method static Builder|Post newQuery()
Expand Down Expand Up @@ -214,7 +216,7 @@ public function setTitleAttribute(string $value): void
*/
public function getTitleAttribute(?string $value): ?string
{
if (null !== $value) {
if ($value !== null) {
return $value;
}

Expand All @@ -236,14 +238,14 @@ public function getTitleAttribute(?string $value): ?string
*/
public function getGuidAttribute(?string $value): ?string
{
if (\is_string($value) && '' !== $value && ! str_contains($value, ' ')) {
if (is_string($value) && $value !== '' && ! str_contains($value, ' ')) {
return $value;
}
$value = $this->title;
if ('' === $value) {
if ($value === '') {
$value = $this->attributes['post_type'].' '.$this->attributes['post_id'];
}
if (null === $value) {
if ($value === null) {
$value = 'u-'.random_int(1, 1000);
}
$value = Str::slug($value);
Expand Down
6 changes: 2 additions & 4 deletions Models/Traits/LinkedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
* Modules\Lang\Models\Traits\LinkedTrait.
*
* @property \Modules\Xot\Contracts\UserContract|null $user
* @property Post $post
* @property Post $post
*/
trait LinkedTrait
{
}
trait LinkedTrait {}
44 changes: 22 additions & 22 deletions Models/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,35 @@
/**
* Modules\Lang\Models\Translation.
*
* @property int $id
* @property int $id
* @property string|null $lang
* @property string|null $key
* @property string|null $value
* @property string|null $created_by
* @property string|null $updated_by
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property string $namespace
* @property string $group
* @property string $namespace
* @property string $group
* @property string|null $item
*
* @method static \Illuminate\Database\Eloquent\Builder|Translation newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Translation newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Translation ofTranslatedGroup(string $group)
* @method static \Illuminate\Database\Eloquent\Builder|Translation orderByGroupKeys(bool $ordered)
* @method static \Illuminate\Database\Eloquent\Builder|Translation query()
* @method static \Illuminate\Database\Eloquent\Builder|Translation selectDistinctGroup()
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereCreatedBy($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereGroup($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereItem($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereKey($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereLang($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereNamespace($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereUpdatedBy($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereValue($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Translation newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Translation ofTranslatedGroup(string $group)
* @method static \Illuminate\Database\Eloquent\Builder|Translation orderByGroupKeys(bool $ordered)
* @method static \Illuminate\Database\Eloquent\Builder|Translation query()
* @method static \Illuminate\Database\Eloquent\Builder|Translation selectDistinctGroup()
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereCreatedBy($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereGroup($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereItem($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereKey($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereLang($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereNamespace($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereUpdatedBy($value)
* @method static \Illuminate\Database\Eloquent\Builder|Translation whereValue($value)
* @method static \Modules\Lang\Database\Factories\TranslationFactory factory($count = null, $state = [])
*
* @property \Modules\Xot\Contracts\ProfileContract|null $creator
Expand Down Expand Up @@ -83,12 +83,12 @@ public function scopeOrderByGroupKeys(EloquentBuilder $query, bool $ordered): El

public function scopeSelectDistinctGroup(EloquentBuilder $query): EloquentBuilder|QueryBuilder
{
$select = match (\DB::getDriverName()) {
$select = match (DB::getDriverName()) {
'mysql' => 'DISTINCT `group`',
default => 'DISTINCT "group"',
};

return $query->select(\DB::raw($select));
return $query->select(DB::raw($select));
}

/*
Expand Down
4 changes: 1 addition & 3 deletions Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,5 @@ class EventServiceProvider extends BaseEventServiceProvider
/**
* Configure the proper event listeners for email verification.
*/
protected function configureEmailVerification(): void
{
}
protected function configureEmailVerification(): void {}
}
9 changes: 6 additions & 3 deletions Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Modules\Xot\Providers\XotBaseRouteServiceProvider;

use function in_array;
use function is_array;

class RouteServiceProvider extends XotBaseRouteServiceProvider
{
/**
Expand All @@ -30,7 +33,7 @@ public function registerCallback(): void
public function registerLang(): void
{
$locales = config('laravellocalization.supportedLocales');
if (! \is_array($locales)) {
if (! is_array($locales)) {
$locales = ['it' => 'it', 'en' => 'en'];
}
$langs = array_keys($locales);
Expand All @@ -46,9 +49,9 @@ public function registerLang(): void
$n = 3;
}

if (\in_array(request()->segment($n), $langs, false)) {
if (in_array(request()->segment($n), $langs, false)) {
$lang = request()->segment($n);
if (null !== $lang) {
if ($lang !== null) {
app()->setLocale($lang);
}
}
Expand Down
10 changes: 4 additions & 6 deletions Services/TranslatorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ class TranslatorService extends LaravelTranslator
/**
* Get the translation for the given key.
*
* @param string $key
* @param string|null $locale
* @param bool $fallback
*
* @param string $key
* @param string|null $locale
* @param bool $fallback
* @return string|array
*/
public function get($key, array $replace = [], $locale = null, $fallback = true)
Expand All @@ -49,8 +48,7 @@ public function setTranslationManager(Manager $manager)
/**
* Undocumented function.
*
* @param string $key
*
* @param string $key
* @return void
*/
protected function notifyMissingKey($key)
Expand Down
4 changes: 1 addition & 3 deletions View/Components/Flag.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
*/
class Flag extends Component
{
public function __construct(public string $name)
{
}
public function __construct(public string $name) {}

public function render(): Renderable
{
Expand Down
Loading

0 comments on commit ed8d810

Please sign in to comment.