1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Gettext\Scanner; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class to handle the info of a parsed function |
8
|
|
|
*/ |
9
|
|
|
final class ParsedFunction |
10
|
|
|
{ |
11
|
|
|
private $name; |
12
|
|
|
private $filename; |
13
|
|
|
private $line; |
14
|
|
|
private $lastLine; |
15
|
|
|
private $arguments = []; |
16
|
|
|
private $comments = []; |
17
|
|
|
private $argumentIsClosed = false; |
18
|
|
|
|
19
|
|
|
public function __construct(string $name, string $filename, int $line) |
20
|
|
|
{ |
21
|
|
|
$this->name = $name; |
22
|
|
|
$this->filename = $filename; |
23
|
|
|
$this->line = $this->lastLine = $line; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getName(): string |
27
|
|
|
{ |
28
|
|
|
return $this->name; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getLine(): int |
32
|
|
|
{ |
33
|
|
|
return $this->line; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getLastLine(): int |
37
|
|
|
{ |
38
|
|
|
return $this->lastLine; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function setLastLine(int $lastLine): self |
42
|
|
|
{ |
43
|
|
|
$this->lastLine = $lastLine; |
44
|
|
|
|
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getFilename(): string |
49
|
|
|
{ |
50
|
|
|
return $this->filename; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getArguments(): array |
54
|
|
|
{ |
55
|
|
|
return $this->arguments; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function countArguments(): int |
59
|
|
|
{ |
60
|
|
|
return count($this->arguments); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return ParsedComments[] |
65
|
|
|
*/ |
66
|
|
|
public function getComments(): array |
67
|
|
|
{ |
68
|
|
|
return $this->comments; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function addArgument(string $argument = null): self |
72
|
|
|
{ |
73
|
|
|
$this->arguments[] = $argument; |
74
|
|
|
$this->argumentIsClosed = false; |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function addArgumentChunk(string $chunk): self |
80
|
|
|
{ |
81
|
|
|
if ($this->argumentIsClosed) { |
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$value = end($this->arguments).$chunk; |
86
|
|
|
$key = key($this->arguments) ?: 0; |
87
|
|
|
|
88
|
|
|
$this->arguments[$key] = $value; |
89
|
|
|
|
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function closeArgument(): self |
94
|
|
|
{ |
95
|
|
|
$this->argumentIsClosed = true; |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function addComment(ParsedComment $comment): self |
101
|
|
|
{ |
102
|
|
|
$this->comments[] = $comment; |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
} |