Completed
Push — v5-dev ( a42eb3 )
by Oscar
01:56
created

ParsedFunction   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 98
rs 10
c 0
b 0
f 0
wmc 15
lcom 2
cbo 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getName() 0 4 1
A getLine() 0 4 1
A getLastLine() 0 4 1
A setLastLine() 0 6 1
A getFilename() 0 4 1
A getArguments() 0 4 1
A countArguments() 0 4 1
A getComments() 0 4 1
A addArgument() 0 7 1
A addArgumentChunk() 0 13 3
A closeArgument() 0 6 1
A addComment() 0 6 1
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
}