CollectionParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
c 0
b 0
f 0
dl 0
loc 20
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A parse() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Swis\JsonApi\Client\Parsers;
6
7
use Swis\JsonApi\Client\Collection;
8
use Swis\JsonApi\Client\Exceptions\ValidationException;
9
10
/**
11
 * @internal
12
 */
13
class CollectionParser
14
{
15
    private ItemParser $itemParser;
16
17 180
    public function __construct(ItemParser $itemParser)
18
    {
19 180
        $this->itemParser = $itemParser;
20 90
    }
21
22
    /**
23
     * @param  mixed  $data
24
     */
25 76
    public function parse($data): Collection
26
    {
27 76
        if (! is_array($data)) {
28 24
            throw new ValidationException(sprintf('ResourceCollection MUST be an array, "%s" given.', gettype($data)));
29
        }
30
31 52
        return Collection::make($data)
0 ignored issues
show
Bug introduced by
$data of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $items of Illuminate\Support\Collection::make(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        return Collection::make(/** @scrutinizer ignore-type */ $data)
Loading history...
32 52
            ->map(fn ($item) => $this->itemParser->parse($item));
33
    }
34
}
35