From 4cf7f906271f3f6cc0fe784bb6b5e132ae4acffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F?= Date: Sat, 10 Nov 2018 20:13:39 +0200 Subject: [PATCH 1/2] Update Argument.php I made the code easier. --- src/Intervention/Image/Commands/Argument.php | 50 ++++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/Intervention/Image/Commands/Argument.php b/src/Intervention/Image/Commands/Argument.php index 40a8f629d..95b4b2f99 100644 --- a/src/Intervention/Image/Commands/Argument.php +++ b/src/Intervention/Image/Commands/Argument.php @@ -81,59 +81,57 @@ public function required() */ public function type($type) { - $fail = false; - + $valid = true; $value = $this->value(); - if (is_null($value)) { + if ($value === null) { return $this; } switch (strtolower($type)) { - case 'bool': case 'boolean': - $fail = ! is_bool($value); - $message = sprintf('%s accepts only boolean values as argument %d.', $this->getCommandName(), $this->key + 1); + $valid = \is_bool($value); + $message = '%s accepts only boolean values as argument %d.'; break; - case 'int': case 'integer': - $fail = ! is_integer($value); - $message = sprintf('%s accepts only integer values as argument %d.', $this->getCommandName(), $this->key + 1); + $valid = \is_int($value); + $message = '%s accepts only integer values as argument %d.'; break; - case 'num': case 'numeric': - $fail = ! is_numeric($value); - $message = sprintf('%s accepts only numeric values as argument %d.', $this->getCommandName(), $this->key + 1); + $valid = is_numeric($value); + $message = '%s accepts only numeric values as argument %d.'; break; - case 'str': case 'string': - $fail = ! is_string($value); - $message = sprintf('%s accepts only string values as argument %d.', $this->getCommandName(), $this->key + 1); + $valid = \is_string($value); + $message = '%s accepts only string values as argument %d.'; break; - case 'array': - $fail = ! is_array($value); - $message = sprintf('%s accepts only array as argument %d.', $this->getCommandName(), $this->key + 1); + $valid = \is_array($value); + $message = '%s accepts only array as argument %d.'; break; - case 'closure': - $fail = ! is_a($value, '\Closure'); - $message = sprintf('%s accepts only Closure as argument %d.', $this->getCommandName(), $this->key + 1); + $valid = is_a($value, \Closure::class); + $message = '%s accepts only Closure as argument %d.'; break; - case 'digit': - $fail = ! $this->isDigit($value); - $message = sprintf('%s accepts only integer values as argument %d.', $this->getCommandName(), $this->key + 1); + $valid = $this->isDigit($value); + $message = '%s accepts only integer values as argument %d.'; break; } - if ($fail) { + if (! $valid) { + $commandName = $this->getCommandName(); + $argument = $this->key + 1; - $message = isset($message) ? $message : sprintf("Missing argument for %d.", $this->key); + if (isset($message)) { + $message = sprintf($message, $commandName, $argument); + } else { + $message = sprintf('Missing argument for %d.', $argument); + } throw new \Intervention\Image\Exception\InvalidArgumentException( $message From c4d92f221e2256b06028795d41e641d6de710d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F?= Date: Sat, 10 Nov 2018 20:27:26 +0200 Subject: [PATCH 2/2] Update Argument.php --- src/Intervention/Image/Commands/Argument.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Intervention/Image/Commands/Argument.php b/src/Intervention/Image/Commands/Argument.php index 95b4b2f99..e64e8ac54 100644 --- a/src/Intervention/Image/Commands/Argument.php +++ b/src/Intervention/Image/Commands/Argument.php @@ -114,7 +114,7 @@ public function type($type) $message = '%s accepts only array as argument %d.'; break; case 'closure': - $valid = is_a($value, \Closure::class); + $valid = is_a($value, '\Closure'); $message = '%s accepts only Closure as argument %d.'; break; case 'digit':