IdenticalValueToken::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
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
use Prophecy\Util\StringUtil;
15
16
/**
17
 * Identical value token.
18
 *
19
 * @author Florian Voutzinos <[email protected]>
20
 */
21
class IdenticalValueToken implements TokenInterface
22
{
23
    private $value;
24
    private $string;
25
    private $util;
26
27
    /**
28
     * Initializes token.
29
     *
30
     * @param mixed      $value
31
     * @param StringUtil $util
32
     */
33
    public function __construct($value, StringUtil $util = null)
34
    {
35
        $this->value = $value;
36
        $this->util  = $util ?: new StringUtil();
37
    }
38
39
    /**
40
     * Scores 11 if argument matches preset value.
41
     *
42
     * @param $argument
43
     *
44
     * @return bool|int
45
     */
46
    public function scoreArgument($argument)
47
    {
48
        return $argument === $this->value ? 11 : false;
49
    }
50
51
    /**
52
     * Returns false.
53
     *
54
     * @return bool
55
     */
56
    public function isLast()
57
    {
58
        return false;
59
    }
60
61
    /**
62
     * Returns string representation for token.
63
     *
64
     * @return string
65
     */
66 View Code Duplication
    public function __toString()
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...
67
    {
68
        if (null === $this->string) {
69
            $this->string = sprintf('identical(%s)', $this->util->stringify($this->value));
70
        }
71
72
        return $this->string;
73
    }
74
}
75