ToEqual   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 40.63 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 4
c 5
b 1
f 1
lcom 1
cbo 1
dl 26
loc 64
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A match() 0 6 1
A reportFailed() 13 13 1
A reportNegativeFailed() 13 13 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 expect package.
5
 *
6
 * (c) Noritaka Horio <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
namespace expect\matcher;
12
13
use expect\FailedMessage;
14
15
/**
16
 * Verify whether equivalent.
17
 *
18
 * <code>
19
 * $matcher = new ToEqual(100);
20
 * $matcher->match(100); //return true
21
 *
22
 * $matcher = new ToEqual(100);
23
 * $matcher->match(99); //return false
24
 * <code>
25
 *
26
 * @author Noritaka Horio <[email protected]>
27
 * @copyright Noritaka Horio <[email protected]>
28
 */
29
final class ToEqual implements ReportableMatcher
30
{
31
    /**
32
     * @var mixed
33
     */
34
    private $actual;
35
36
    /**
37
     * @var mixed
38
     */
39
    private $expected;
40
41
    /**
42
     * @param mixed $expected expected value
43
     */
44
    public function __construct($expected)
45
    {
46
        $this->expected = $expected;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function match($actual)
53
    {
54
        $this->actual = $actual;
55
56
        return $this->actual === $this->expected;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 View Code Duplication
    public function reportFailed(FailedMessage $message)
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...
63
    {
64
        $message->appendText("Expected ")
65
            ->appendValue($this->actual)
66
            ->appendText(' to be ')
67
            ->appendValue($this->expected)
68
            ->appendText("\n\n")
69
            ->appendText('    expected: ')
70
            ->appendValue($this->expected)
71
            ->appendText("\n")
72
            ->appendText('         got: ')
73
            ->appendValue($this->actual);
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 View Code Duplication
    public function reportNegativeFailed(FailedMessage $message)
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...
80
    {
81
        $message->appendText("Expected ")
82
            ->appendValue($this->actual)
83
            ->appendText(' not to be ')
84
            ->appendValue($this->expected)
85
            ->appendText("\n\n")
86
            ->appendText('    expected not: ')
87
            ->appendValue($this->expected)
88
            ->appendText("\n")
89
            ->appendText('             got: ')
90
            ->appendValue($this->actual);
91
    }
92
}
93