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.
Completed
Push — master ( b5d278...796de0 )
by Sergey
17s queued 11s
created

Context::getLinkedData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
/*
3
 * This file is part of the jsonapi.
4
 *
5
 * (c) Sergey Revenko <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Reva2\JsonApi\Decoders;
12
13
/**
14
 * Decoder context
15
 *
16
 * @author Sergey Revenko <[email protected]>
17
 * @package Reva2\JsonApi\Decoders
18
 */
19
class Context
20
{
21
    /**
22
     * @var array
23
     */
24
    protected $resources = [];
25
26
    /**
27
     * @var array
28
     */
29
    protected $linked = [];
30
31
    /**
32
     * Register resource with specified type and id
33
     *
34
     * @param string $type
35
     * @param string $id
36
     * @param mixed $resource
37
     * @return self
38
     */
39 5
    public function registerResource($type, $id, $resource)
40
    {
41 5
        if (!isset($this->resources[$type])) {
42 5
            $this->resources[$type] = [];
43
        }
44
45 5
        if (isset($this->resources[$type][$id])) {
46 1
            throw new \RuntimeException(sprintf(
47 1
                "Resource with type '%s' and id '%s' already registered",
48 1
                $type,
49 1
                $id
50
            ));
51
        }
52
53 5
        $this->resources[$type][$id] = $resource;
54
55 5
        return $this;
56
    }
57
58
    /**
59
     * Returns resource with specified type and id
60
     *
61
     * @param string $type
62
     * @param string $id
63
     * @return mixed|null
64
     */
65 6
    public function getResource($type, $id)
66
    {
67 6
        if (!isset($this->resources[$type][$id])) {
68 5
            return null;
69
        }
70
71 2
        return $this->resources[$type][$id];
72
    }
73
74
    /**
75
     * Adds linked data
76
     *
77
     * @param string $type
78
     * @param string $id
79
     * @param int $idx
80
     * @param mixed $data
81
     * @return $this
82
     */
83 1
    public function addLinkedData($type, $id, $idx, $data)
84
    {
85 1
        if (!isset($this->linked[$type])) {
86 1
            $this->linked[$type] = [];
87
        }
88
89 1
        $this->linked[$type][$id] = ['idx' => $idx, 'data' => $data];
90
91 1
        return $this;
92
    }
93
94
    /**
95
     * Returns linked data for resource with specified type and id
96
     *
97
     * @param $type
98
     * @param $id
99
     * @return array|null
100
     */
101 4 View Code Duplication
    public function getLinkedData($type, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
    {
103 4
        if (!isset($this->linked[$type][$id])) {
104 4
            return null;
105
        }
106
107 1
        return $this->linked[$type][$id]['data'];
108
    }
109
110 1 View Code Duplication
    public function getLinkedDataIndex($type, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
    {
112 1
        if (!isset($this->linked[$type][$id])) {
113
            return null;
114
        }
115
116 1
        return $this->linked[$type][$id]['idx'];
117
    }
118
}
119