Completed
Pull Request — master (#29)
by
unknown
06:10
created

Collection::add()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

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