AtLeast   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A count() 0 4 1
B evaluate() 0 19 5
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\SpecificationInterface;
15
16
/**
17
 * At Least Quantifier Class.
18
 *
19
 * @author Karel Osorio Ramírez <[email protected]>
20
 */
21
class AtLeast extends Quantifier
22
{
23
    /**
24
     * @var int
25
     */
26
    protected $count;
27
28
    /**
29
     * @param int                    $count
30
     * @param SelectorInterface      $selector
31
     * @param SpecificationInterface $specification
32
     */
33
    public function __construct($count, SelectorInterface $selector, SpecificationInterface $specification)
34
    {
35
        parent::__construct($selector, $specification);
36
37
        $this->count = (int) $count;
38
    }
39
40
    /**
41
     * @return int
42
     */
43
    public function count()
44
    {
45
        return $this->count;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function evaluate($value)
52
    {
53
        if ($this->count() == 0) {
54
            return true;
55
        }
56
57
        $count = 0;
58
        /** @var bool $result */
59
        foreach ($this->evaluationIterator($value) as $result) {
60
            if ($result) {
61
                ++$count;
62
                if ($this->count() == $count) {
63
                    return true;
64
                }
65
            }
66
        }
67
68
        return false;
69
    }
70
}
71