Code Duplication    Length = 73-73 lines in 2 locations

src/matcher/ToBeGreaterThan.php 1 location

@@ 28-100 (lines=73) @@
25
 * @author Noritaka Horio <[email protected]>
26
 * @copyright Noritaka Horio <[email protected]>
27
 */
28
final class ToBeGreaterThan implements ReportableMatcher
29
{
30
    /**
31
     * @var int|float
32
     */
33
    private $actual;
34
35
    /**
36
     * @var int|float
37
     */
38
    private $expected;
39
40
    /**
41
     * Create a new matcher.
42
     *
43
     * @param int|float $expected expected value
44
     */
45
    public function __construct($expected)
46
    {
47
        $this->expected = $expected;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function match($actual)
54
    {
55
        $this->actual = $actual;
56
57
        return $this->actual >= $this->expected;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function reportFailed(FailedMessage $message)
64
    {
65
        $detail = $this->createDetailMessage();
66
        $message->appendText('Expected ')
67
            ->appendValue($this->actual)
68
            ->appendText(' to be greater than ')
69
            ->appendValue($this->expected)
70
            ->appendText($detail);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function reportNegativeFailed(FailedMessage $message)
77
    {
78
        $detail = $this->createDetailMessage(' not');
79
        $message->appendText('Expected ')
80
            ->appendValue($this->actual)
81
            ->appendText(' not to be greater than ')
82
            ->appendValue($this->expected)
83
            ->appendText($detail);
84
    }
85
86
    private function createDetailMessage($prefixMessage = '')
87
    {
88
        $message = FailedMessage::fromString("\n\n");
89
        $message->appendText('    expected')
90
            ->appendText($prefixMessage)
91
            ->appendText(': >= ')
92
            ->appendValue($this->expected)
93
            ->appendText("\n")
94
            ->appendSpace(strlen($prefixMessage))
95
            ->appendText('         got:    ')
96
            ->appendValue($this->actual);
97
98
        return (string) $message;
99
    }
100
}
101

src/matcher/ToBeLessThan.php 1 location

@@ 28-100 (lines=73) @@
25
 * @author Noritaka Horio <[email protected]>
26
 * @copyright Noritaka Horio <[email protected]>
27
 */
28
final class ToBeLessThan implements ReportableMatcher
29
{
30
    /**
31
     * @var int|float
32
     */
33
    private $actual;
34
35
    /**
36
     * @var int|float
37
     */
38
    private $expected;
39
40
    /**
41
     * Create a new matcher.
42
     *
43
     * @param int|float $expected expected value
44
     */
45
    public function __construct($expected)
46
    {
47
        $this->expected = $expected;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function match($actual)
54
    {
55
        $this->actual = $actual;
56
57
        return $this->actual < $this->expected;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function reportFailed(FailedMessage $message)
64
    {
65
        $detail = $this->createDetailMessage();
66
        $message->appendText('Expected ')
67
            ->appendValue($this->actual)
68
            ->appendText(' to be less than ')
69
            ->appendValue($this->expected)
70
            ->appendText($detail);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function reportNegativeFailed(FailedMessage $message)
77
    {
78
        $detail = $this->createDetailMessage(' not');
79
        $message->appendText('Expected ')
80
            ->appendValue($this->actual)
81
            ->appendText(' not to be less than ')
82
            ->appendValue($this->expected)
83
            ->appendText($detail);
84
    }
85
86
    private function createDetailMessage($prefixMessage = '')
87
    {
88
        $message = FailedMessage::fromString("\n\n");
89
        $message->appendText('    expected')
90
            ->appendText($prefixMessage)
91
            ->appendText(': < ')
92
            ->appendValue($this->expected)
93
            ->appendText("\n")
94
            ->appendSpace(strlen($prefixMessage))
95
            ->appendText('         got:   ')
96
            ->appendValue($this->actual);
97
98
        return (string) $message;
99
    }
100
}
101