Passed
Push — master ( f8044c...6aa085 )
by Alexander
03:26
created

Transformer::callIncludeMethod()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 1
b 0
f 0
nc 4
nop 3
dl 0
loc 20
rs 9.2
1
<?php
2
3
namespace Flugg\Responder;
4
5
use Flugg\Responder\Contracts\Transformer as TransformerContract;
6
use Flugg\Responder\Serializers\NullSerializer;
7
8
/**
9
 * A service class responsible for transforming data without serializing.
10
 *
11
 * @package flugger/laravel-responder
12
 * @author  Alexander Tømmerås <[email protected]>
13
 * @license The MIT License
14
 */
15
class Transformer implements TransformerContract
16
{
17
    /**
18
     * A builder used to build transformed arrays.
19
     *
20
     * @var \Flugg\Responder\TransformBuilder
21
     */
22
    protected $transformBuilder;
23
24
    /**
25
     * Construct the service class.
26
     *
27
     * @param \Flugg\Responder\TransformBuilder $transformBuilder
28
     */
29 1
    public function __construct(TransformBuilder $transformBuilder)
30
    {
31 1
        $this->transformBuilder = $transformBuilder;
32 1
    }
33
34
    /**
35
     * Transform the data without serializing with the given transformer and relations.
36
     *
37
     * @param  mixed                                                          $data
38
     * @param  \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer
39
     * @param  string[]                                                       $with
40
     * @param  string[]                                                       $without
41
     * @return array
42
     */
43 1
    public function transform($data = null, $transformer = null, array $with = [], array $without = []): array
44
    {
45 1
        return $this->transformBuilder->resource($data, $transformer)
46 1
            ->with($with)
47 1
            ->without($without)
48 1
            ->serializer(new NullSerializer)
49 1
            ->transform();
50
    }
51
}