Skip to content

Commit

Permalink
fix php cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Apr 17, 2024
1 parent ad60f1b commit c6a850c
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 319 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
},
"require-dev": {
"laravel/legacy-factories": "^1.0.4",
"laravel/pint": "^1.15",
"mockery/mockery": "^1.3.3",
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit": "^9.0 || ^10.5"
Expand Down
4 changes: 2 additions & 2 deletions src/Translatable/Contracts/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getDefaultLocale(): ?string;

public function getNewTranslation(string $locale): Model;

public function getTranslation(?string $locale = null, bool $withFallback = null): ?Model;
public function getTranslation(?string $locale = null, ?bool $withFallback = null): ?Model;

public function getTranslationOrNew(?string $locale = null): Model;

Expand All @@ -34,7 +34,7 @@ public function hasTranslation(?string $locale = null): bool;

public function isTranslationAttribute(string $key): bool;

public function replicateWithTranslations(array $except = null): Model;
public function replicateWithTranslations(?array $except = null): Model;

public function setDefaultLocale(?string $locale);

Expand Down
6 changes: 3 additions & 3 deletions src/Translatable/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
trait Translatable
{
use Scopes, Relationship;
use Relationship, Scopes;

protected static $autoloadTranslations = null;

Expand Down Expand Up @@ -186,7 +186,7 @@ public function getNewTranslation(string $locale): Model
return $translation;
}

public function getTranslation(?string $locale = null, bool $withFallback = null): ?Model
public function getTranslation(?string $locale = null, ?bool $withFallback = null): ?Model
{
$configFallbackLocale = $this->getFallbackLocale();
$locale = $locale ?: $this->locale();
Expand Down Expand Up @@ -279,7 +279,7 @@ public function isTranslationAttribute(string $key): bool
return in_array($key, $this->translatedAttributes);
}

public function replicateWithTranslations(array $except = null): Model
public function replicateWithTranslations(?array $except = null): Model
{
$newInstance = $this->replicate($except);

Expand Down
3 changes: 2 additions & 1 deletion src/Translatable/Validation/RuleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class RuleFactory
{
const FORMAT_ARRAY = 1;

const FORMAT_KEY = 2;

/**
Expand Down Expand Up @@ -77,6 +78,7 @@ public function parse(array $input): array
foreach ($input as $key => $value) {
if (! $this->isTranslatable($key)) {
$rules[$key] = $value;

continue;
}

Expand All @@ -94,7 +96,6 @@ protected function formatKey(string $locale, string $key): string
}

/**
* @param string $locale
* @param string|string[]|mixed $rule
* @return string|string[]|mixed
*/
Expand Down
3 changes: 1 addition & 2 deletions tests/Eloquent/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class Country extends Eloquent implements TranslatableContract
/**
* This is the foreign key used to define the translation relationship.
* Set this if you want to overwrite the laravel default for foreign keys.
*
* @var
*/
public $translationForeignKey;

Expand All @@ -41,6 +39,7 @@ class Country extends Eloquent implements TranslatableContract
* @var array
*/
public $fillable = [];

public $guarded = [];

/**
Expand Down
3 changes: 0 additions & 3 deletions tests/Eloquent/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class Person extends Eloquent implements TranslatableContract
/**
* This is the foreign key used to define the translation relationship.
* Set this if you want to overwrite the laravel default for foreign keys.
*
* @var
*/
public $translationForeignKey;

Expand All @@ -47,7 +45,6 @@ class Person extends Eloquent implements TranslatableContract
/**
* Mutate name attribute into upper-case.
*
* @param $value
* @return string
*/
public function getNameAttribute($value)
Expand Down
1 change: 1 addition & 0 deletions tests/Eloquent/PersonTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
class PersonTranslation extends Eloquent
{
public $timestamps = false;

public $fillable = ['name'];
}
1 change: 1 addition & 0 deletions tests/Eloquent/StrictTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
class StrictTranslation extends Eloquent
{
public $timestamps = false;

protected $table = 'country_translations';
}
18 changes: 9 additions & 9 deletions tests/EloquentOverrideTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,52 @@ public function to_array_returns_translated_attributes(): void
{
$vegetable = factory(Vegetable::class)->make(['name:en' => 'Peas']);

static::assertArrayHasKey('name', $vegetable->toArray());
static::assertEquals('Peas', $vegetable->toArray()['name']);
self::assertArrayHasKey('name', $vegetable->toArray());
self::assertEquals('Peas', $vegetable->toArray()['name']);
}

/** @test */
public function to_array_wont_break_if_no_translations_exist(): void
{
$vegetable = factory(Vegetable::class)->make();

static::assertIsArray($vegetable->toArray());
self::assertIsArray($vegetable->toArray());
}

/** @test */
public function translated_attributes_can_be_accessed_as_properties(): void
{
$vegetable = factory(Vegetable::class)->make(['name:en' => 'Peas']);

static::assertTrue(isset($vegetable->name));
static::assertEquals('Peas', $vegetable->name);
self::assertTrue(isset($vegetable->name));
self::assertEquals('Peas', $vegetable->name);
}

/** @test */
public function it_can_hide_translated_attributes(): void
{
$vegetable = factory(Vegetable::class)->make(['name:en' => 'Peas']);

static::assertTrue(isset($vegetable->toArray()['name']));
self::assertTrue(isset($vegetable->toArray()['name']));

$vegetable->setHidden(['name']);

static::assertFalse(isset($vegetable->toArray()['name']));
self::assertFalse(isset($vegetable->toArray()['name']));
}

/** @test */
public function it_finds_custom_primary_keys(): void
{
$vegetable = new Vegetable();

static::assertEquals('vegetable_identity', $vegetable->getTranslationRelationKey());
self::assertEquals('vegetable_identity', $vegetable->getTranslationRelationKey());
}

/** @test */
public function setAttribute_returns_parent_setAttribute(): void
{
$vegetable = new Vegetable();

static::assertSame($vegetable, $vegetable->setAttribute('name', 'China'));
self::assertSame($vegetable, $vegetable->setAttribute('name', 'China'));
}
}
Loading

0 comments on commit c6a850c

Please sign in to comment.