Skip to content

Commit

Permalink
Apply fixes from StyleCI (#232)
Browse files Browse the repository at this point in the history
[ci skip] [skip ci]

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
joedixon and StyleCIBot authored Jul 11, 2022
1 parent 931265c commit 0a2b4e8
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/Console/Commands/ListMissingTranslationKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Console/Commands/SynchroniseTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
Expand All @@ -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'));
}
}
Expand All @@ -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'));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Factories/TranslationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Drivers/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
44 changes: 22 additions & 22 deletions src/Drivers/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -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()]));
}
}
Expand All @@ -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());
}

Expand All @@ -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);
}

Expand All @@ -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))];
}
Expand All @@ -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()))];
}
Expand All @@ -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')}";
}
Expand All @@ -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)) {
Expand Down Expand Up @@ -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", "<?php\n\nreturn " . var_export($translations->toArray(), true) . ';' . \PHP_EOL);
$this->disk->put("{$this->languageFilesPath}".DIRECTORY_SEPARATOR."{$language}".DIRECTORY_SEPARATOR."{$group}.php", "<?php\n\nreturn ".var_export($translations->toArray(), true).';'.\PHP_EOL);
}

/**
Expand All @@ -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", "<?php\n\nreturn " . var_export($translations->toArray(), true) . ';' . \PHP_EOL);
$this->disk->put("$directory".DIRECTORY_SEPARATOR."{$group}.php", "<?php\n\nreturn ".var_export($translations->toArray(), true).';'.\PHP_EOL);
}

/**
Expand All @@ -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)
);
}
Expand All @@ -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));
Expand All @@ -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}"));
}
}

Expand Down
26 changes: 13 additions & 13 deletions src/Drivers/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand All @@ -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') ?: '';

Expand Down
20 changes: 10 additions & 10 deletions src/TranslationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]);
}

Expand All @@ -71,7 +71,7 @@ private function loadViews()
*/
private function registerRoutes()
{
$this->loadRoutesFrom(__DIR__ . '/../routes/web.php');
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
}

/**
Expand All @@ -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');
}

Expand All @@ -93,7 +93,7 @@ private function publishConfiguration()
*/
private function mergeConfiguration()
{
$this->mergeConfigFrom(__DIR__ . '/../config/translation.php', 'translation');
$this->mergeConfigFrom(__DIR__.'/../config/translation.php', 'translation');
}

/**
Expand All @@ -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');
}

Expand All @@ -119,7 +119,7 @@ private function loadMigrations()
return;
}

$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
}

/**
Expand All @@ -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'),
]);
}

Expand Down Expand Up @@ -162,7 +162,7 @@ private function registerCommands()
*/
private function registerHelpers()
{
require __DIR__ . '/../resources/helpers.php';
require __DIR__.'/../resources/helpers.php';
}

/**
Expand Down
Loading

0 comments on commit 0a2b4e8

Please sign in to comment.