diff --git a/src/Console/Commands/ListMissingTranslationKeys.php b/src/Console/Commands/ListMissingTranslationKeys.php index 43b3908..498f310 100644 --- a/src/Console/Commands/ListMissingTranslationKeys.php +++ b/src/Console/Commands/ListMissingTranslationKeys.php @@ -20,7 +20,7 @@ public function handle() // check whether or not there are any missing translations $empty = true; foreach ($missingTranslations as $language => $values) { - if (!empty($values)) { + if (! empty($values)) { $empty = false; } } diff --git a/src/Console/Commands/SynchroniseTranslations.php b/src/Console/Commands/SynchroniseTranslations.php index bb7cf4d..51463d1 100644 --- a/src/Console/Commands/SynchroniseTranslations.php +++ b/src/Console/Commands/SynchroniseTranslations.php @@ -44,7 +44,7 @@ public function handle() else { $this->fromDriver = $this->anticipate(__('translation::translation.prompt_from_driver'), $this->drivers); - if (!in_array($this->fromDriver, $this->drivers)) { + if (! in_array($this->fromDriver, $this->drivers)) { return $this->error(__('translation::translation.invalid_driver')); } } @@ -61,7 +61,7 @@ public function handle() else { $this->toDriver = $this->anticipate(__('translation::translation.prompt_to_driver'), $this->drivers); - if (!in_array($this->toDriver, $this->drivers)) { + if (! in_array($this->toDriver, $this->drivers)) { return $this->error(__('translation::translation.invalid_driver')); } } @@ -86,7 +86,7 @@ public function handle() else { $language = $this->anticipate(__('translation::translation.prompt_language_if_any'), $languages); - if ($language && !in_array($language, $languages)) { + if ($language && ! in_array($language, $languages)) { return $this->error(__('translation::translation.invalid_language')); } } diff --git a/src/Database/Factories/TranslationFactory.php b/src/Database/Factories/TranslationFactory.php index 0b76c61..7ae73e8 100644 --- a/src/Database/Factories/TranslationFactory.php +++ b/src/Database/Factories/TranslationFactory.php @@ -2,8 +2,8 @@ namespace JoeDixon\Translation\Database\Factories; -use JoeDixon\Translation\Language; use Illuminate\Database\Eloquent\Factories\Factory; +use JoeDixon\Translation\Language; use JoeDixon\Translation\Translation; class TranslationFactory extends Factory diff --git a/src/Drivers/Database.php b/src/Drivers/Database.php index f211bf9..9f7e69f 100644 --- a/src/Drivers/Database.php +++ b/src/Drivers/Database.php @@ -77,7 +77,7 @@ public function addLanguage(string $language, ?string $name = null): void */ public function addGroupTranslation($language, $group, $key, $value = ''): void { - if (!$this->languageExists($language)) { + if (! $this->languageExists($language)) { $this->addLanguage($language); } @@ -99,7 +99,7 @@ public function addGroupTranslation($language, $group, $key, $value = ''): void */ public function addSingleTranslation($language, $vendor, $key, $value = ''): void { - if (!$this->languageExists($language)) { + if (! $this->languageExists($language)) { $this->addLanguage($language); } diff --git a/src/Drivers/File.php b/src/Drivers/File.php index 9619f4c..dc27e43 100644 --- a/src/Drivers/File.php +++ b/src/Drivers/File.php @@ -42,9 +42,9 @@ public function allLanguages(): Collection */ public function allGroup(string $language): Collection { - $groupPath = "{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . "{$language}"; + $groupPath = "{$this->languageFilesPath}".DIRECTORY_SEPARATOR."{$language}"; - if (!$this->disk->exists($groupPath)) { + if (! $this->disk->exists($groupPath)) { return []; } @@ -85,8 +85,8 @@ public function addLanguage(string $language, ?string $name = null): void throw new LanguageExistsException(__('translation::errors.language_exists', ['language' => $language])); } - $this->disk->makeDirectory("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . "$language"); - if (!$this->disk->exists("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . "{$language}.json")) { + $this->disk->makeDirectory("{$this->languageFilesPath}".DIRECTORY_SEPARATOR."$language"); + if (! $this->disk->exists("{$this->languageFilesPath}".DIRECTORY_SEPARATOR."{$language}.json")) { $this->saveSingleTranslations($language, collect(['single' => collect()])); } } @@ -96,14 +96,14 @@ public function addLanguage(string $language, ?string $name = null): void */ public function addGroupTranslation(string $language, string $group, string $key, string $value = ''): void { - if (!$this->languageExists($language)) { + if (! $this->languageExists($language)) { $this->addLanguage($language); } $translations = $this->getGroupTranslationsFor($language); // does the group exist? If not, create it. - if (!$translations->keys()->contains($group)) { + if (! $translations->keys()->contains($group)) { $translations->put($group, collect()); } @@ -119,7 +119,7 @@ public function addGroupTranslation(string $language, string $group, string $key */ public function addSingleTranslation(string $language, string $vendor, string $key, string $value = ''): void { - if (!$this->languageExists($language)) { + if (! $this->languageExists($language)) { $this->addLanguage($language); } @@ -141,7 +141,7 @@ public function getSingleTranslationsFor(string $language): Collection return strpos($file, "{$language}.json"); })->flatMap(function ($file) { if (strpos($file->getPathname(), 'vendor')) { - $vendor = Str::before(Str::after($file->getPathname(), 'vendor' . DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR); + $vendor = Str::before(Str::after($file->getPathname(), 'vendor'.DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR); return ["{$vendor}::single" => new Collection(json_decode($this->disk->get($file), true))]; } @@ -159,7 +159,7 @@ public function getGroupTranslationsFor(string $language): Collection // here we check if the path contains 'vendor' as these will be the // files which need namespacing if (Str::contains($group->getPathname(), 'vendor')) { - $vendor = Str::before(Str::after($group->getPathname(), 'vendor' . DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR); + $vendor = Str::before(Str::after($group->getPathname(), 'vendor'.DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR); return ["{$vendor}::{$group->getBasename('.php')}" => new Collection($this->disk->getRequire($group->getPathname()))]; } @@ -183,7 +183,7 @@ public function getGroupsFor(string $language): Collection { return $this->getGroupFilesFor($language)->map(function ($file) { if (Str::contains($file->getPathname(), 'vendor')) { - $vendor = Str::before(Str::after($file->getPathname(), 'vendor' . DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR); + $vendor = Str::before(Str::after($file->getPathname(), 'vendor'.DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR); return "{$vendor}::{$file->getBasename('.php')}"; } @@ -198,7 +198,7 @@ public function getGroupsFor(string $language): Collection public function getTranslationsForFile(string $language, string $file): Collection { $file = Str::finish($file, '.php'); - $filePath = "{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . "{$language}" . DIRECTORY_SEPARATOR . "{$file}"; + $filePath = "{$this->languageFilesPath}".DIRECTORY_SEPARATOR."{$language}".DIRECTORY_SEPARATOR."{$file}"; $translations = new Collection; if ($this->disk->exists($filePath)) { @@ -228,7 +228,7 @@ public function saveGroupTranslations(string $language, string $group, Collectio return; } - $this->disk->put("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . "{$language}" . DIRECTORY_SEPARATOR . "{$group}.php", "toArray(), true) . ';' . \PHP_EOL); + $this->disk->put("{$this->languageFilesPath}".DIRECTORY_SEPARATOR."{$language}".DIRECTORY_SEPARATOR."{$group}.php", "toArray(), true).';'.\PHP_EOL); } /** @@ -237,13 +237,13 @@ public function saveGroupTranslations(string $language, string $group, Collectio private function saveNamespacedGroupTranslations(string $language, string $group, Collection $translations): void { [$namespace, $group] = explode('::', $group); - $directory = "{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . "{$namespace}" . DIRECTORY_SEPARATOR . "{$language}"; + $directory = "{$this->languageFilesPath}".DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR."{$namespace}".DIRECTORY_SEPARATOR."{$language}"; - if (!$this->disk->exists($directory)) { + if (! $this->disk->exists($directory)) { $this->disk->makeDirectory($directory, 0755, true); } - $this->disk->put("$directory" . DIRECTORY_SEPARATOR . "{$group}.php", "toArray(), true) . ';' . \PHP_EOL); + $this->disk->put("$directory".DIRECTORY_SEPARATOR."{$group}.php", "toArray(), true).';'.\PHP_EOL); } /** @@ -253,9 +253,9 @@ private function saveSingleTranslations(string $language, Collection $translatio { foreach ($translations as $group => $translation) { $vendor = Str::before($group, '::single'); - $languageFilePath = $vendor !== 'single' ? 'vendor' . DIRECTORY_SEPARATOR . "{$vendor}" . DIRECTORY_SEPARATOR . "{$language}.json" : "{$language}.json"; + $languageFilePath = $vendor !== 'single' ? 'vendor'.DIRECTORY_SEPARATOR."{$vendor}".DIRECTORY_SEPARATOR."{$language}.json" : "{$language}.json"; $this->disk->put( - "{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . "{$languageFilePath}", + "{$this->languageFilesPath}".DIRECTORY_SEPARATOR."{$languageFilePath}", json_encode((object) $translations->get($group), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) ); } @@ -266,7 +266,7 @@ private function saveSingleTranslations(string $language, Collection $translatio */ public function getGroupFilesFor(string $language): Collection { - $groups = new Collection($this->disk->allFiles("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . "{$language}")); + $groups = new Collection($this->disk->allFiles("{$this->languageFilesPath}".DIRECTORY_SEPARATOR."{$language}")); // namespaced files reside in the vendor directory so we'll grab these // the `getVendorGroupFileFor` method $groups = $groups->merge($this->getVendorGroupFilesFor($language)); @@ -279,17 +279,17 @@ public function getGroupFilesFor(string $language): Collection */ public function getVendorGroupFilesFor(string $language): ?Collection { - if (!$this->disk->exists("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . 'vendor')) { + if (! $this->disk->exists("{$this->languageFilesPath}".DIRECTORY_SEPARATOR.'vendor')) { return null; } $vendorGroups = []; - foreach ($this->disk->directories("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . 'vendor') as $vendor) { + foreach ($this->disk->directories("{$this->languageFilesPath}".DIRECTORY_SEPARATOR.'vendor') as $vendor) { $vendor = Arr::last(explode(DIRECTORY_SEPARATOR, $vendor)); - if (!$this->disk->exists("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . "{$vendor}" . DIRECTORY_SEPARATOR . "{$language}")) { + if (! $this->disk->exists("{$this->languageFilesPath}".DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR."{$vendor}".DIRECTORY_SEPARATOR."{$language}")) { array_push($vendorGroups, []); } else { - array_push($vendorGroups, $this->disk->allFiles("{$this->languageFilesPath}" . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . "{$vendor}" . DIRECTORY_SEPARATOR . "{$language}")); + array_push($vendorGroups, $this->disk->allFiles("{$this->languageFilesPath}".DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR."{$vendor}".DIRECTORY_SEPARATOR."{$language}")); } } diff --git a/src/Drivers/Translation.php b/src/Drivers/Translation.php index 2594743..e899d8a 100644 --- a/src/Drivers/Translation.php +++ b/src/Drivers/Translation.php @@ -13,57 +13,57 @@ abstract class Translation /** * Get all languages. */ - public abstract function allLanguages(): Collection; + abstract public function allLanguages(): Collection; /** * Get all translations. */ - public abstract function allTranslations(): Collection; + abstract public function allTranslations(): Collection; /** * Get all group translations for a given language. */ - public abstract function allGroup(string $language): Collection; + abstract public function allGroup(string $language): Collection; /** * Get all translations for a given language. */ - public abstract function allTranslationsFor(string $language): Collection; + abstract public function allTranslationsFor(string $language): Collection; /** * Add a new language. */ - public abstract function addLanguage(string $language, ?string $name = null): void; + abstract public function addLanguage(string $language, ?string $name = null): void; /** * Add a group translation. */ - public abstract function addGroupTranslation(string $language, string $group, string $key, string $value = ''): void; + abstract public function addGroupTranslation(string $language, string $group, string $key, string $value = ''): void; /** * Add a single translation. */ - public abstract function addSingleTranslation(string $language, string $vendor, string $key, string $value = ''): void; + abstract public function addSingleTranslation(string $language, string $vendor, string $key, string $value = ''): void; /** * Get single translations for a given language. */ - public abstract function getSingleTranslationsFor(string $language): Collection; + abstract public function getSingleTranslationsFor(string $language): Collection; /** * Get group translations for a given language. */ - public abstract function getGroupTranslationsFor(string $language): Collection; + abstract public function getGroupTranslationsFor(string $language): Collection; /** * Determine whether the given language exists. */ - public abstract function languageExists(string $language): bool; + abstract public function languageExists(string $language): bool; /** * Get all the groups for a given language. */ - public abstract function getGroupsFor(string $language): Collection; + abstract public function getGroupsFor(string $language): Collection; /** * Find all of the translations in the app without translation for a given language. @@ -131,7 +131,7 @@ public function getSourceLanguageTranslationsWith(string $language): Collection public function filterTranslationsFor(string $language, ?string $filter): Collection { $allTranslations = $this->getSourceLanguageTranslationsWith(($language)); - if (!$filter) { + if (! $filter) { return $allTranslations; } @@ -149,7 +149,7 @@ public function filterTranslationsFor(string $language, ?string $filter): Collec public function add(Request $request, $language, $isGroupTranslation) { $namespace = $request->has('namespace') && $request->get('namespace') ? "{$request->get('namespace')}::" : ''; - $group = $namespace . $request->get('group'); + $group = $namespace.$request->get('group'); $key = $request->get('key'); $value = $request->get('value') ?: ''; diff --git a/src/TranslationServiceProvider.php b/src/TranslationServiceProvider.php index 7f468ff..fef9ba3 100644 --- a/src/TranslationServiceProvider.php +++ b/src/TranslationServiceProvider.php @@ -57,10 +57,10 @@ public function register() */ private function loadViews() { - $this->loadViewsFrom(__DIR__ . '/../resources/views', 'translation'); + $this->loadViewsFrom(__DIR__.'/../resources/views', 'translation'); $this->publishes([ - __DIR__ . '/../resources/views' => resource_path('views/vendor/translation'), + __DIR__.'/../resources/views' => resource_path('views/vendor/translation'), ]); } @@ -71,7 +71,7 @@ private function loadViews() */ private function registerRoutes() { - $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); + $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); } /** @@ -82,7 +82,7 @@ private function registerRoutes() private function publishConfiguration() { $this->publishes([ - __DIR__ . '/../config/translation.php' => config_path('translation.php'), + __DIR__.'/../config/translation.php' => config_path('translation.php'), ], 'config'); } @@ -93,7 +93,7 @@ private function publishConfiguration() */ private function mergeConfiguration() { - $this->mergeConfigFrom(__DIR__ . '/../config/translation.php', 'translation'); + $this->mergeConfigFrom(__DIR__.'/../config/translation.php', 'translation'); } /** @@ -104,7 +104,7 @@ private function mergeConfiguration() private function publishAssets() { $this->publishes([ - __DIR__ . '/../public/assets' => public_path('vendor/translation'), + __DIR__.'/../public/assets' => public_path('vendor/translation'), ], 'assets'); } @@ -119,7 +119,7 @@ private function loadMigrations() return; } - $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } /** @@ -129,10 +129,10 @@ private function loadMigrations() */ private function loadTranslations() { - $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'translation'); + $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'translation'); $this->publishes([ - __DIR__ . '/../resources/lang' => resource_path('lang/vendor/translation'), + __DIR__.'/../resources/lang' => resource_path('lang/vendor/translation'), ]); } @@ -162,7 +162,7 @@ private function registerCommands() */ private function registerHelpers() { - require __DIR__ . '/../resources/helpers.php'; + require __DIR__.'/../resources/helpers.php'; } /** diff --git a/tests/DatabaseDriverTest.php b/tests/DatabaseDriverTest.php index c7dd450..c2e27bb 100644 --- a/tests/DatabaseDriverTest.php +++ b/tests/DatabaseDriverTest.php @@ -282,7 +282,7 @@ public function a_list_of_languages_can_be_viewed() public function the_language_creation_page_can_be_viewed() { $this->translation->addGroupTranslation(config('app.locale'), 'translation::translation', 'add_language', 'Add a new language'); - $this->get(config('translation.ui_url') . '/create') + $this->get(config('translation.ui_url').'/create') ->assertSee('Add a new language'); } @@ -304,7 +304,7 @@ public function a_list_of_translations_can_be_viewed() TranslationModel::factory()->single()->create(['language_id' => $default->id, 'key' => 'Hello', 'value' => 'Hello!']); TranslationModel::factory()->single()->create(['language_id' => $default->id, 'key' => "What's up", 'value' => 'Sup!']); - $this->get(config('translation.ui_url') . '/en/translations') + $this->get(config('translation.ui_url').'/en/translations') ->assertSee('hello') ->assertSee('whats_up') ->assertSee('Hello') @@ -315,14 +315,14 @@ public function a_list_of_translations_can_be_viewed() public function the_translation_creation_page_can_be_viewed() { $this->translation->addGroupTranslation('en', 'translation::translation', 'add_translation', 'Add a translation'); - $this->get(config('translation.ui_url') . '/' . config('app.locale') . '/translations/create') + $this->get(config('translation.ui_url').'/'.config('app.locale').'/translations/create') ->assertSee('Add a translation'); } /** @test */ public function a_new_translation_can_be_added() { - $this->post(config('translation.ui_url') . '/' . config('app.locale') . '/translations', ['group' => 'single', 'key' => 'joe', 'value' => 'is cool']) + $this->post(config('translation.ui_url').'/'.config('app.locale').'/translations', ['group' => 'single', 'key' => 'joe', 'value' => 'is cool']) ->assertRedirect(); $this->assertDatabaseHas('translations', ['language_id' => 1, 'key' => 'joe', 'value' => 'is cool']); @@ -335,7 +335,7 @@ public function a_translation_can_be_updated() TranslationModel::factory()->group()->create(['language_id' => $default->id, 'group' => 'test', 'key' => 'hello', 'value' => 'Hello']); $this->assertDatabaseHas('translations', ['language_id' => 1, 'group' => 'test', 'key' => 'hello', 'value' => 'Hello']); - $this->post(config('translation.ui_url') . '/en', ['group' => 'test', 'key' => 'hello', 'value' => 'Hello there!']) + $this->post(config('translation.ui_url').'/en', ['group' => 'test', 'key' => 'hello', 'value' => 'Hello there!']) ->assertStatus(200); $this->assertDatabaseHas('translations', ['language_id' => 1, 'group' => 'test', 'key' => 'hello', 'value' => 'Hello there!']); @@ -347,7 +347,7 @@ public function adding_a_translation_fires_an_event_with_the_expected_data() Event::fake(); $data = ['key' => 'joe', 'value' => 'is cool']; - $this->post(config('translation.ui_url') . '/en/translations', $data); + $this->post(config('translation.ui_url').'/en/translations', $data); Event::assertDispatched(TranslationAdded::class, function ($event) use ($data) { return $event->language === 'en' && @@ -363,7 +363,7 @@ public function updating_a_translation_fires_an_event_with_the_expected_data() Event::fake(); $data = ['group' => 'test', 'key' => 'hello', 'value' => 'Hello there!']; - $this->post(config('translation.ui_url') . '/en/translations', $data); + $this->post(config('translation.ui_url').'/en/translations', $data); Event::assertDispatched(TranslationAdded::class, function ($event) use ($data) { return $event->language === 'en' &&