Skip to content

Commit

Permalink
[9.x] Simplify some conditions with is_countable() (#41168)
Browse files Browse the repository at this point in the history
* Simplify come conditions with is_countable().

* Remove useless import.
  • Loading branch information
lucasmichot authored Feb 22, 2022
1 parent ed8d75b commit bb4d381
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function choice($key, $number, array $replace = [], $locale = null)
// If the given "number" is actually an array or countable we will simply count the
// number of elements in an instance. This allows developers to pass an array of
// items without having to count it on their end first which gives bad syntax.
if (is_array($number) || $number instanceof Countable) {
if (is_countable($number)) {
$number = count($number);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Illuminate\Validation\Concerns;

use Countable;
use DateTime;
use DateTimeInterface;
use Egulias\EmailValidator\EmailValidator;
Expand Down Expand Up @@ -1518,7 +1517,7 @@ public function validateRequired($attribute, $value)
return false;
} elseif (is_string($value) && trim($value) === '') {
return false;
} elseif ((is_array($value) || $value instanceof Countable) && count($value) < 1) {
} elseif (is_countable($value) && count($value) < 1) {
return false;
} elseif ($value instanceof File) {
return (string) $value->getPath() !== '';
Expand Down

0 comments on commit bb4d381

Please sign in to comment.