Quantifier::evaluationIterator()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 4
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Specification\Quantifier;
12
13
use Cubiche\Core\Selector\SelectorInterface;
14
use Cubiche\Core\Specification\Specification;
15
use Cubiche\Core\Specification\SpecificationInterface;
16
17
/**
18
 * Abstract Quantifier Class.
19
 *
20
 * @author Karel Osorio Ramírez <[email protected]>
21
 */
22
abstract class Quantifier extends Specification implements QuantifierInterface
23
{
24
    /**
25
     * @var SelectorInterface
26
     */
27
    protected $selector;
28
29
    /**
30
     * @var SpecificationInterface
31
     */
32
    protected $specification;
33
34
    /**
35
     * @param SelectorInterface      $selector
36
     * @param SpecificationInterface $specification
37
     */
38
    public function __construct(SelectorInterface $selector, SpecificationInterface $specification)
39
    {
40
        $this->selector = $selector;
41
        $this->specification = $specification;
42
    }
43
44
    /**
45
     * @return \Cubiche\Core\Selector\SelectorInterface
46
     */
47
    public function selector()
48
    {
49
        return $this->selector;
50
    }
51
52
    /**
53
     * @return \Cubiche\Core\Specification\SpecificationInterface
54
     */
55
    public function specification()
56
    {
57
        return $this->specification;
58
    }
59
60
    /**
61
     * @param mixed $value
62
     *
63
     * @return Generator
64
     */
65
    protected function evaluationIterator($value)
66
    {
67
        $items = $this->selector()->apply($value);
68
        if (!\is_array($items) && !$value instanceof \Traversable) {
69
            $items = array($items);
70
        }
71
72
        foreach ($items as $item) {
73
            yield $this->specification()->evaluate($item);
74
        }
75
    }
76
}
77