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 ( 5f6b2b...ad565c )
by Mewes
02:16
created

XlsHeaderFooterWrapper::start()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 2
1
<?php
2
3
namespace MewesK\TwigSpreadsheetBundle\Wrapper;
4
5
use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter;
6
7
/**
8
 * Class XlsHeaderFooterWrapper
9
 *
10
 * @package MewesK\TwigSpreadsheetBundle\Wrapper
11
 */
12
class XlsHeaderFooterWrapper extends AbstractWrapper
13
{
14
    /**
15
     * @var array
16
     */
17
    protected $context;
18
    /**
19
     * @var \Twig_Environment
20
     */
21
    protected $environment;
22
    /**
23
     * @var XlsSheetWrapper
24
     */
25
    protected $sheetWrapper;
26
27
    /**
28
     * @var array
29
     */
30
    protected $alignmentAttributes;
31
32
    /**
33
     * @var null|HeaderFooter
34
     */
35
    protected $object;
36
    /**
37
     * @var array
38
     */
39
    protected $attributes;
40
    /**
41
     * @var array
42
     */
43
    protected $mappings;
44
45
    /**
46
     * XlsHeaderFooterWrapper constructor.
47
     *
48
     * @param array $context
49
     * @param \Twig_Environment $environment
50
     * @param XlsSheetWrapper $sheetWrapper
51
     */
52 View Code Duplication
    public function __construct(array $context, \Twig_Environment $environment, XlsSheetWrapper $sheetWrapper)
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...
53
    {
54
        $this->context = $context;
55
        $this->environment = $environment;
56
        $this->sheetWrapper = $sheetWrapper;
57
58
        $this->alignmentAttributes = [];
59
60
        $this->object = null;
61
        $this->attributes = [];
62
        $this->mappings = [];
63
64
        $this->initializeMappings();
65
    }
66
67
    protected function initializeMappings()
68
    {
69
        $this->mappings['scaleWithDocument'] = function ($value) {
70
            $this->object->setScaleWithDocument($value);
71
        };
72
        $this->mappings['alignWithMargins'] = function ($value) {
73
            $this->object->setAlignWithMargins($value);
74
        };
75
    }
76
77
    /**
78
     * @param string $type
79
     * @param array $properties
80
     * @throws \LogicException
81
     */
82
    public function start(string $type, array $properties = [])
83
    {
84
        if ($this->sheetWrapper->getObject() === null) {
85
            throw new \LogicException();
86
        }
87
        if (in_array(strtolower($type),
88
                ['header', 'oddheader', 'evenheader', 'firstheader', 'footer', 'oddfooter', 'evenfooter', 'firstfooter'],
89
                true) === false
90
        ) {
91
            throw new \InvalidArgumentException(sprintf('Unknown type "%s"', $type));
92
        }
93
94
        $this->object = $this->sheetWrapper->getObject()->getHeaderFooter();
95
        $this->attributes['value'] = ['left' => null, 'center' => null, 'right' => null]; // will be generated by the alignment tags
96
        $this->attributes['type'] = $type;
97
        $this->attributes['properties'] = $properties;
98
99
        $this->setProperties($properties, $this->mappings);
100
    }
101
102
    public function end()
103
    {
104
        $value = implode('', $this->attributes['value']);
105
106
        switch (strtolower($this->attributes['type'])) {
107
            case 'header':
108
                $this->object->setOddHeader($value);
109
                $this->object->setEvenHeader($value);
110
                $this->object->setFirstHeader($value);
111
                break;
112
            case 'oddheader':
113
                $this->object->setDifferentOddEven(true);
114
                $this->object->setOddHeader($value);
115
                break;
116
            case 'evenheader':
117
                $this->object->setDifferentOddEven(true);
118
                $this->object->setEvenHeader($value);
119
                break;
120
            case 'firstheader':
121
                $this->object->setDifferentFirst(true);
122
                $this->object->setFirstHeader($value);
123
                break;
124
            case 'footer':
125
                $this->object->setOddFooter($value);
126
                $this->object->setEvenFooter($value);
127
                $this->object->setFirstFooter($value);
128
                break;
129
            case 'oddfooter':
130
                $this->object->setDifferentOddEven(true);
131
                $this->object->setOddFooter($value);
132
                break;
133
            case 'evenfooter':
134
                $this->object->setDifferentOddEven(true);
135
                $this->object->setEvenFooter($value);
136
                break;
137
            case 'firstfooter':
138
                $this->object->setDifferentFirst(true);
139
                $this->object->setFirstFooter($value);
140
                break;
141
            default:
142
                throw new \InvalidArgumentException(sprintf('Unknown type "%s"', $this->attributes['type']));
143
        }
144
145
        $this->object = null;
146
        $this->attributes = [];
147
    }
148
149
    /**
150
     * @param string $type
151
     * @param array $properties
152
     * @throws \InvalidArgumentException
153
     */
154
    public function startAlignment(string $type, array $properties = [])
155
    {
156
        $this->alignmentAttributes['type'] = $type;
157
        $this->alignmentAttributes['properties'] = $properties;
158
159
        switch (strtolower($type)) {
160
            case 'left':
161
                $this->attributes['value']['left'] = '&L';
162
                break;
163
            case 'center':
164
                $this->attributes['value']['center'] = '&C';
165
                break;
166
            case 'right':
167
                $this->attributes['value']['right'] = '&R';
168
                break;
169
            default:
170
                throw new \InvalidArgumentException(sprintf('Unknown alignment type "%s"', $this->alignmentAttributes['type']));
171
        }
172
    }
173
174
    /**
175
     * @param string $value
176
     * @throws \InvalidArgumentException
177
     */
178
    public function endAlignment($value)
179
    {
180
        switch (strtolower($this->alignmentAttributes['type'])) {
181 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...
182
                if (strpos($this->attributes['value']['left'], '&G') === false) {
183
                    $this->attributes['value']['left'] .= $value;
184
                }
185
                break;
186 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...
187
                if (strpos($this->attributes['value']['center'], '&G') === false) {
188
                    $this->attributes['value']['center'] .= $value;
189
                }
190
                break;
191 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...
192
                if (strpos($this->attributes['value']['right'], '&G') === false) {
193
                    $this->attributes['value']['right'] .= $value;
194
                }
195
                break;
196
            default:
197
                throw new \InvalidArgumentException(sprintf('Unknown alignment type "%s"', $this->alignmentAttributes['type']));
198
        }
199
200
        $this->alignmentAttributes = [];
201
    }
202
203
    //
204
    // Getters/Setters
205
    //
206
207
    /**
208
     * @return null|HeaderFooter
209
     */
210
    public function getObject()
211
    {
212
        return $this->object;
213
    }
214
215
    /**
216
     * @param null|HeaderFooter $object
217
     */
218
    public function setObject(HeaderFooter $object = null)
219
    {
220
        $this->object = $object;
221
    }
222
223
    /**
224
     * @return array
225
     */
226
    public function getAttributes(): array
227
    {
228
        return $this->attributes;
229
    }
230
231
    /**
232
     * @param array $attributes
233
     */
234
    public function setAttributes(array $attributes)
235
    {
236
        $this->attributes = $attributes;
237
    }
238
239
    /**
240
     * @return array
241
     */
242
    public function getMappings(): array
243
    {
244
        return $this->mappings;
245
    }
246
247
    /**
248
     * @param array $mappings
249
     */
250
    public function setMappings(array $mappings)
251
    {
252
        $this->mappings = $mappings;
253
    }
254
255
    /**
256
     * @return array
257
     */
258
    public function getAlignmentAttributes(): array
259
    {
260
        return $this->alignmentAttributes;
261
    }
262
263
    /**
264
     * @param array $alignmentAttributes
265
     */
266
    public function setAlignmentAttributes(array $alignmentAttributes)
267
    {
268
        $this->alignmentAttributes = $alignmentAttributes;
269
    }
270
}
271