Completed
Pull Request — master (#29)
by
unknown
01:39
created

Collection::__get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Softonic\GraphQL\Mutation;
4
5
use Softonic\GraphQL\Exceptions\InaccessibleArgumentException;
6
7
class Collection extends FilteredCollection
8
{
9 22
    public function __get(string $key): Collection
10
    {
11 22
        if (empty($this->arguments)) {
12 2
            throw InaccessibleArgumentException::fromEmptyArguments();
13
        }
14
15 20
        return parent::__get($key);
16
    }
17
18 14
    public function add(array $itemData): void
19
    {
20 14
        if (!empty($this->arguments[0]) && $this->arguments[0] instanceof Collection) {
21 8
            foreach ($this->arguments as $argument) {
22 8
                $argument->add($itemData);
23
            }
24
        } else {
25 14
            $this->arguments[] = new Item($itemData, $this->config, true);
26
        }
27 14
    }
28
}
29