diff --git a/src/Translatable/Contracts/Translatable.php b/src/Translatable/Contracts/Translatable.php index 022844f..40fc11e 100644 --- a/src/Translatable/Contracts/Translatable.php +++ b/src/Translatable/Contracts/Translatable.php @@ -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; diff --git a/src/Translatable/Translatable.php b/src/Translatable/Translatable.php index b822997..d9bf3c7 100644 --- a/src/Translatable/Translatable.php +++ b/src/Translatable/Translatable.php @@ -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); @@ -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; diff --git a/src/Translatable/Validation/Rules/TranslatableExists.php b/src/Translatable/Validation/Rules/TranslatableExists.php index f26fc4f..8a64fe6 100644 --- a/src/Translatable/Validation/Rules/TranslatableExists.php +++ b/src/Translatable/Validation/Rules/TranslatableExists.php @@ -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; } diff --git a/tests/EloquentOverrideTest.php b/tests/EloquentOverrideTest.php index 4875bff..992b268 100644 --- a/tests/EloquentOverrideTest.php +++ b/tests/EloquentOverrideTest.php @@ -48,7 +48,7 @@ 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()); } @@ -56,7 +56,7 @@ public function it_finds_custom_primary_keys(): void #[Test] public function setAttribute_returns_parent_setAttribute(): void { - $vegetable = new Vegetable(); + $vegetable = new Vegetable; self::assertSame($vegetable, $vegetable->setAttribute('name', 'China')); } diff --git a/tests/ScopesTest.php b/tests/ScopesTest.php index 98f51a9..02513ac 100644 --- a/tests/ScopesTest.php +++ b/tests/ScopesTest.php @@ -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(); diff --git a/tests/TranslatableTest.php b/tests/TranslatableTest.php index b03fedb..00237e7 100644 --- a/tests/TranslatableTest.php +++ b/tests/TranslatableTest.php @@ -22,7 +22,7 @@ public function it_finds_the_default_translation_class(): void { self::assertEquals( VegetableTranslation::class, - (new Vegetable())->getTranslationModelNameDefault() + (new Vegetable)->getTranslationModelNameDefault() ); } @@ -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() ); } @@ -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(), @@ -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'; @@ -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'], @@ -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()); } @@ -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()); } @@ -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')); @@ -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', @@ -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', @@ -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', @@ -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'], @@ -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', @@ -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' => '', @@ -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'], @@ -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'],