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   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 68
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 2
A getSerializer() 0 4 1
A getData() 0 4 1
A setData() 0 6 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