AbstractCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 31
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toTuple() 0 3 1
A __toString() 0 3 1
A __toArray() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PHPSu\ShellCommandBuilder\Collection;
6
7
use PHPSu\ShellCommandBuilder\Exception\ShellBuilderException;
8
use PHPSu\ShellCommandBuilder\ShellInterface;
9
10
/**
11
 * @internal
12
 * @psalm-internal PHPSu\ShellCommandBuilder
13
 */
14
abstract class AbstractCollection implements ShellInterface
15
{
16
    /** @var CollectionTuple|null */
17
    protected $tuple;
18
19
    /**
20
     * @param string|ShellInterface $command
21
     * @param string $join
22
     * @return CollectionTuple
23
     * @throws ShellBuilderException
24
     */
25
    protected function toTuple($command, string $join): CollectionTuple
26
    {
27
        return CollectionTuple::create($command, $join);
28
    }
29
30
    /**
31
     * @return array<string|ShellInterface|array<mixed>>
32
     * @throws ShellBuilderException
33
     */
34
    public function __toArray(): array
35
    {
36
        if ($this->tuple === null) {
37
            throw new ShellBuilderException('Tuple has not been set yet - collection cannot be parsed to array');
38
        }
39
        return $this->tuple->__toArray();
40
    }
41
42
    public function __toString(): string
43
    {
44
        return (string)$this->tuple;
45
    }
46
}
47