LogicalAndToken::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
 * Logical AND token.
16
 *
17
 * @author Boris Mikhaylov <[email protected]>
18
 */
19
class LogicalAndToken implements TokenInterface
20
{
21
    private $tokens = array();
22
23
    /**
24
     * @param array $arguments exact values or tokens
25
     */
26 View Code Duplication
    public function __construct(array $arguments)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        foreach ($arguments as $argument) {
29
            if (!$argument instanceof TokenInterface) {
30
                $argument = new ExactValueToken($argument);
31
            }
32
            $this->tokens[] = $argument;
33
        }
34
    }
35
36
    /**
37
     * Scores maximum score from scores returned by tokens for this argument if all of them score.
38
     *
39
     * @param $argument
40
     *
41
     * @return bool|int
42
     */
43
    public function scoreArgument($argument)
44
    {
45
        if (0 === count($this->tokens)) {
46
            return false;
47
        }
48
49
        $maxScore = 0;
50
        foreach ($this->tokens as $token) {
51
            $score = $token->scoreArgument($argument);
52
            if (false === $score) {
53
                return false;
54
            }
55
            $maxScore = max($score, $maxScore);
56
        }
57
58
        return $maxScore;
59
    }
60
61
    /**
62
     * Returns false.
63
     *
64
     * @return boolean
65
     */
66
    public function isLast()
67
    {
68
        return false;
69
    }
70
71
    /**
72
     * Returns string representation for token.
73
     *
74
     * @return string
75
     */
76
    public function __toString()
77
    {
78
        return sprintf('bool(%s)', implode(' AND ', $this->tokens));
79
    }
80
}
81