Completed
Pull Request — master (#462)
by
unknown
01:33
created

NotInArrayToken::scoreArgument()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 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
 * Check if values is not in array
16
 *
17
 * @author Vinícius Alonso <[email protected]>
18
 */
19 View Code Duplication
class NotInArrayToken implements TokenInterface
0 ignored issues
show
Duplication introduced by
This class 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...
20
{
21
    private $token = array();
22
    private $strict;
23
24
    /**
25
     * @param array $arguments tokens
26
     * @param bool $strict
27
     */
28
    public function __construct(array $arguments, bool $strict = true)
29
    {
30
        $this->token = $arguments;
31
        $this->strict = $strict;
32
    }
33
34
    /**
35
     * Return scores 8 score if argument is in array.
36
     *
37
     * @param $argument
38
     *
39
     * @return bool|int
40
     */
41
    public function scoreArgument($argument)
42
    {
43
        if (count($this->token) === 0) {
44
            return false;
45
        }
46
47
        if (!\in_array($argument, $this->token, $this->strict)) {
48
            return 8;
49
        }
50
51
        return false;
52
    }
53
54
    /**
55
     * Returns false.
56
     *
57
     * @return boolean
58
     */
59
    public function isLast()
60
    {
61
        return false;
62
    }
63
64
    /**
65
     * Returns string representation for token.
66
     *
67
     * @return string
68
     */
69
    public function __toString()
70
    {
71
        $arrayAsString = implode(', ', $this->token);
72
        return "[{$arrayAsString}]";
73
    }
74
}
75
76