GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SerializerField::setData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
namespace Solvire\API\Serializers\DataFields;
3
4
use Solvire\Utilities\OptionsChecker as Ch;
5
6
/**
7
 * 
8
 * With nested objects we need to reuse some of the serializers. 
9
 * If we tack on a serializer field we can attach this serializer to it. 
10
 * Not sure if this can scale indefinitely downward 
11
 *
12
 * @author solvire <[email protected]>
13
 * @package DataFields
14
 * @namespace Solvire\API\Serializers\DataFields
15
 */
16
class SerializerField extends DataField
17
{
18
19
    protected $requiredFields = [
20
        'serializer',
21
        'callback',
22
    ];
23
24
    /**
25
     * @var \League\Fractal\SerializerAbstract $serializer 
26
     */
27
    protected $serializer = null;
28
    
29
    /**
30
     * @var closure 
31
     */
32
    protected $callback = null;
33
34
    /**
35
     * 
36
     *
37
     * @param array $options            
38
     */
39 4
    public function __construct($options)
40
    {
41 4
        Ch::ek($options, $this->requiredFields);
42 4
        $this->serializer = $options['serializer'];
43 4
        $this->callback = $options['callback'];
44
        
45
        // make sure that the serializer is set up properly 
46 4
        if(! $this->serializer instanceof \Solvire\API\Serializers\BaseSerializer)
47 4
        {
48 1
            throw new \RuntimeException("Your serializer must be of type Solvire\API\Serializers\BaseSerializer on " . $this->name );
49
        }
50
        
51 3
        parent::__construct($options);
52 3
    }
53
54
    /**
55
     * 
56
     * @return object \Solvire\API\Serializers\BaseSerializer
57
     */
58 1
    public function getSerializer()
59
    {
60 1
        return $this->serializer;
61
    }
62
    
63
    /**
64
     * (non-PHPdoc)
65
     * @see \Solvire\API\Serializers\DataFields\DataField::getData()
66
     */
67 2
    public function getData()
68
    {
69 2
        return $this->serializer->loadData($this->data);
70
    }
71
    
72
    /**
73
     * 
74
     * @param Model $model
75
     */
76 2
    public function setData($model)
77
    {
78 2
        $cb = $this->callback;
79 2
        $this->data = $cb($model);
80 2
        return $this;
81
    }
82
    
83
}
84