Skip to content

Commit

Permalink
use null coalescing operator instead of array_get
Browse files Browse the repository at this point in the history
  • Loading branch information
Vito Famiglietti committed Oct 19, 2018
1 parent 09de9b3 commit 19e4551
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/EnumServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class EnumServiceProvider extends ServiceProvider
public function boot()
{
$this->bootCommands();

$this->bootValidators();
}

Expand All @@ -41,27 +42,23 @@ private function bootCommands()
private function bootValidators()
{
Validator::extend('enum_key', function($attribute, $value, $parameters, $validator) {
$enum = array_get($parameters, 0, null);
$enum = $parameters[0] ?? null;

return (new EnumKey($enum))->passes($attribute, $value);
});

Validator::extend('enum_value', function($attribute, $value, $parameters, $validator) {
$enum = array_get($parameters, 0, null);
$strict = array_get($parameters, 1, null);
$enum = $parameters[0] ?? null;

$strict = $parameters[1] ?? null;

if ($strict) {
$strict = (boolean) json_decode(strtolower($strict));
return (new EnumValue($enum, $strict))->passes($attribute, $value);
if (! $strict) {
return (new EnumValue($enum))->passes($attribute, $value);
}

return (new EnumValue($enum))->passes($attribute, $value);
});
}
$strict = !! json_decode(strtolower($strict));

/**
* Register any package services.
*/
public function register()
{
return (new EnumValue($enum, $strict))->passes($attribute, $value);
});
}
}

0 comments on commit 19e4551

Please sign in to comment.