Skip to content

Commit

Permalink
fix return type changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Aug 28, 2024
1 parent c5519e0 commit e6b3c13
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
5 changes: 4 additions & 1 deletion src/Translatable/Contracts/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public function isTranslationAttribute(string $key): bool;
*/
public function replicateWithTranslations(?array $except = null): Model;

public function setDefaultLocale(?string $locale): self;
/**
* @return self
*/
public function setDefaultLocale(?string $locale);

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

Expand Down
7 changes: 5 additions & 2 deletions src/Translatable/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function getNewTranslation(string $locale): Model
$modelName = $this->getTranslationModelName();

/** @var Model $translation */
$translation = new $modelName();
$translation = new $modelName;
$translation->setAttribute($this->getLocaleKey(), $locale);
$translation->setAttribute($this->getTranslationRelationKey(), $this->getKey());
$this->translations->add($translation);
Expand Down Expand Up @@ -315,7 +315,10 @@ public function setAttribute($key, $value)
return parent::setAttribute($key, $value);
}

public function setDefaultLocale(?string $locale): TranslatableContract
/**
* @return TranslatableContract
*/
public function setDefaultLocale(?string $locale)
{
$this->defaultLocale = $locale;

Expand Down
2 changes: 1 addition & 1 deletion src/Translatable/Validation/Rules/TranslatableExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function ignore(int|string|Model $id, ?string $idColumn = null): self
}

$this->ignore = $id;
$this->idColumn = $idColumn ?? ((new $this->model())->getKeyName());
$this->idColumn = $idColumn ?? ((new $this->model)->getKeyName());

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/EloquentOverrideTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public function it_can_hide_translated_attributes(): void
#[Test]
public function it_finds_custom_primary_keys(): void
{
$vegetable = new Vegetable();
$vegetable = new Vegetable;

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

#[Test]
public function setAttribute_returns_parent_setAttribute(): void
{
$vegetable = new Vegetable();
$vegetable = new Vegetable;

self::assertSame($vegetable, $vegetable->setAttribute('name', 'China'));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ScopesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function lists_of_translated_fields_with_fallback(): void
factory(Country::class)->create(['code' => 'el', 'name:de' => 'Griechenland']);
factory(Country::class)->create(['code' => 'fr', 'name:en' => 'France']);

$country = new Country();
$country = new Country;
$country->useTranslationFallback = true;

$countries = $country->listsTranslations('name')->get();
Expand Down
36 changes: 18 additions & 18 deletions tests/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function it_finds_the_default_translation_class(): void
{
self::assertEquals(
VegetableTranslation::class,
(new Vegetable())->getTranslationModelNameDefault()
(new Vegetable)->getTranslationModelNameDefault()
);
}

Expand All @@ -33,7 +33,7 @@ public function it_finds_the_translation_class_with_namespace_set(): void

self::assertEquals(
'App\Models\Translations\VegetableTranslation',
(new Vegetable())->getTranslationModelNameDefault()
(new Vegetable)->getTranslationModelNameDefault()
);
}

Expand All @@ -44,14 +44,14 @@ public function it_finds_the_translation_class_with_suffix_set(): void

self::assertEquals(
'Tests\Eloquent\VegetableTrans',
(new Vegetable())->getTranslationModelName()
(new Vegetable)->getTranslationModelName()
);
}

#[Test]
public function it_returns_custom_TranslationModelName(): void
{
$vegetable = new Vegetable();
$vegetable = new Vegetable;

self::assertEquals(
$vegetable->getTranslationModelNameDefault(),
Expand All @@ -68,7 +68,7 @@ public function it_returns_custom_TranslationModelName(): void
#[Test]
public function it_returns_relation_key(): void
{
$vegetable = new Vegetable();
$vegetable = new Vegetable;
self::assertEquals('vegetable_identity', $vegetable->getRelationKey());

$vegetable->translationForeignKey = 'my_awesome_key';
Expand Down Expand Up @@ -341,7 +341,7 @@ public function it_fills_a_non_default_language_with_fallback_set(): void
{
$this->app->make('config')->set('translatable.fallback_locale', 'en');

$vegetable = new Vegetable();
$vegetable = new Vegetable;
$vegetable->fill([
'quantity' => 5,
'en' => ['name' => 'Peas'],
Expand Down Expand Up @@ -381,7 +381,7 @@ public function new_translation_can_be_saved_directly(): void
#[Test]
public function the_locale_key_is_locale_by_default(): void
{
$vegetable = new Vegetable();
$vegetable = new Vegetable;

self::assertEquals('locale', $vegetable->getLocaleKey());
}
Expand All @@ -391,14 +391,14 @@ public function the_locale_key_can_be_overridden_in_configuration(): void
{
$this->app->make('config')->set('translatable.locale_key', 'language_id');

$vegetable = new Vegetable();
$vegetable = new Vegetable;
self::assertEquals('language_id', $vegetable->getLocaleKey());
}

#[Test]
public function the_locale_key_can_be_customized_per_model(): void
{
$vegetable = new Vegetable();
$vegetable = new Vegetable;
$vegetable->localeKey = 'language_id';
self::assertEquals('language_id', $vegetable->getLocaleKey());
}
Expand Down Expand Up @@ -467,7 +467,7 @@ public function it_throws_an_exception_if_translation_does_not_exist(): void
#[Test]
public function it_returns_if_attribute_is_translated(): void
{
$vegetable = new Vegetable();
$vegetable = new Vegetable;

self::assertTrue($vegetable->isTranslationAttribute('name'));
self::assertFalse($vegetable->isTranslationAttribute('some-field'));
Expand Down Expand Up @@ -631,7 +631,7 @@ public function passing_an_empty_array_should_not_delete_translations(): void
#[Test]
public function fill_with_translation_key(): void
{
$vegetable = new Vegetable();
$vegetable = new Vegetable;
$vegetable->fill([
'name:en' => 'Peas',
'name:de' => 'Erbsen',
Expand All @@ -648,7 +648,7 @@ public function fill_with_translation_key(): void
#[Test]
public function it_uses_the_default_locale_from_the_model(): void
{
$vegetable = new Vegetable();
$vegetable = new Vegetable;
$vegetable->fill([
'name:en' => 'Peas',
'name:fr' => 'Pois',
Expand All @@ -670,7 +670,7 @@ public function it_uses_the_default_locale_from_the_model(): void
#[Test]
public function replicate_entity(): void
{
$vegetable = new Vegetable();
$vegetable = new Vegetable;
$vegetable->fill([
'name:fr' => 'Pomme',
'name:en' => 'Apple',
Expand Down Expand Up @@ -717,7 +717,7 @@ public function fill_will_ignore_unknown_locales(): void
{
config(['translatable.locales' => ['en']]);

$vegetable = new Vegetable();
$vegetable = new Vegetable;
$vegetable->fill([
'en' => ['name' => 'Peas'],
'ua' => ['name' => 'unknown'],
Expand All @@ -737,7 +737,7 @@ public function fill_will_ignore_unknown_locales_with_translations(): void
{
config(['translatable.locales' => ['en']]);

$vegetable = new Vegetable();
$vegetable = new Vegetable;
$vegetable->fill([
'name:en' => 'Peas',
'name:ua' => 'unknown',
Expand All @@ -759,7 +759,7 @@ public function it_uses_fallback_locale_if_default_is_empty(): void
$this->app->make('config')->set('translatable.use_fallback', true);
$this->app->make('config')->set('translatable.use_property_fallback', true);
$this->app->make('config')->set('translatable.fallback_locale', 'en');
$vegetable = new Vegetable();
$vegetable = new Vegetable;
$vegetable->fill([
'name:en' => 'Peas',
'name:fr' => '',
Expand All @@ -777,7 +777,7 @@ public function it_uses_value_when_fallback_is_not_available(): void
$this->app->make('config')->set('translatable.fallback_locale', 'it');
$this->app->make('config')->set('translatable.use_fallback', true);

$vegetable = new Vegetable();
$vegetable = new Vegetable;
$vegetable->fill([
'en' => ['name' => ''],
'de' => ['name' => 'Erbsen'],
Expand All @@ -803,7 +803,7 @@ public function empty_translated_attribute(): void
#[Test]
public function empty_translations_are_not_saved(): void
{
$vegetable = new Vegetable();
$vegetable = new Vegetable;
$vegetable->fill([
'en' => [],
'de' => ['name' => 'Erbsen'],
Expand Down

0 comments on commit e6b3c13

Please sign in to comment.