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.
Test Setup Failed
Push — master ( 33031e...bac02e )
by Mohamed
05:28 queued 12s
created

Base   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 82.61%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 2
dl 0
loc 98
ccs 19
cts 23
cp 0.8261
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setEntityAttributes() 0 13 3
B getArrayCopy() 0 24 6
A getId() 0 4 1
A setId() 0 6 1
A get() 0 10 2
1
<?php
2
3
namespace Neta\Shopware\SDK\Entity;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Support\Str;
7
8
/**
9
 * Class Base.
10
 *
11
 * @author    Alexander Mahrt <[email protected]>
12
 * @copyright 2016 LeadCommerce <[email protected]>
13
 */
14
class Base
15
{
16
    /**
17
     * @var int
18
     */
19
    protected $id;
20
21
    /**
22
     * @var array
23
     */
24
    protected $attributesRaw = [];
25 11
26
    /**
27 11
     * Sets the attributes of this entity.
28 11
     *
29 11
     * @param array $attributes
30 11
     *
31
     * @return $this
32
     */
33
    public function setEntityAttributes(array $attributes)
34 11
    {
35
        $this->attributesRaw = $attributes;
36
37
        foreach ($attributes as $attribute => $value) {
38
            $setter = 'set' . ucfirst($attribute);
39
            if (method_exists($this, $setter)) {
40
                $this->$setter($value);
41
            }
42 4
        }
43
44 4
        return $this;
45
    }
46 4
47 4
    /**
48 1
     * Gets the attributes of this entity.
49 4
     *
50
     * @return array
51
     */
52 4
    public function getArrayCopy()
53
    {
54
        $array = get_object_vars($this);
55
56
        unset($array['attributesRaw']);
57
58
        foreach ($array as $key => &$value) {
59 4
            if ($value instanceof Base) {
60 4
                $array[$key] = $value->getArrayCopy();
61
            } elseif (is_array($value)) {
62 4
                foreach ($value as $k => $v) {
63
                    if ($v instanceof Base) {
64
                        $value[$k] = $v->getArrayCopy();
65
                    }
66
                }
67
            }
68
        }
69
70
        $array = array_filter($array, function ($value) {
71
            return $value !== null;
72
        });
73
74
        return $array;
75
    }
76
77
    /**
78 9
     * @return int
79
     */
80 9
    public function getId()
81
    {
82 9
        return $this->id;
83
    }
84
85
    /**
86
     * @param int $id
87
     *
88
     * @return Base
89
     */
90
    public function setId($id)
91
    {
92
        $this->id = $id;
93
94
        return $this;
95
    }
96
97
    /**
98
     * @param string $key
99
     * @return mixed
100
     */
101
    public function get(string $key)
102
    {
103
        $method = 'get' . Str::camel(ucfirst($key));
104
105
        if (method_exists($this, $method)) {
106
            return $this->$method();
107
        }
108
109
        return Arr::get($this->attributesRaw, $key, null);
110
    }
111
}
112