Args   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 46
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A count() 0 3 1
A prepare() 0 17 4
A get() 0 3 1
A type() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Conia\Quma;
6
7
use Conia\Quma\Util;
8
9
/**
10
 * @psalm-type ArgsArray = list<mixed>|array<non-empty-string, mixed>
11
 */
12
class Args
13
{
14
    protected ArgType $type;
15
    protected int $count;
16
17
    /** @psalm-var ArgsArray */
18
    protected readonly array $args;
19
20 60
    public function __construct(array $args)
21
    {
22 60
        $this->args = $this->prepare($args);
23
    }
24
25
    /** @psalm-return ArgsArray */
26 25
    public function get(): array
27
    {
28 25
        return $this->args;
29
    }
30
31 59
    public function count(): int
32
    {
33 59
        return $this->count;
34
    }
35
36 26
    public function type(): ArgType
37
    {
38 26
        return $this->type;
39
    }
40
41 60
    protected function prepare(array $args): array
42
    {
43 60
        $this->count = count($args);
44
45 60
        if ($this->count === 1 && is_array($args[0])) {
46 23
            if (Util::isAssoc($args[0])) {
47 22
                $this->type = ArgType::Named;
48
            } else {
49 3
                $this->type = ArgType::Positional;
50
            }
51
52 23
            return $args[0];
53
        }
54
55 48
        $this->type = ArgType::Positional;
56
57 48
        return $args;
58
    }
59
}
60