ToEndWith   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 4
c 4
b 1
f 0
lcom 1
cbo 2
dl 53
loc 53
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A match() 7 7 1
A reportNegativeFailed() 7 7 1
A reportFailed() 7 7 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 the string value is end with the expected string.
17
 *
18
 * <code>
19
 * $matcher = new ToEndWith('foo');
20
 * $matcher->match('barfoo'); //return true
21
 *
22
 * $matcher->match('foobar'); //return false
23
 * <code>
24
 *
25
 * @author Noritaka Horio <[email protected]>
26
 * @copyright Noritaka Horio <[email protected]>
27
 */
28 View Code Duplication
final class ToEndWith implements ReportableMatcher
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...
29
{
30
    /**
31
     * @var string
32
     */
33
    private $actual;
34
35
    /**
36
     * @var string
37
     */
38
    private $pattern;
39
40
    /**
41
     * @param string $expected pattern keyword
42
     */
43
    public function __construct($expected)
44
    {
45
        $this->pattern = preg_quote($expected, '/');
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function match($actual)
52
    {
53
        $this->actual = $actual;
54
        $patternMatcher = new PatternMatcher("/{$this->pattern}$/");
55
56
        return $patternMatcher->match($actual);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function reportFailed(FailedMessage $message)
63
    {
64
        $message->appendText('Expected ')
65
            ->appendValue($this->actual)
66
            ->appendText(' to end with ')
67
            ->appendValue($this->pattern);
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function reportNegativeFailed(FailedMessage $message)
74
    {
75
        $message->appendText('Expected ')
76
            ->appendValue($this->actual)
77
            ->appendText(' not to end with ')
78
            ->appendValue($this->pattern);
79
    }
80
}
81