CommandParams::hasSecondArgument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
3
namespace Bigwhoop\Trumpet\Commands;
4
5
final class CommandParams
6
{
7
    /** @var string[] */
8
    private $params = [];
9
10 23
    public function __construct(string $params = '', string $argumentSeparator = ' ')
11
    {
12 23
        $this->params = str_getcsv($params, $argumentSeparator, '"');
13 23
    }
14
15 23
    public function getFirstArgument(string $default = ''): string
16
    {
17 23
        return $this->getArgument(0, $default);
18
    }
19
20
    public function hasFirstArgument(): bool
21
    {
22
        return $this->hasArgument(0);
23
    }
24
    
25 20
    public function getSecondArgument(string $default = ''): string
26
    {
27 20
        return $this->getArgument(1, $default);
28
    }
29
30 5
    public function hasSecondArgument(): bool
31
    {
32 5
        return $this->hasArgument(1);
33
    }
34
35 10
    public function getThirdArgument(string $default = ''): string
36
    {
37 10
        return $this->getArgument(2, $default);
38
    }
39
40
    public function hasThirdArgument(): bool
41
    {
42
        return $this->hasArgument(2);
43
    }
44
45 23
    public function getArgument(int $n, string $default = ''): string
46
    {
47 23
        $args = $this->getArguments();
48
49 23
        return array_key_exists($n, $args) ? $args[$n] : $default;
50
    }
51
    
52 23
    public function getArguments(): array
53
    {
54 23
        return $this->params;
55
    }
56
    
57 5
    public function hasArgument(int $n): bool
58
    {
59 5
        return array_key_exists($n, $this->getArguments());
60
    }
61
}
62