Completed
Push — master ( 7eeb17...89e06f )
by Phil
04:53
created

AbstractStore::validate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 18
ccs 0
cts 15
cp 0
rs 9.2
cc 4
eloc 10
nc 4
nop 1
crap 20
1
<?php
2
3
namespace Percy\Store;
4
5
use Aura\Filter\Exception\FilterFailed;
6
use Aura\Filter\FilterFactory;
7
use InvalidArgumentException;
8
use Percy\Decorator\DecoratorTrait;
9
use Percy\Entity\Collection;
10
11
abstract class AbstractStore implements StoreInterface
12
{
13
    use DecoratorTrait;
14
15
    /**
16
     * Construct.
17
     *
18
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
19
     */
20
    public function __construct(FilterFactory $filter)
21
    {
22
        $this->filter = $filter;
0 ignored issues
show
Bug introduced by
The property filter 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...
23
    }
24
25
    /**
26
     * Iterate collection and validate data.
27
     *
28
     * @param \Percy\Entity\Collection $collection
29
     *
30
     * @throws \Percy\Exception\ValidationException when first validation failure occurs
31
     *
32
     * @return boolean
33
     */
34
    public function validate(Collection $collection)
35
    {
36
        foreach ($collection->getIterator() as $entity) {
37
            if (is_null($collection->getValidator())) {
0 ignored issues
show
Bug introduced by
The method getValidator() does not seem to exist on object<Percy\Entity\Collection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
                continue;
39
            }
40
41
            $filter = $this->filter->newSubjectFilter($entity->getValidator());
42
43
            try {
44
                $filter($entity->toArray());
45
            } catch (FilterFailed $e) {
0 ignored issues
show
Bug introduced by
The class Aura\Filter\Exception\FilterFailed does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
46
                throw new ValidationException($e->getMessage());
47
            }
48
        }
49
50
        return true;
51
    }
52
}
53