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 ( 1b3ca1...0529a5 )
by Mewes
03:22
created

HeaderFooterWrapper::setAlignmentParameters()   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 1
1
<?php
2
3
namespace MewesK\TwigSpreadsheetBundle\Wrapper;
4
5
use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter;
6
7
/**
8
 * Class HeaderFooterWrapper.
9
 */
10
class HeaderFooterWrapper extends BaseWrapper
11
{
12
    /**
13
     * @var SheetWrapper
14
     */
15
    protected $sheetWrapper;
16
17
    /**
18
     * @var null|HeaderFooter
19
     */
20
    protected $object;
21
    /**
22
     * @var array
23
     */
24
    protected $alignmentParameters;
25
26
    /**
27
     * HeaderFooterWrapper constructor.
28
     *
29
     * @param array             $context
30
     * @param \Twig_Environment $environment
31
     * @param SheetWrapper      $sheetWrapper
32
     */
33
    public function __construct(array $context, \Twig_Environment $environment, SheetWrapper $sheetWrapper)
34
    {
35
        parent::__construct($context, $environment);
36
37
        $this->sheetWrapper = $sheetWrapper;
38
39
        $this->object = null;
40
        $this->alignmentParameters = [];
41
    }
42
43
    /**
44
     * @param string $type
45
     * @param array  $properties
46
     *
47
     * @throws \InvalidArgumentException
48
     * @throws \LogicException
49
     * @throws \RuntimeException
50
     */
51
    public function start(string $type, array $properties = [])
52
    {
53
        if ($this->sheetWrapper->getObject() === null) {
54
            throw new \LogicException();
55
        }
56
        if (in_array(strtolower($type),
57
                ['header', 'oddheader', 'evenheader', 'firstheader', 'footer', 'oddfooter', 'evenfooter', 'firstfooter'],
58
                true) === false
59
        ) {
60
            throw new \InvalidArgumentException(sprintf('Unknown type "%s"', $type));
61
        }
62
63
        $this->object = $this->sheetWrapper->getObject()->getHeaderFooter();
64
        $this->parameters['value'] = ['left' => null, 'center' => null, 'right' => null]; // will be generated by the alignment tags
65
        $this->parameters['type'] = $type;
66
        $this->parameters['properties'] = $properties;
67
68
        $this->setProperties($properties);
69
    }
70
71
    public function end()
72
    {
73
        $value = implode('', $this->parameters['value']);
74
75
        switch (strtolower($this->parameters['type'])) {
76
            case 'header':
77
                $this->object->setOddHeader($value);
78
                $this->object->setEvenHeader($value);
79
                $this->object->setFirstHeader($value);
80
                break;
81
            case 'oddheader':
82
                $this->object->setDifferentOddEven(true);
83
                $this->object->setOddHeader($value);
84
                break;
85
            case 'evenheader':
86
                $this->object->setDifferentOddEven(true);
87
                $this->object->setEvenHeader($value);
88
                break;
89
            case 'firstheader':
90
                $this->object->setDifferentFirst(true);
91
                $this->object->setFirstHeader($value);
92
                break;
93
            case 'footer':
94
                $this->object->setOddFooter($value);
95
                $this->object->setEvenFooter($value);
96
                $this->object->setFirstFooter($value);
97
                break;
98
            case 'oddfooter':
99
                $this->object->setDifferentOddEven(true);
100
                $this->object->setOddFooter($value);
101
                break;
102
            case 'evenfooter':
103
                $this->object->setDifferentOddEven(true);
104
                $this->object->setEvenFooter($value);
105
                break;
106
            case 'firstfooter':
107
                $this->object->setDifferentFirst(true);
108
                $this->object->setFirstFooter($value);
109
                break;
110
            default:
111
                throw new \InvalidArgumentException(sprintf('Unknown type "%s"', $this->parameters['type']));
112
        }
113
114
        $this->object = null;
115
        $this->parameters = [];
116
    }
117
118
    /**
119
     * @param string $type
120
     * @param array  $properties
121
     *
122
     * @throws \InvalidArgumentException
123
     */
124
    public function startAlignment(string $type, array $properties = [])
125
    {
126
        $this->alignmentParameters['type'] = $type;
127
        $this->alignmentParameters['properties'] = $properties;
128
129
        switch (strtolower($type)) {
130
            case 'left':
131
                $this->parameters['value']['left'] = '&L';
132
                break;
133
            case 'center':
134
                $this->parameters['value']['center'] = '&C';
135
                break;
136
            case 'right':
137
                $this->parameters['value']['right'] = '&R';
138
                break;
139
            default:
140
                throw new \InvalidArgumentException(sprintf('Unknown alignment type "%s"', $this->alignmentParameters['type']));
141
        }
142
    }
143
144
    /**
145
     * @param string $value
146
     *
147
     * @throws \InvalidArgumentException
148
     */
149
    public function endAlignment($value)
150
    {
151
        switch (strtolower($this->alignmentParameters['type'])) {
152 View Code Duplication
            case 'left':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
153
                if (strpos($this->parameters['value']['left'], '&G') === false) {
154
                    $this->parameters['value']['left'] .= $value;
155
                }
156
                break;
157 View Code Duplication
            case 'center':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
158
                if (strpos($this->parameters['value']['center'], '&G') === false) {
159
                    $this->parameters['value']['center'] .= $value;
160
                }
161
                break;
162 View Code Duplication
            case 'right':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
163
                if (strpos($this->parameters['value']['right'], '&G') === false) {
164
                    $this->parameters['value']['right'] .= $value;
165
                }
166
                break;
167
            default:
168
                throw new \InvalidArgumentException(sprintf('Unknown alignment type "%s"', $this->alignmentParameters['type']));
169
        }
170
171
        $this->alignmentParameters = [];
172
    }
173
174
    /**
175
     * @return null|HeaderFooter
176
     */
177
    public function getObject()
178
    {
179
        return $this->object;
180
    }
181
182
    /**
183
     * @param null|HeaderFooter $object
184
     */
185
    public function setObject(HeaderFooter $object = null)
186
    {
187
        $this->object = $object;
188
    }
189
190
    /**
191
     * @return array
192
     */
193
    public function getAlignmentParameters(): array
194
    {
195
        return $this->alignmentParameters;
196
    }
197
198
    /**
199
     * @param array $alignmentParameters
200
     */
201
    public function setAlignmentParameters(array $alignmentParameters)
202
    {
203
        $this->alignmentParameters = $alignmentParameters;
204
    }
205
206
    /**
207
     * @return array
208
     */
209
    protected function configureMappings(): array
210
    {
211
        return [
212
            'scaleWithDocument' => function ($value) { $this->object->setScaleWithDocument($value); },
213
            'alignWithMargins' => function ($value) { $this->object->setAlignWithMargins($value); },
214
        ];
215
    }
216
}
217