LogicalAndToken   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 14.52 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 1
cbo 1
dl 9
loc 62
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 3
A scoreArgument() 0 17 4
A isLast() 0 4 1
A __toString() 0 4 1

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
/**
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