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

Transformer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 37
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A transform() 0 8 1
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
}