RiCollectionFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 27
ccs 8
cts 8
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 17 2
1
<?php
2
3
namespace VGirol\JsonApiFaker\Laravel\Factory;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Collection;
7
use VGirol\JsonApiFaker\Exception\JsonApiFakerException;
8
use VGirol\JsonApiFaker\Laravel\Messages;
9
10
/**
11
 * Factory for collection of resource identifier (@see ResourceIdentifierFactory).
12
 */
13
class RiCollectionFactory extends CollectionFactory
14
{
15
    /**
16
     * Returns an array of ResourceIdentifierContract.
17
     *
18
     * @param Collection $collection
19
     * @param string     $resourceType
20
     *
21
     * @return array
22
     */
23 21
    protected function transform($collection, $resourceType): array
24
    {
25 21
        return $collection->map(
26
            /**
27
             * @param \Illuminate\Database\Eloquent\Model $model
28
             *
29
             * @return \VGirol\JsonApiFaker\Laravel\Contract\ResourceIdentifierContract
30
             * @throws JsonApiFakerException
31
             */
32 21
            function ($model) use ($resourceType) {
33 21
                if (!is_a($model, Model::class)) {
34 3
                    throw new JsonApiFakerException(Messages::ERROR_NOT_MODEL_INSTANCE);
35
                }
36
37 18
                return $this->generator->resourceIdentifier($model, $resourceType);
38 21
            }
39 18
        )->toArray();
40
    }
41
}
42