Completed
Pull Request — master (#166)
by Pascal
01:44
created

ParsedComment::getLastLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Gettext\Utils;
4
5
/**
6
 * Comment parsed by PhpFunctionsScanner.
7
 */
8
class ParsedComment
9
{
10
    /**
11
     * The comment itself.
12
     *
13
     * @var string
14
     */
15
    protected $comment;
16
17
    /**
18
     * The line where the comment starts.
19
     *
20
     * @var int
21
     */
22
    protected $firstLine;
23
24
    /**
25
     * The line where the comment ends.
26
     *
27
     * @var int
28
     */
29
    protected $lastLine;
30
31
    /**
32
     * Initializes the instance.
33
     *
34
     * @param string $comment The comment itself.
35
     * @param int    $firstLine The line where the comment starts.
36
     * @param int    $lastLine The line where the comment ends.
37
     */
38
    public function __construct($comment, $firstLine, $lastLine)
39
    {
40
        $this->comment = $comment;
41
        $this->firstLine = $firstLine;
42
        $this->lastLine = $lastLine;
43
    }
44
45
    /**
46
     * Return the line where the comment starts.
47
     *
48
     * @return int Line number.
49
     */
50
    public function getFirstLine()
51
    {
52
        return $this->firstLine;
53
    }
54
55
    /**
56
     * Return the line where the comment ends.
57
     *
58
     * @return int Line number.
59
     */
60
    public function getLastLine()
61
    {
62
        return $this->lastLine;
63
    }
64
65
    /**
66
     * Return the actual comment string.
67
     *
68
     * @return string The comment.
69
     */
70
    public function getComment()
71
    {
72
        return $this->comment;
73
    }
74
75
    /**
76
     * Whether this comment is related with a given function.
77
     *
78
     * @param ParsedFunction $function The function to check.
79
     * @return bool Whether the comment is related or not.
80
     */
81
    public function isRelatedWith(ParsedFunction $function)
82
    {
83
        return $this->getLastLine() === $function->getLine() || $this->getLastLine() === $function->getLine() - 1;
84
    }
85
}
86