From ec5fdb084b46c8d90b10e76b6882f083bbebd7c7 Mon Sep 17 00:00:00 2001 From: Mihkel Allorg Date: Wed, 6 Mar 2019 13:34:04 +0200 Subject: [PATCH] Update composer, style --- composer.json | 8 ++++---- src/Models/Translation.php | 1 + src/Traits/Translatable.php | 18 +++++++++++------- src/TranslatableServiceProvider.php | 8 ++++---- src/TranslatorManager.php | 3 +-- tests/CreatesApplication.php | 4 ++-- tests/Models/TestModel.php | 4 ++-- tests/TestCase.php | 2 +- tests/TranslatableTest.php | 16 +++++++--------- tests/factories/TestModelFactory.php | 2 +- 10 files changed, 34 insertions(+), 32 deletions(-) diff --git a/composer.json b/composer.json index 968a785..70cfe1e 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "require": { "google/cloud-translate": "^1.2", "php": ">=7.1.3", - "illuminate/support": "5.6.*|5.7.*" + "illuminate/support": "5.6.*|5.7.*|5.8.*" }, "require-dev": { "matthewbdaly/artisan-standalone": "0.0.*", @@ -25,9 +25,9 @@ } }, "autoload-dev": { - "classmap": [ - "tests" - ] + "psr-4": { + "Mihkullorg\\Tests\\Translatable\\": "tests/" + } }, "extra": { "laravel": { diff --git a/src/Models/Translation.php b/src/Models/Translation.php index fa0fd2f..2bb1113 100644 --- a/src/Models/Translation.php +++ b/src/Models/Translation.php @@ -39,6 +39,7 @@ public function scopeLanguage($query, $language) public function scopeFresherThan($query, $date) { $date = $date instanceof Carbon ? $date->toDateTimeString() : $date; + return $query->where('updated_at', '>=', $date); } diff --git a/src/Traits/Translatable.php b/src/Traits/Translatable.php index 11d0ef0..d3eac78 100644 --- a/src/Traits/Translatable.php +++ b/src/Traits/Translatable.php @@ -1,16 +1,16 @@ $field, $language); } @@ -45,7 +45,7 @@ public function translations() /** * @param string $field Translatable field name * @param string $language Language code - * @return integer + * @return int */ public function deleteTranslation($field, $language) { @@ -79,14 +79,18 @@ public function createTranslation($field, $language, $translation) * 'language' => 'ru', * 'body' => 'Russian body translations', * 'title' => '...', - * ] + * ]. * * @return array[] */ public function getTranslationsAsArray() { return $this->translations->groupBy('language')->map(function($language) { - return $language->groupBy('field')->map(function($field) { return $field->first()->value; }); - })->each(function($values, $language) { $values->put('language', $language); })->values()->toArray(); + return $language->groupBy('field')->map(function($field) { + return $field->first()->value; + }); + })->each(function($values, $language) { + $values->put('language', $language); + })->values()->toArray(); } } diff --git a/src/TranslatableServiceProvider.php b/src/TranslatableServiceProvider.php index 35b2c33..0f09444 100644 --- a/src/TranslatableServiceProvider.php +++ b/src/TranslatableServiceProvider.php @@ -13,7 +13,7 @@ class TranslatableServiceProvider extends BaseServiceProvider */ public function boot() { - $this->loadMigrationsFrom(__DIR__ . '/database/migrations'); + $this->loadMigrationsFrom(__DIR__.'/database/migrations'); $this->publishConfig(); $this->app->singleton('mt-translator', function ($app) { return new TranslatorManager($app); @@ -32,13 +32,13 @@ public function register() private function publishConfig() { - $config = __DIR__ . '/../config/config.php'; + $config = __DIR__.'/../config/config.php'; $migrationFileName = '2019_01_10_000001_create_translatable_tables.php'; - $migration = __DIR__ . '/database/migrations/' . $migrationFileName; + $migration = __DIR__.'/database/migrations/'.$migrationFileName; $this->publishes([ $config => config_path('translatable.php'), - $migration => app_path('database/migrations/' . $migrationFileName), + $migration => app_path('database/migrations/'.$migrationFileName), ], 'translatable'); } } diff --git a/src/TranslatorManager.php b/src/TranslatorManager.php index 752d3ce..bc85f31 100644 --- a/src/TranslatorManager.php +++ b/src/TranslatorManager.php @@ -3,12 +3,11 @@ namespace Mihkullorg\Translatable; use Illuminate\Support\Manager; -use Mihkullorg\Translatable\Contracts\TranslatorInterface; use Mihkullorg\Translatable\Drivers\GoogleTranslator; +use Mihkullorg\Translatable\Contracts\TranslatorInterface; class TranslatorManager extends Manager implements TranslatorInterface { - /** * Get the default driver name. * diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index 0fcea09..06d7a87 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -1,6 +1,6 @@ $value, ]); } + /** * @param TestModel $model * @param $field @@ -127,6 +124,7 @@ private function createTranslationInThePast(TestModel $model, $field, $language, $translation = $model->translations()->make(compact('field', 'language', 'value')); $translation->updated_at = Carbon::now()->subDay(); $translation->save(['timestamps' => false]); + return $translation; } } diff --git a/tests/factories/TestModelFactory.php b/tests/factories/TestModelFactory.php index e03bcc7..f7399af 100644 --- a/tests/factories/TestModelFactory.php +++ b/tests/factories/TestModelFactory.php @@ -1,7 +1,7 @@