Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from StyleCI #29

Open
wants to merge 1 commit into
base: dependabot/composer/develop/phpunit/phpunit-tw-10.1.0or-tw-11.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/LanguageLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function languages($hydrate = false)
static::$languages = json_decode(static::getFile(__DIR__.'/../resources/languages.json'), true);
}

return $hydrate ? array_map(fn($language): Language => new Language($language), static::$languages) : static::$languages;
return $hydrate ? array_map(fn ($language): Language => new Language($language), static::$languages) : static::$languages;
}

/**
Expand Down Expand Up @@ -243,7 +243,7 @@ protected static function collapse($array): array
*
* @return string
*/
public static function getFile($filePath): string | false
public static function getFile($filePath): string|false
{
if (! file_exists($filePath)) {
throw LanguageLoaderException::invalidLanguage();
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/LanguageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class LanguageServiceProvider extends ServiceProvider
public function boot(): void
{
// Add language validation rule
Validator::extend('language', fn($attribute, $value): bool => is_string($value) && mb_strlen($value) === 2 && array_key_exists(mb_strtolower($value), languages()), __('validation.invalid_language'));
Validator::extend('language', fn ($attribute, $value): bool => is_string($value) && mb_strlen($value) === 2 && array_key_exists(mb_strtolower($value), languages()), __('validation.invalid_language'));
}
}
1 change: 0 additions & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);
use Rinvex\Language\Language;

use Rinvex\Language\LanguageLoader;

if (! function_exists('language')) {
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/LanguageLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ public function it_throws_an_exception_when_invalid_language(): void
public function it_filters_data(): void
{
$array1 = [['id' => 1, 'name' => 'Hello'], ['id' => 2, 'name' => 'World']];
$this->assertEquals([1 => ['id' => 2, 'name' => 'World']], self::$methods['filter']->invoke(null, $array1, fn($item): bool => $item['id'] === 2));
$this->assertEquals([1 => ['id' => 2, 'name' => 'World']], self::$methods['filter']->invoke(null, $array1, fn ($item): bool => $item['id'] === 2));

$array2 = ['', 'Hello', '', 'World'];
$this->assertEquals(['Hello', 'World'], array_values(self::$methods['filter']->invoke(null, $array2)));

$array3 = ['id' => 1, 'first' => 'Hello', 'second' => 'World'];
$this->assertEquals(['first' => 'Hello', 'second' => 'World'], self::$methods['filter']->invoke(null, $array3, fn($item, $key): bool => $key !== 'id'));
$this->assertEquals(['first' => 'Hello', 'second' => 'World'], self::$methods['filter']->invoke(null, $array3, fn ($item, $key): bool => $key !== 'id'));
}

#[Test]
Expand All @@ -149,7 +149,7 @@ public function it_gets_data(): void
$this->assertEquals('Taylor', self::$methods['get']->invoke(null, $array, '0.users.0.name'));
$this->assertNull(self::$methods['get']->invoke(null, $array, '0.users.3'));
$this->assertEquals('Not found', self::$methods['get']->invoke(null, $array, '0.users.3', 'Not found'));
$this->assertEquals('Not found', self::$methods['get']->invoke(null, $array, '0.users.3', fn(): string => 'Not found'));
$this->assertEquals('Not found', self::$methods['get']->invoke(null, $array, '0.users.3', fn (): string => 'Not found'));
$this->assertEquals('Taylor', self::$methods['get']->invoke(null, $dottedArray, ['users', 'first.name']));
$this->assertNull(self::$methods['get']->invoke(null, $dottedArray, ['users', 'middle.name']));
$this->assertEquals('Not found', self::$methods['get']->invoke(null, $dottedArray, ['users', 'last.name'], 'Not found'));
Expand Down