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 ( f8e5a3...1b3ca1 )
by Mewes
04:44
created

BaseWrapper::getMappings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace MewesK\TwigSpreadsheetBundle\Wrapper;
4
5
/**
6
 * Class BaseWrapper.
7
 */
8
abstract class BaseWrapper
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $context;
14
15
    /**
16
     * @var \Twig_Environment
17
     */
18
    protected $environment;
19
20
    /**
21
     * @var array
22
     */
23
    protected $attributes;
24
    /**
25
     * @var array
26
     */
27
    protected $mappings;
28
29
    /**
30
     * BaseWrapper constructor.
31
     *
32
     * @param array             $context
33
     * @param \Twig_Environment $environment
34
     */
35
    public function __construct(array $context, \Twig_Environment $environment)
36
    {
37
        $this->context = $context;
38
        $this->environment = $environment;
39
40
        $this->attributes = [];
41
        $this->mappings = $this->configureMappings();
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function getAttributes(): array
48
    {
49
        return $this->attributes;
50
    }
51
52
    /**
53
     * @param array $attributes
54
     */
55
    public function setAttributes(array $attributes)
56
    {
57
        $this->attributes = $attributes;
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function getMappings(): array
64
    {
65
        return $this->mappings;
66
    }
67
68
    /**
69
     * @param array $mappings
70
     */
71
    public function setMappings(array $mappings)
72
    {
73
        $this->mappings = $mappings;
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    protected function configureMappings(): array
80
    {
81
        return [];
82
    }
83
84
    /**
85
     * Calls the matching mapping callable for each property.
86
     *
87
     * @param array       $properties
88
     * @param array       $mappings
89
     * @param string|null $column
90
     *
91
     * @throws \RuntimeException
92
     */
93
    protected function setProperties(array $properties, array $mappings, string $column = null)
94
    {
95
        foreach ($properties as $key => $value) {
96
            if (!isset($mappings[$key])) {
97
                throw new \RuntimeException(sprintf('No mapping found for key "%s"', $key));
98
            }
99
100
            if (is_array($value) && is_array($mappings[$key])) {
101
                // recursion
102
                if (isset($mappings[$key]['__multi'])) {
103
                    // handle multi target structure (with columns)
104
                    /**
105
                     * @var array $value
106
                     */
107
                    foreach ($value as $_column => $_value) {
108
                        $this->setProperties($_value, $mappings[$key], $_column);
109
                    }
110
                } else {
111
                    // handle single target structure
112
                    $this->setProperties($value, $mappings[$key]);
113
                }
114
            } elseif (is_callable($mappings[$key])) {
115
                // call single and multi target mapping
116
                // if column is set it is used to get object from the callback in __multi
117
                $mappings[$key](
118
                    $value,
119
                    $column !== null ? $mappings['__multi']($column) : null
120
                );
121
            } else {
122
                throw new \RuntimeException(sprintf('Invalid mapping for key "%s"', $key));
123
            }
124
        }
125
    }
126
}
127