minor #29231 SCA: consolidate non empty array checks across codebase (kalessil)

This PR was squashed before being merged into the 3.4 branch (closes #29231).

Discussion
----------

SCA: consolidate non empty array checks across codebase

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

This PR replaces `is_array(...) && count(...) > 0` with `... && is_array(...)` construct used in the codebase.

Commits
-------

2f1fd54dda SCA: consolidate non empty array checks across codebase
This commit is contained in:
Nicolas Grekas 2018-11-20 17:02:07 +01:00
commit 36527634f2
3 changed files with 3 additions and 3 deletions

View File

@ -48,7 +48,7 @@ class FormValidator extends ConstraintValidator
// Validate the data against its own constraints
if ($form->isRoot() && (\is_object($data) || \is_array($data))) {
if (\is_array($groups) && \count($groups) > 0 || $groups instanceof GroupSequence && \count($groups->groups) > 0) {
if (($groups && \is_array($groups)) || ($groups instanceof GroupSequence && $groups->groups)) {
$validator->atPath('data')->validate($form->getData(), null, $groups);
}
}

View File

@ -69,7 +69,7 @@ class ArrayConverter
$elem = &$elem[$part];
}
if (\is_array($elem) && \count($elem) > 0 && $parentOfElem) {
if ($elem && \is_array($elem) && $parentOfElem) {
/* Process next case:
* 'foo.bar': 'test1'
* 'foo': 'test2'

View File

@ -120,7 +120,7 @@ abstract class Constraint
if (\is_array($options)) {
reset($options);
}
if (\is_array($options) && \count($options) > 0 && \is_string(key($options))) {
if ($options && \is_array($options) && \is_string(key($options))) {
foreach ($options as $option => $value) {
if (array_key_exists($option, $knownOptions)) {
$this->$option = $value;