Skip to content

Commit

Permalink
Merge pull request #3 from Laravel-Lang/1.x
Browse files Browse the repository at this point in the history
Optimized imports
  • Loading branch information
andrey-helldar authored Jun 22, 2024
2 parents 0e2e913 + bbcd303 commit dd9f27c
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/Casts/TrimCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;

use function is_bool;
use function is_null;
use function is_numeric;
use function trim;

class TrimCast implements CastsAttributes
{
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
Expand Down
3 changes: 3 additions & 0 deletions src/Concerns/HasStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace LaravelLang\Models\Concerns;

use function is_string;
use function trim;

trait HasStrings
{
protected function trim(mixed $value): mixed
Expand Down
4 changes: 4 additions & 0 deletions src/Console/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
use LaravelLang\Models\Services\ClassMap;
use Symfony\Component\Console\Attribute\AsCommand;

use function array_filter;
use function array_merge;
use function class_exists;
use function compact;
use function Laravel\Prompts\info;
use function Laravel\Prompts\search;
use function Laravel\Prompts\text;
Expand Down
2 changes: 2 additions & 0 deletions src/Console/ModelsHelperCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use LaravelLang\Models\Services\ClassMap;
use Symfony\Component\Console\Attribute\AsCommand;

use function ltrim;

#[AsCommand(name: 'lang:models:helper')]
class ModelsHelperCommand extends Command
{
Expand Down
6 changes: 3 additions & 3 deletions src/Eloquent/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

use Illuminate\Database\Eloquent\Model;

use function array_filter;

abstract class Translation extends Model
{
public $timestamps = false;

public function translatable(): array
{
return array_filter($this->getFillable(), function (string $column) {
return $column !== 'locale';
});
return array_filter($this->getFillable(), fn (string $column) => $column !== 'locale');
}

protected function casts(): array
Expand Down
3 changes: 3 additions & 0 deletions src/Exceptions/AttributeIsNotTranslatableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Exception;
use Illuminate\Database\Eloquent\Model;

use function implode;
use function sprintf;

class AttributeIsNotTranslatableException extends Exception
{
public function __construct(string $column, Model $model)
Expand Down
2 changes: 2 additions & 0 deletions src/Exceptions/UnavailableLocaleException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use LaravelLang\LocaleList\Locale;
use LaravelLang\Locales\Facades\Locales;

use function sprintf;

class UnavailableLocaleException extends Exception
{
public function __construct(Locale|string|null $locale)
Expand Down
6 changes: 6 additions & 0 deletions src/Generators/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
use LaravelLang\Config\Facades\Config;
use LaravelLang\Models\Eloquent\Translation;

use function collect;
use function file_get_contents;
use function implode;
use function is_array;
use function ltrim;

abstract class Generator
{
protected string $stub;
Expand Down
4 changes: 4 additions & 0 deletions src/Generators/HelperGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use Illuminate\Support\Str;
use LaravelLang\Config\Facades\Config;

use function array_map;
use function md5;
use function sprintf;

class HelperGenerator extends Generator
{
protected string $stub = __DIR__ . '/../../stubs/helper.stub';
Expand Down
5 changes: 5 additions & 0 deletions src/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace LaravelLang\Models\Generators;

use function array_map;
use function database_path;
use function date;
use function sprintf;

class MigrationGenerator extends Generator
{
protected string $stub = __DIR__ . '/../../stubs/migration.stub';
Expand Down
4 changes: 4 additions & 0 deletions src/Generators/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use DragonCode\Support\Facades\Filesystem\Path;
use LaravelLang\Models\Services\ClassMap;

use function array_map;
use function dirname;
use function sprintf;

class ModelGenerator extends Generator
{
protected string $stub = __DIR__ . '/../../stubs/model.stub';
Expand Down
5 changes: 4 additions & 1 deletion src/HasTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
use LaravelLang\Models\Services\Registry;
use LaravelLang\Models\Services\Relation;

use function filled;
use function in_array;
use function is_iterable;

/**
* @mixin \Illuminate\Database\Eloquent\Concerns\HasAttributes
* @mixin \Illuminate\Database\Eloquent\Model
Expand All @@ -29,7 +33,6 @@ trait HasTranslations
public static function bootHasTranslations(): void
{
static::saved(function (Model $model) {
// @var HasTranslations|Model $model
Relation::resolveKey($model);

$model->translations?->each?->save();
Expand Down
3 changes: 3 additions & 0 deletions src/Services/ClassMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use LaravelLang\Config\Facades\Config;
use LaravelLang\Models\HasTranslations;

use function collect;
use function ltrim;

class ClassMap
{
public static function get(): array
Expand Down
3 changes: 3 additions & 0 deletions src/Services/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use LaravelLang\Config\Facades\Config;
use LaravelLang\Models\Eloquent\Translation;

use function blank;
use function get_class;

class Relation
{
public static function initialize(Model $model): Model
Expand Down

0 comments on commit dd9f27c

Please sign in to comment.