diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..e0a6500 --- /dev/null +++ b/.php_cs @@ -0,0 +1,12 @@ +exclude('coverage') + ->in(__DIR__) +; + +return Symfony\CS\Config\Config::create() + ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) + ->fixers(['short_array_syntax']) + ->finder($finder) +; \ No newline at end of file diff --git a/src/Translatable/Exception/LocalesNotDefinedException.php b/src/Translatable/Exception/LocalesNotDefinedException.php index a4d2f75..afb3c63 100644 --- a/src/Translatable/Exception/LocalesNotDefinedException.php +++ b/src/Translatable/Exception/LocalesNotDefinedException.php @@ -1,3 +1,5 @@ useFallback() : $withFallback; - if ($this->getTranslationByLocaleKey($locale)) - { + if ($this->getTranslationByLocaleKey($locale)) { $translation = $this->getTranslationByLocaleKey($locale); - } - elseif ($withFallback + } elseif ($withFallback && $this->getFallbackLocale() && $this->getTranslationByLocaleKey($this->getFallbackLocale()) - ) - { + ) { $translation = $this->getTranslationByLocaleKey($this->getFallbackLocale()); - } - else - { + } else { $translation = null; } @@ -67,10 +63,8 @@ public function hasTranslation($locale = null) { $locale = $locale ?: App::getLocale(); - foreach ($this->translations as $translation) - { - if ($translation->getAttribute($this->getLocaleKey()) == $locale) - { + foreach ($this->translations as $translation) { + if ($translation->getAttribute($this->getLocaleKey()) == $locale) { return true; } } @@ -87,7 +81,7 @@ public function getTranslationModelNameDefault() { $config = App::make('config'); - return get_class($this) . $config->get('translatable.translation_suffix', 'Translation'); + return get_class($this).$config->get('translatable.translation_suffix', 'Translation'); } public function getRelationKey() @@ -98,6 +92,7 @@ public function getRelationKey() public function getLocaleKey() { $config = App::make('config'); + return $this->localeKey ?: $config->get('translatable.locale_key', 'locale'); } @@ -108,69 +103,60 @@ public function translations() public function getAttribute($key) { - if ($this->isTranslationAttribute($key)) - { - if ($this->getTranslation() === null) - { - return null; + if ($this->isTranslationAttribute($key)) { + if ($this->getTranslation() === null) { + return; } + return $this->getTranslation()->$key; } + return parent::getAttribute($key); } public function setAttribute($key, $value) { - if (in_array($key, $this->translatedAttributes)) - { + if (in_array($key, $this->translatedAttributes)) { $this->getTranslationOrNew(App::getLocale())->$key = $value; - } - else - { + } else { parent::setAttribute($key, $value); } } public function save(array $options = []) { - if ($this->exists) - { - if (count($this->getDirty()) > 0) - { + if ($this->exists) { + if (count($this->getDirty()) > 0) { // If $this->exists and dirty, parent::save() has to return true. If not, // an error has occurred. Therefore we shouldn't save the translations. - if (parent::save($options)) - { + if (parent::save($options)) { return $this->saveTranslations(); } + return false; - } - else - { + } else { // If $this->exists and not dirty, parent::save() skips saving and returns // false. So we have to save the translations - if($saved = $this->saveTranslations()) - { + if ($saved = $this->saveTranslations()) { $this->fireModelEvent('saved', false); } return $saved; } - } - elseif (parent::save($options)) - { + } elseif (parent::save($options)) { // We save the translations only if the instance is saved in the database. return $this->saveTranslations(); } + return false; } protected function getTranslationOrNew($locale) { - if (($translation = $this->getTranslation($locale, false)) === null) - { + if (($translation = $this->getTranslation($locale, false)) === null) { $translation = $this->getNewTranslation($locale); } + return $translation; } @@ -178,18 +164,12 @@ public function fill(array $attributes) { $totallyGuarded = $this->totallyGuarded(); - foreach ($attributes as $key => $values) - { - if ($this->isKeyALocale($key)) - { - foreach ($values as $translationAttribute => $translationValue) - { - if ($this->alwaysFillable() or $this->isFillable($translationAttribute)) - { + foreach ($attributes as $key => $values) { + if ($this->isKeyALocale($key)) { + foreach ($values as $translationAttribute => $translationValue) { + if ($this->alwaysFillable() or $this->isFillable($translationAttribute)) { $this->getTranslationOrNew($key)->$translationAttribute = $translationValue; - } - elseif ($totallyGuarded) - { + } elseif ($totallyGuarded) { throw new MassAssignmentException($key); } } @@ -202,14 +182,13 @@ public function fill(array $attributes) private function getTranslationByLocaleKey($key) { - foreach ($this->translations as $translation) - { - if ($translation->getAttribute($this->getLocaleKey()) == $key) - { + foreach ($this->translations as $translation) { + if ($translation->getAttribute($this->getLocaleKey()) == $key) { return $translation; } } - return null; + + return; } private function getFallbackLocale() @@ -222,10 +201,10 @@ private function getFallbackLocale() */ private function useFallback() { - if (isset($this->useTranslationFallback) && $this->useTranslationFallback !== null) - { + if (isset($this->useTranslationFallback) && $this->useTranslationFallback !== null) { return $this->useTranslationFallback; } + return App::make('config')->get('translatable.use_fallback'); } @@ -237,6 +216,7 @@ protected function isTranslationAttribute($key) protected function isKeyALocale($key) { $locales = $this->getLocales(); + return in_array($key, $locales); } @@ -245,25 +225,24 @@ protected function getLocales() $config = App::make('config'); $locales = (array) $config->get('translatable.locales', []); - if (empty($locales)) - { + if (empty($locales)) { throw new LocalesNotDefinedException('Please make sure you have run "php artisan config:publish dimsav/laravel-translatable" '. ' and that the locales configuration is defined.'); } + return $locales; } protected function saveTranslations() { $saved = true; - foreach ($this->translations as $translation) - { - if ($saved && $this->isTranslationDirty($translation)) - { + foreach ($this->translations as $translation) { + if ($saved && $this->isTranslationDirty($translation)) { $translation->setAttribute($this->getRelationKey(), $this->getKey()); $saved = $translation->save(); } } + return $saved; } @@ -271,15 +250,17 @@ protected function isTranslationDirty(Model $translation) { $dirtyAttributes = $translation->getDirty(); unset($dirtyAttributes[$this->getLocaleKey()]); + return count($dirtyAttributes) > 0; } public function getNewTranslation($locale) { $modelName = $this->getTranslationModelName(); - $translation = new $modelName; + $translation = new $modelName(); $translation->setAttribute($this->getLocaleKey(), $locale); $this->translations->add($translation); + return $translation; } @@ -290,8 +271,7 @@ public function __isset($key) public function scopeTranslatedIn(Builder $query, $locale) { - return $query->whereHas('translations', function(Builder $q) use ($locale) - { + return $query->whereHas('translations', function (Builder $q) use ($locale) { $q->where($this->getLocaleKey(), '=', $locale); }); } @@ -312,7 +292,7 @@ public function scopeTranslated(Builder $query) * ] * * @param Builder $query - * @param string $translationField + * @param string $translationField */ public function scopeListsTranslations(Builder $query, $translationField) { @@ -323,15 +303,13 @@ public function scopeListsTranslations(Builder $query, $translationField) ->leftJoin($this->getTranslationsTable(), $this->getTranslationsTable().'.'.$this->getRelationKey(), '=', $this->getTable().'.'.$this->getKeyName()) ->where('locale', App::getLocale()) ; - if ($withFallback) - { - $query->orWhere(function(Builder $q){ - $q->where($this->getTranslationsTable() .'.'. $this->getLocaleKey(), $this->getFallbackLocale()) - ->whereNotIn($this->getTranslationsTable() . '.' . $this->getRelationKey(), function(QueryBuilder $q) - { - $q->select($this->getTranslationsTable() . '.' . $this->getRelationKey()) + if ($withFallback) { + $query->orWhere(function (Builder $q) { + $q->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), $this->getFallbackLocale()) + ->whereNotIn($this->getTranslationsTable().'.'.$this->getRelationKey(), function (QueryBuilder $q) { + $q->select($this->getTranslationsTable().'.'.$this->getRelationKey()) ->from($this->getTranslationsTable()) - ->where($this->getTranslationsTable() . '.' . $this->getLocaleKey(), App::getLocale()); + ->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), App::getLocale()); }); }); } @@ -341,10 +319,8 @@ public function toArray() { $attributes = parent::toArray(); - foreach($this->translatedAttributes AS $field) - { - if ($translations = $this->getTranslation()) - { + foreach ($this->translatedAttributes as $field) { + if ($translations = $this->getTranslation()) { $attributes[$field] = $translations->$field; } } diff --git a/src/Translatable/TranslatableServiceProvider.php b/src/Translatable/TranslatableServiceProvider.php index 6c8ed6f..07ea6b3 100644 --- a/src/Translatable/TranslatableServiceProvider.php +++ b/src/Translatable/TranslatableServiceProvider.php @@ -2,19 +2,17 @@ use Illuminate\Support\ServiceProvider; -class TranslatableServiceProvider extends ServiceProvider { - +class TranslatableServiceProvider extends ServiceProvider +{ public function boot() { $this->publishes([ - __DIR__ .'/../config/translatable.php'=> config_path('translatable.php'), + __DIR__.'/../config/translatable.php' => config_path('translatable.php'), ]); } /** * Register the service provider. - * - * @return void */ public function register() { diff --git a/src/config/translatable.php b/src/config/translatable.php index e315914..e38da0f 100644 --- a/src/config/translatable.php +++ b/src/config/translatable.php @@ -73,5 +73,4 @@ */ 'always_fillable' => false, - ]; diff --git a/tests/TestCoreModelExtension.php b/tests/TestCoreModelExtension.php index 6956789..0dac40c 100644 --- a/tests/TestCoreModelExtension.php +++ b/tests/TestCoreModelExtension.php @@ -8,10 +8,9 @@ use Dimsav\Translatable\Test\Model\City; use Dimsav\Translatable\Test\Model\CityTranslation; use Dimsav\Translatable\Test\Model\Company; -use Orchestra\Testbench\TestCase; - -class TestCoreModelExtension extends TestsBase { +class TestCoreModelExtension extends TestsBase +{ // Saving /** @@ -19,11 +18,11 @@ class TestCoreModelExtension extends TestsBase { */ public function it_saves_empty_instances() { - $company = new Company; + $company = new Company(); $company->save(); $this->assertGreaterThan(0, $company->id); - $country = new Continent; + $country = new Continent(); $country->save(); $this->assertGreaterThan(0, $country->id); } @@ -74,7 +73,7 @@ public function it_returns_false_if_exists_and_dirty_and_parent_save_returns_fal { $that = $this; $event = App::make('events'); - $event->listen('eloquent*', function($model) use ($that) { + $event->listen('eloquent*', function ($model) use ($that) { return get_class($model) == 'Dimsav\Translatable\Test\Model\Country' ? false : true; }); @@ -91,11 +90,11 @@ public function it_returns_false_if_does_not_exist_and_parent_save_returns_false { $that = $this; $event = App::make('events'); - $event->listen('eloquent*', function($model) use ($that) { + $event->listen('eloquent*', function ($model) use ($that) { return get_class($model) == 'Dimsav\Translatable\Test\Model\Continent' ? false : true; }); - $continent = new Continent; + $continent = new Continent(); $this->assertFalse($continent->save()); } @@ -141,8 +140,8 @@ public function it_does_not_delete_translations_when_attempting_to_delete_transl $this->assertTrue(is_object($translation)); try { $country->delete(); + } catch (\Exception $e) { } - catch (\Exception $e) {} $country = Country::find(1); $this->assertNotNull($country); @@ -197,7 +196,6 @@ public function it_passes_the_N_plus_1_problem() $this->assertEquals(2, $this->queriesCount); } - // Forms /** @@ -208,4 +206,4 @@ public function it_fakes_isset_for_translated_attributes() $country = Country::find(1); $this->assertEquals(true, isset($country->name)); } -} \ No newline at end of file +} diff --git a/tests/TestsBase.php b/tests/TestsBase.php index 68fecd0..49bec5f 100644 --- a/tests/TestsBase.php +++ b/tests/TestsBase.php @@ -3,8 +3,8 @@ use Orchestra\Testbench\TestCase; use Dimsav\Translatable\Test\Model\Country; -class TestsBase extends TestCase { - +class TestsBase extends TestCase +{ protected $queriesCount; public function setUp() @@ -28,9 +28,9 @@ protected function getPackageProviders($app) protected function getEnvironmentSetUp($app) { - $app['path.base'] = __DIR__ . '/..'; + $app['path.base'] = __DIR__.'/..'; $app['config']->set('database.default', 'mysql'); - $app['config']->set('database.connections.mysql', array( + $app['config']->set('database.connections.mysql', [ 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'translatable_test', @@ -38,19 +38,20 @@ protected function getEnvironmentSetUp($app) 'password' => 'secret', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', - )); - $app['config']->set('translatable.locales', array('el', 'en', 'fr', 'de', 'id')); + ]); + $app['config']->set('translatable.locales', ['el', 'en', 'fr', 'de', 'id']); } protected function getPackageAliases($app) { - return array('Eloquent' => 'Illuminate\Database\Eloquent\Model'); + return ['Eloquent' => 'Illuminate\Database\Eloquent\Model']; } - protected function countQueries() { + protected function countQueries() + { $that = $this; $event = App::make('events'); - $event->listen('illuminate.query', function() use ($that) { + $event->listen('illuminate.query', function () use ($that) { $that->queriesCount++; }); } @@ -78,4 +79,4 @@ private function resetDatabase() '--path' => $migrationsPath, ]); } -} \ No newline at end of file +} diff --git a/tests/TranslatableTest.php b/tests/TranslatableTest.php index 3ae5575..f0a8240 100644 --- a/tests/TranslatableTest.php +++ b/tests/TranslatableTest.php @@ -4,14 +4,14 @@ use Dimsav\Translatable\Test\Model\CountryStrict; use Dimsav\Translatable\Test\Model\CountryWithCustomLocaleKey; -class TranslatableTest extends TestsBase { - +class TranslatableTest extends TestsBase +{ /** * @test */ public function it_finds_the_default_translation_class() { - $country = new Country; + $country = new Country(); $this->assertEquals( 'Dimsav\Translatable\Test\Model\CountryTranslation', $country->getTranslationModelNameDefault()); @@ -23,7 +23,7 @@ public function it_finds_the_default_translation_class() public function it_finds_the_translation_class_with_suffix_set() { App::make('config')->set('translatable.translation_suffix', 'Trans'); - $country = new Country; + $country = new Country(); $this->assertEquals( 'Dimsav\Translatable\Test\Model\CountryTrans', $country->getTranslationModelName()); @@ -34,7 +34,7 @@ public function it_finds_the_translation_class_with_suffix_set() */ public function it_returns_custom_TranslationModelName() { - $country = new Country; + $country = new Country(); $this->assertEquals( $country->getTranslationModelNameDefault(), @@ -53,7 +53,7 @@ public function it_returns_custom_TranslationModelName() */ public function it_returns_relation_key() { - $country = new Country; + $country = new Country(); $this->assertEquals('country_id', $country->getRelationKey()); $country->translationForeignKey = 'my_awesome_key'; @@ -119,7 +119,7 @@ public function it_uses_default_locale_to_return_translations() */ public function it_creates_translations() { - $country = new Country; + $country = new Country(); $country->code = 'be'; $country->save(); @@ -129,7 +129,6 @@ public function it_creates_translations() $country = Country::whereCode('be')->first(); $this->assertEquals('Belgium', $country->name); - } /** @@ -137,7 +136,7 @@ public function it_creates_translations() */ public function it_creates_translations_using_the_shortcut() { - $country = new Country; + $country = new Country(); $country->code = 'be'; $country->name = 'Belgium'; $country->save(); @@ -151,10 +150,10 @@ public function it_creates_translations_using_the_shortcut() */ public function it_creates_translations_using_mass_assignment() { - $data = array( + $data = [ 'code' => 'be', 'name' => 'Belgium', - ); + ]; $country = Country::create($data); $this->assertEquals('be', $country->code); $this->assertEquals('Belgium', $country->name); @@ -165,11 +164,11 @@ public function it_creates_translations_using_mass_assignment() */ public function it_creates_translations_using_mass_assignment_and_locales() { - $data = array( + $data = [ 'code' => 'be', 'en' => ['name' => 'Belgium'], - 'fr' => ['name' => 'Belgique'] - ); + 'fr' => ['name' => 'Belgique'], + ]; $country = Country::create($data); $this->assertEquals('be', $country->code); $this->assertEquals('Belgium', $country->translate('en')->name); @@ -185,11 +184,11 @@ public function it_creates_translations_using_mass_assignment_and_locales() */ public function it_skips_mass_assignment_if_attributes_non_fillable() { - $data = array( + $data = [ 'code' => 'be', 'en' => ['name' => 'Belgium'], - 'fr' => ['name' => 'Belgique'] - ); + 'fr' => ['name' => 'Belgique'], + ]; $country = CountryStrict::create($data); $this->assertEquals('be', $country->code); $this->assertNull($country->translate('en')); @@ -281,7 +280,7 @@ public function it_fills_a_non_default_language_with_fallback_set() { App::make('config')->set('translatable.fallback_locale', 'en'); - $country = new Country; + $country = new Country(); $country->fill([ 'code' => 'gr', 'en' => ['name' => 'Greece'], @@ -412,7 +411,7 @@ public function configuration_overrides_fillable() $country = new CountryStrict([ 'en' => ['name' => 'Not fillable'], - 'code' => 'te' + 'code' => 'te', ]); $this->assertSame($country->getTranslation('en')->name, 'Not fillable'); @@ -426,7 +425,7 @@ public function lists_of_translated_fields() App::setLocale('de'); $list = [[ 'id' => '1', - 'name' => 'Griechenland' + 'name' => 'Griechenland', ]]; $this->assertEquals($list, Country::listsTranslations('name')->get()->toArray()); } @@ -438,15 +437,15 @@ public function lists_of_translated_fields_with_fallback() { App::make('config')->set('translatable.fallback_locale', 'en'); App::setLocale('de'); - $country = new Country; + $country = new Country(); $country->useTranslationFallback = true; $list = [[ 'id' => '1', - 'name' => 'Griechenland' + 'name' => 'Griechenland', ],[ 'id' => '2', - 'name' => 'France' - ],]; + 'name' => 'France', + ]]; $this->assertEquals($list, $country->listsTranslations('name')->get()->toArray()); } } diff --git a/tests/migrations/2013_11_28_152610_create_tables.php b/tests/migrations/2013_11_28_152610_create_tables.php index 2c8f475..b50ef94 100644 --- a/tests/migrations/2013_11_28_152610_create_tables.php +++ b/tests/migrations/2013_11_28_152610_create_tables.php @@ -3,36 +3,31 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -class CreateTables extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::create('countries', function(Blueprint $table) - { - $table->increments('id'); - $table->string('code'); +class CreateTables extends Migration +{ + /** + * Run the migrations. + */ + public function up() + { + Schema::create('countries', function (Blueprint $table) { + $table->increments('id'); + $table->string('code'); $table->timestamps(); $table->softDeletes(); - }); + }); - Schema::create('country_translations', function(Blueprint $table) - { + Schema::create('country_translations', function (Blueprint $table) { $table->increments('id'); $table->integer('country_id')->unsigned(); $table->string('name'); $table->string('locale')->index(); - $table->unique(['country_id','locale']); + $table->unique(['country_id', 'locale']); $table->foreign('country_id')->references('id')->on('countries')->onDelete('cascade'); }); - Schema::create('cities', function(Blueprint $table) - { + Schema::create('cities', function (Blueprint $table) { $table->increments('id'); $table->integer('country_id')->unsigned(); $table->timestamps(); @@ -40,8 +35,7 @@ public function up() $table->foreign('country_id')->references('id')->on('countries'); }); - Schema::create('city_translations', function(Blueprint $table) - { + Schema::create('city_translations', function (Blueprint $table) { $table->increments('id'); $table->integer('city_id')->unsigned(); $table->string('name'); @@ -51,39 +45,31 @@ public function up() $table->foreign('city_id')->references('id')->on('cities')->onDelete('cascade'); }); - Schema::create('companies', function(Blueprint $table) - { + Schema::create('companies', function (Blueprint $table) { $table->increments('id'); $table->string('name')->nullable(); $table->timestamps(); }); - Schema::create('continents', function(Blueprint $table) - { + Schema::create('continents', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); }); - Schema::create('continent_translations', function(Blueprint $table) - { + Schema::create('continent_translations', function (Blueprint $table) { $table->increments('id'); $table->integer('continent_id')->unsigned(); $table->string('name'); $table->string('locale')->index(); $table->timestamps(); }); + } - } - - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - + /** + * Reverse the migrations. + */ + public function down() + { Schema::dropIfExists('city_translations'); Schema::dropIfExists('cities'); @@ -94,6 +80,5 @@ public function down() Schema::dropIfExists('continent_translations'); Schema::dropIfExists('continents'); - } - + } } diff --git a/tests/migrations/2014_02_02_181020_add_seeds.php b/tests/migrations/2014_02_02_181020_add_seeds.php index c93f6c4..445868a 100644 --- a/tests/migrations/2014_02_02_181020_add_seeds.php +++ b/tests/migrations/2014_02_02_181020_add_seeds.php @@ -6,55 +6,52 @@ use Dimsav\Translatable\Test\Model\City; use Dimsav\Translatable\Test\Model\CityTranslation; -class AddSeeds extends Migration { - - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - $countries = array( - ['id'=>1, 'code'=>'gr'], - ['id'=>2, 'code'=>'fr'], - ['id'=>3, 'code'=>'en'], - ['id'=>4, 'code'=>'de'], - ); +class AddSeeds extends Migration +{ + /** + * Run the migrations. + */ + public function up() + { + $countries = [ + ['id' => 1, 'code' => 'gr'], + ['id' => 2, 'code' => 'fr'], + ['id' => 3, 'code' => 'en'], + ['id' => 4, 'code' => 'de'], + ]; $this->createCountries($countries); - $countryTranslations = array( + $countryTranslations = [ ['country_id' => 1, 'locale' => 'el', 'name' => 'Ελλάδα'], ['country_id' => 1, 'locale' => 'fr', 'name' => 'Grèce'], ['country_id' => 1, 'locale' => 'en', 'name' => 'Greece'], ['country_id' => 1, 'locale' => 'de', 'name' => 'Griechenland'], ['country_id' => 2, 'locale' => 'en', 'name' => 'France'], - ); + ]; $this->createCountryTranslations($countryTranslations); - - $cities = array( - ['id'=>1, 'country_id'=>1], - ); + $cities = [ + ['id' => 1, 'country_id' => 1], + ]; $this->createCities($cities); - $cityTranslations = array( + $cityTranslations = [ ['city_id' => 1, 'locale' => 'el', 'name' => 'Αθήνα'], ['city_id' => 1, 'locale' => 'fr', 'name' => 'Athènes'], ['city_id' => 1, 'locale' => 'en', 'name' => 'Athens'], ['city_id' => 1, 'locale' => 'de', 'name' => 'Athen'], - ); + ]; $this->createCityTranslations($cityTranslations); - } + } private function createCountries($countries) { foreach ($countries as $data) { - $country = new Country; + $country = new Country(); $country->id = $data['id']; $country->code = $data['code']; $country->save(); @@ -64,7 +61,7 @@ private function createCountries($countries) private function createCountryTranslations($translations) { foreach ($translations as $data) { - $translation = new CountryTranslation; + $translation = new CountryTranslation(); $translation->country_id = $data['country_id']; $translation->locale = $data['locale']; $translation->name = $data['name']; @@ -75,7 +72,7 @@ private function createCountryTranslations($translations) private function createCities($cities) { foreach ($cities as $data) { - $city = new City; + $city = new City(); $city->id = $data['id']; $city->country_id = $data['country_id']; $city->save(); @@ -85,7 +82,7 @@ private function createCities($cities) private function createCityTranslations($translations) { foreach ($translations as $data) { - $translation = new CityTranslation; + $translation = new CityTranslation(); $translation->city_id = $data['city_id']; $translation->locale = $data['locale']; $translation->name = $data['name']; @@ -93,11 +90,10 @@ private function createCityTranslations($translations) } } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() {} - + /** + * Reverse the migrations. + */ + public function down() + { + } } diff --git a/tests/models/City.php b/tests/models/City.php index fe90c16..5df7d79 100644 --- a/tests/models/City.php +++ b/tests/models/City.php @@ -3,16 +3,16 @@ use Dimsav\Translatable\Translatable; use Illuminate\Database\Eloquent\Model as Eloquent; -class City extends Eloquent { - +class City extends Eloquent +{ use Translatable; /** - * Array with the fields translated in the Translation table + * Array with the fields translated in the Translation table. * * @var array */ - public $translatedAttributes = array('name'); + public $translatedAttributes = ['name']; /** * Set $translationModel if you want to overwrite the convention @@ -33,18 +33,17 @@ class City extends Eloquent { /** * Add your translated attributes here if you want - * fill them with mass assignment + * fill them with mass assignment. * * @var array */ - public $fillable = array('name'); + public $fillable = ['name']; /** * The database field being used to define the locale parameter in the translation model. - * Defaults to 'locale' + * Defaults to 'locale'. * * @var string */ public $localeKey; - } diff --git a/tests/models/CityTranslation.php b/tests/models/CityTranslation.php index bba1db5..d26efa1 100644 --- a/tests/models/CityTranslation.php +++ b/tests/models/CityTranslation.php @@ -2,8 +2,7 @@ use Illuminate\Database\Eloquent\Model as Eloquent; -class CityTranslation extends Eloquent { - +class CityTranslation extends Eloquent +{ public $timestamps = false; - } diff --git a/tests/models/Company.php b/tests/models/Company.php index e2ad2a6..751eed2 100644 --- a/tests/models/Company.php +++ b/tests/models/Company.php @@ -5,4 +5,6 @@ /** * A test class used as a normal class extending Eloquent, not using laravel-translatable. */ -class Company extends Eloquent {} \ No newline at end of file +class Company extends Eloquent +{ +} diff --git a/tests/models/Continent.php b/tests/models/Continent.php index f913c01..8e006a0 100644 --- a/tests/models/Continent.php +++ b/tests/models/Continent.php @@ -6,10 +6,9 @@ /** * A test class that has no required properties. */ -class Continent extends Eloquent { - +class Continent extends Eloquent +{ use Translatable; - public $translatedAttributes = array('name'); - -} \ No newline at end of file + public $translatedAttributes = ['name']; +} diff --git a/tests/models/ContinentTranslation.php b/tests/models/ContinentTranslation.php index 064eefe..a3149bc 100644 --- a/tests/models/ContinentTranslation.php +++ b/tests/models/ContinentTranslation.php @@ -2,6 +2,6 @@ use Illuminate\Database\Eloquent\Model as Eloquent; -class ContinentTranslation extends Eloquent { - -} \ No newline at end of file +class ContinentTranslation extends Eloquent +{ +} diff --git a/tests/models/Country.php b/tests/models/Country.php index 69912b4..967b7db 100644 --- a/tests/models/Country.php +++ b/tests/models/Country.php @@ -3,16 +3,16 @@ use Dimsav\Translatable\Translatable; use Illuminate\Database\Eloquent\Model as Eloquent; -class Country extends Eloquent { - +class Country extends Eloquent +{ use Translatable; /** - * Array with the fields translated in the Translation table + * Array with the fields translated in the Translation table. * * @var array */ - public $translatedAttributes = array('name'); + public $translatedAttributes = ['name']; /** * Set $translationModel if you want to overwrite the convention @@ -33,18 +33,17 @@ class Country extends Eloquent { /** * Add your translated attributes here if you want - * fill them with mass assignment + * fill them with mass assignment. * * @var array */ - public $fillable = array('code','name'); + public $fillable = ['code','name']; /** * The database field being used to define the locale parameter in the translation model. - * Defaults to 'locale' + * Defaults to 'locale'. * * @var string */ public $localeKey; - -} \ No newline at end of file +} diff --git a/tests/models/CountryGuarded.php b/tests/models/CountryGuarded.php index 6b78cad..9ac516b 100644 --- a/tests/models/CountryGuarded.php +++ b/tests/models/CountryGuarded.php @@ -2,17 +2,17 @@ use Dimsav\Translatable\Translatable; use Illuminate\Database\Eloquent\Model as Eloquent; -class CountryGuarded extends Eloquent { +class CountryGuarded extends Eloquent +{ use Translatable; public $table = 'countries'; - protected $fillable = array(); - protected $guarded = array('*'); + protected $fillable = []; + protected $guarded = ['*']; public $translatedAttributes = ['name']; public $translationModel = 'Dimsav\Translatable\Test\Model\CountryTranslation'; public $translationForeignKey = 'country_id'; - -} \ No newline at end of file +} diff --git a/tests/models/CountryStrict.php b/tests/models/CountryStrict.php index 51946d5..2ab7e8b 100644 --- a/tests/models/CountryStrict.php +++ b/tests/models/CountryStrict.php @@ -3,20 +3,20 @@ use Dimsav\Translatable\Translatable; use Illuminate\Database\Eloquent\Model as Eloquent; -class CountryStrict extends Eloquent { - +class CountryStrict extends Eloquent +{ use Translatable; /** - * Array with the fields translated in the Translation table + * Array with the fields translated in the Translation table. * * @var array */ - public $translatedAttributes = array('name'); + public $translatedAttributes = ['name']; /** * Here we set a custom model for translation. - * The convention would be Dimsav\Translatable\Test\Model\CountryStrictTranslation + * The convention would be Dimsav\Translatable\Test\Model\CountryStrictTranslation. * * @var string Class containing the translation */ @@ -29,7 +29,7 @@ class CountryStrict extends Eloquent { /** * Column containing the locale in the translation table. - * Defaults to 'locale' + * Defaults to 'locale'. * * @var string */ @@ -39,12 +39,11 @@ class CountryStrict extends Eloquent { /** * Add your translated attributes here if you want - * fill them with mass assignment + * fill them with mass assignment. * * @var array */ - public $fillable = array('code'); + public $fillable = ['code']; protected $softDelete = true; - -} \ No newline at end of file +} diff --git a/tests/models/CountryTranslation.php b/tests/models/CountryTranslation.php index 1c8f5c9..bb2bcf7 100644 --- a/tests/models/CountryTranslation.php +++ b/tests/models/CountryTranslation.php @@ -2,8 +2,7 @@ use Illuminate\Database\Eloquent\Model as Eloquent; -class CountryTranslation extends Eloquent { - +class CountryTranslation extends Eloquent +{ public $timestamps = false; - -} \ No newline at end of file +} diff --git a/tests/models/CountryWithCustomLocaleKey.php b/tests/models/CountryWithCustomLocaleKey.php index 2bd368d..6968dc8 100644 --- a/tests/models/CountryWithCustomLocaleKey.php +++ b/tests/models/CountryWithCustomLocaleKey.php @@ -3,12 +3,12 @@ use Dimsav\Translatable\Translatable; use Illuminate\Database\Eloquent\Model as Eloquent; -class CountryWithCustomLocaleKey extends Eloquent { - +class CountryWithCustomLocaleKey extends Eloquent +{ use Translatable; public $table = 'countries'; - public $translatedAttributes = array('name'); + public $translatedAttributes = ['name']; public $translationModel = 'Dimsav\Translatable\Test\Model\CountryTranslation'; /* @@ -16,5 +16,4 @@ class CountryWithCustomLocaleKey extends Eloquent { * be used to save the locale info into the database */ public $localeKey = 'language_id'; - -} \ No newline at end of file +}