IdenticalValueToken   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 14.81 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A scoreArgument() 0 4 2
A isLast() 0 4 1
A __toString() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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