Completed
Push — master ( 9e0eff...358dda )
by Guillaume
02:44
created

ArrayValidatorTrait::mustBeArray()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 19
loc 19
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 2
nop 4
crap 3
1
<?php
2
3
namespace Imedia\Ammit\UI\Resolver\Validator\Implementation\Pure;
4
5
use Assert\Assertion;
6
use Imedia\Ammit\UI\Resolver\Validator\UIValidatorInterface;
7
8
/**
9
 * @author Guillaume MOREL <[email protected]>
10
 */
11 View Code Duplication
trait ArrayValidatorTrait
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /**
14
     * Exceptions are caught in order to be processed later
15
     * @param mixed $value Array ?
16
     *
17
     * @return array Empty array if not array
18
     */
19
    public function mustBeArray($value, string $propertyPath = null, UIValidatorInterface $parentValidator = null, string $exceptionMessage = null): array
20
    {
21 1
        $this->validationEngine->validateFieldValue(
0 ignored issues
show
Bug introduced by
The property validationEngine does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22 1
            $parentValidator ?: $this,
23 1
            function() use ($value, $propertyPath, $exceptionMessage) {
24 1
                Assertion::isArray(
25
                    $value,
26
                    $exceptionMessage,
27
                    $propertyPath
28
                );
29 1
            }
30
        );
31
32 1
        if (!is_array($value)) {
33 1
            return [];
34
        }
35
36 1
        return $value;
37
    }
38
}
39