Passed
Branch develop (8534ca)
by Aleksandr
03:12
created

CommandFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormat() 0 3 1
A compile() 0 3 1
A addElement() 0 6 1
A getArguments() 0 3 1
1
<?php
2
3
namespace AlexCool\Rcon\Utils;
4
5
final class CommandFormatter
6
{
7
    /**
8
     * @var array
9
     */
10
    private $format;
11
12
    /**
13
     * @var array
14
     */
15
    private $arguments;
16
17
    /**
18
     * @return string
19
     */
20
    public function getFormat(): string
21
    {
22
        return implode(' ', $this->format);
23
    }
24
25
    /**
26
     * @return array
27
     */
28
    public function getArguments(): array
29
    {
30
        return $this->arguments;
31
    }
32
33
    /**
34
     * @param string $format
35
     * @param $argument
36
     *
37
     * @return $this
38
     */
39
    public function addElement(string $format, $argument)
40
    {
41
        $this->format[] .= $format;
42
        $this->arguments[] .= $argument;
43
44
        return $this;
45
    }
46
47
    /**
48
     * Return result string
49
     *
50
     * @return string
51
     */
52
    public function compile()
53
    {
54
        return vsprintf(implode(' ', $this->format), $this->arguments);
55
    }
56
}
57