Passed
Push — master ( 1863b6...b24285 )
by Steve
32s
created

TextLine::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * (c) Steve Nebes <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace SN\RangeDifferencer;
13
14
class TextLine
15
{
16
    /** @var int */
17
    private $lineNumber = 0;
18
19
    /** @var string */
20
    private $text = '';
21
22
    /**
23
     * Default values.
24
     *
25
     * @param int    $lineNumber
26
     * @param string $text
27
     */
28
    public function __construct(int $lineNumber, string $text)
29
    {
30
        $this->lineNumber = $lineNumber;
31
        $this->text = $text;
32
    }
33
34
    /**
35
     * @return int
36
     */
37
    public function getLineNumber(): int
38
    {
39
        return $this->lineNumber;
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getText(): string
46
    {
47
        return $this->text;
48
    }
49
50
    /**
51
     * Compares this TextLine to $other and returns true if they have the same text.
52
     *
53
     * @param TextLine $other
54
     * @return bool
55
     */
56
    public function isSameText(TextLine $other): bool
57
    {
58
        return $this->text === $other->getText();
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function __toString(): string
65
    {
66
        return sprintf("%d %s\n", $this->lineNumber, $this->text);
67
    }
68
}
69