Completed
Push — master ( 6c04ca...a08b36 )
by Phil
08:12
created

AbstractStore   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 51
wmc 5
lcom 0
cbo 1
ccs 0
cts 19
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A decorate() 0 6 2
A invokeDecorators() 0 12 2
A validate() 0 4 1
1
<?php
2
3
namespace Percy\Store;
4
5
use InvalidArgumentException;
6
use Percy\Decorator\DecoratorInterface;
7
use Percy\Entity\Collection;
8
use Percy\Entity\EntityInterface;
9
10
abstract class AbstractStore implements StoreInterface
11
{
12
    /**
13
     * Iterate collection and apply decorators based on action.
14
     *
15
     * @param \Percy\Entity\Collection $collection
16
     * @param integer                  $action
17
     *
18
     * @return boolean
19
     */
20
    protected function decorate(Collection $collection, $action)
0 ignored issues
show
Unused Code introduced by
The parameter $action is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    {
22
        foreach ($collection->getIterator() as $entity) {
23
            array_walk($entity->getDecorators($type), [$this, 'invokeDecorators'], [$entity]);
0 ignored issues
show
Bug introduced by
$entity->getDecorators($type) cannot be passed to array_walk() as the parameter $array expects a reference.
Loading history...
Bug introduced by
The variable $type does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
24
        }
25
    }
26
27
    /**
28
     * Invoke callable decorator on entity.
29
     *
30
     * @param string                        $decorator
31
     * @param array                         $properties
32
     * @param \Percy\Entity\EntityInterface $entity
33
     *
34
     * @return void
35
     */
36
    protected function invokeDecorators($decorator, array $properties, EntityInterface $entity)
37
    {
38
        $decorator = new $decorator;
39
40
        if (! $decorator instanceof DecoratorInterface) {
41
            throw new InvalidArgumentException(
42
                sprintf('(%s) must be an instance of (Percy\Decorator\DecoratorInterface)', get_class($decorator))
43
            );
44
        }
45
46
        $decorator($entity, $properties);
47
    }
48
49
    /**
50
     * Iterate collection and validate data.
51
     *
52
     * @param \Percy\EntityCollection $collection
53
     *
54
     * @return boolean
55
     */
56
    public function validate(Collection $collection)
0 ignored issues
show
Unused Code introduced by
The parameter $collection is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
    {
58
59
    }
60
}
61