Completed
Pull Request — master (#6)
by
unknown
13:08
created

AbstractCollection::__toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 0
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
abstract class AbstractCollection implements ShellInterface
11
{
12
    /** @var CollectionTuple|null */
13
    protected $tuple;
14
15
    /**
16
     * @param string|ShellInterface $command
17
     * @param string $join
18
     * @return CollectionTuple
19
     * @throws ShellBuilderException
20
     */
21
    protected function toTuple($command, string $join): CollectionTuple
22
    {
23
        return CollectionTuple::create($command, $join);
24
    }
25
26
    /**
27
     * @return array<string|ShellInterface|array<mixed>>
28
     * @throws ShellBuilderException
29
     */
30
    public function __toArray(): array
31
    {
32
        if ($this->tuple === null) {
33
            throw new ShellBuilderException('Tuple has not been set yet - collection cannot be parsed to array');
34
        }
35
        return $this->tuple->__toArray();
36
    }
37
38
    public function __toString(): string
39
    {
40
        return (string)$this->tuple;
41
    }
42
}
43