CommandParams   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 57
ccs 18
cts 22
cp 0.8182
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFirstArgument() 0 4 1
A hasFirstArgument() 0 4 1
A getSecondArgument() 0 4 1
A hasSecondArgument() 0 4 1
A getThirdArgument() 0 4 1
A hasThirdArgument() 0 4 1
A getArgument() 0 6 2
A getArguments() 0 4 1
A hasArgument() 0 4 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