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 ( 78f8b7...0f754d )
by Elemér
04:15
created

BaseWrapper   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 0
dl 0
loc 123
rs 10
c 0
b 0
f 0

7 Methods

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