ArrayEveryEntryToken   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 64
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A scoreArgument() 0 17 6
A isLast() 0 4 1
A __toString() 0 4 1
A getValue() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Prophecy.
5
 * (c) Konstantin Kudryashov <[email protected]>
6
 *     Marcello Duarte <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Prophecy\Argument\Token;
13
14
/**
15
 * Array every entry token.
16
 *
17
 * @author Adrien Brault <[email protected]>
18
 */
19
class ArrayEveryEntryToken implements TokenInterface
20
{
21
    /**
22
     * @var TokenInterface
23
     */
24
    private $value;
25
26
    /**
27
     * @param mixed $value exact value or token
28
     */
29
    public function __construct($value)
30
    {
31
        if (!$value instanceof TokenInterface) {
32
            $value = new ExactValueToken($value);
33
        }
34
35
        $this->value = $value;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function scoreArgument($argument)
42
    {
43
        if (!$argument instanceof \Traversable && !is_array($argument)) {
44
            return false;
45
        }
46
47
        $scores = array();
48
        foreach ($argument as $key => $argumentEntry) {
49
            $scores[] = $this->value->scoreArgument($argumentEntry);
50
        }
51
52
        if (empty($scores) || in_array(false, $scores, true)) {
53
            return false;
54
        }
55
56
        return array_sum($scores) / count($scores);
0 ignored issues
show
Bug Compatibility introduced by
The expression array_sum($scores) / count($scores); of type integer|double adds the type double to the return on line 56 which is incompatible with the return type declared by the interface Prophecy\Argument\Token\...nterface::scoreArgument of type boolean|integer.
Loading history...
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function isLast()
63
    {
64
        return false;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function __toString()
71
    {
72
        return sprintf('[%s, ..., %s]', $this->value, $this->value);
73
    }
74
75
    /**
76
     * @return TokenInterface
77
     */
78
    public function getValue()
79
    {
80
        return $this->value;
81
    }
82
}
83