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

PhpSpreadsheetWrapper::startAlignment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Erelke\TwigSpreadsheetBundle\Wrapper;
4
5
use InvalidArgumentException;
6
use function is_array;
7
use LogicException;
8
use PhpOffice\PhpSpreadsheet\Exception;
9
use RuntimeException;
10
use Symfony\Component\Filesystem\Exception\IOException;
11
use Twig\Environment as Twig_Environment;
12
use \PhpOffice\PhpSpreadsheet\Reader\Exception as Reader_Exception;
13
use \PhpOffice\PhpSpreadsheet\Writer\Exception as Writer_Exception;
14
15
/**
16
 * Class PhpSpreadsheetWrapper.
17
 */
18
class PhpSpreadsheetWrapper
19
{
20
    /**
21
     * @var string
22
     */
23
    const INSTANCE_KEY = '_tsb';
24
25
    /**
26
     * Copies the PhpSpreadsheetWrapper instance from 'varargs' to '_tsb'. This is necessary for all Twig code running
27
     * in sub-functions (e.g. block, macro, ...) since the root context is lost. To fix the sub-context a reference to
28
     * the PhpSpreadsheetWrapper instance is included in all function calls.
29
     *
30
     * @param array $context
31
     *
32
     * @return array
33
     */
34
    public static function fixContext(array $context): array
35
    {
36
        if (!isset($context[self::INSTANCE_KEY]) && isset($context['varargs']) && is_array($context['varargs'])) {
37
            foreach ($context['varargs'] as $arg) {
38
                if ($arg instanceof self) {
39
                    $context[self::INSTANCE_KEY] = $arg;
40
                    break;
41
                }
42
            }
43
        }
44
        return $context;
45
    }
46
47
    /**
48
     * @var DocumentWrapper
49
     */
50
    private $documentWrapper;
51
    /**
52
     * @var SheetWrapper
53
     */
54
    private $sheetWrapper;
55
    /**
56
     * @var RowWrapper
57
     */
58
    private $rowWrapper;
59
    /**
60
     * @var CellWrapper
61
     */
62
    private $cellWrapper;
63
    /**
64
     * @var HeaderFooterWrapper
65
     */
66
    private $headerFooterWrapper;
67
    /**
68
     * @var DrawingWrapper
69
     */
70
    private $drawingWrapper;
71
72
    /**
73
     * PhpSpreadsheetWrapper constructor.
74
     *
75
     * @param array             $context
76
     * @param Twig_Environment $environment
77
     * @param array             $attributes
78
     */
79
    public function __construct(array $context, Twig_Environment $environment, array $attributes = [])
80
    {
81
        $this->documentWrapper = new DocumentWrapper($context, $environment, $attributes);
82
        $this->sheetWrapper = new SheetWrapper($context, $environment, $this->documentWrapper);
83
        $this->rowWrapper = new RowWrapper($context, $environment, $this->sheetWrapper);
84
        $this->cellWrapper = new CellWrapper($context, $environment, $this->sheetWrapper);
85
        $this->headerFooterWrapper = new HeaderFooterWrapper($context, $environment, $this->sheetWrapper);
86
        $this->drawingWrapper = new DrawingWrapper($context, $environment, $this->sheetWrapper, $this->headerFooterWrapper, $attributes);
87
    }
88
89
    /**
90
     * @return int|null
91
     */
92
    public function getCurrentColumn()
93
    {
94
        return $this->sheetWrapper->getColumn();
95
    }
96
97
    /**
98
     * @return int|null
99
     */
100
    public function getCurrentRow()
101
    {
102
        return $this->sheetWrapper->getRow();
103
    }
104
105
    /**
106
     * @param array $properties
107
     *
108
     * @throws Exception
109
     * @throws Reader_Exception
110
     * @throws RuntimeException
111
     */
112
    public function startDocument(array $properties = [])
113
    {
114
        $this->documentWrapper->start($properties);
115
    }
116
117
    /**
118
     * @throws RuntimeException
119
     * @throws LogicException
120
     * @throws InvalidArgumentException
121
     * @throws Exception
122
     * @throws Writer_Exception
123
     * @throws IOException
124
     */
125
    public function endDocument()
126
    {
127
        $this->documentWrapper->end();
128
    }
129
130
    /**
131
     * @param int|string|null $index
132
     * @param array $properties
133
     *
134
     * @throws LogicException
135
     * @throws Exception
136
     * @throws RuntimeException
137
     */
138
    public function startSheet($index = null, array $properties = [])
139
    {
140
        $this->sheetWrapper->start($index, $properties);
141
    }
142
143
    /**
144
     * @throws LogicException
145
     * @throws \Exception
146
     */
147
    public function endSheet()
148
    {
149
        $this->sheetWrapper->end();
150
    }
151
152
    /**
153
     * @param int|null $index
154
     *
155
     * @throws LogicException
156
     */
157
    public function startRow(int $index = null)
158
    {
159
        $this->rowWrapper->start($index);
160
    }
161
162
    /**
163
     * @throws LogicException
164
     */
165
    public function endRow()
166
    {
167
        $this->rowWrapper->end();
168
    }
169
170
    /**
171
     * @param int|null   $index
172
     * @param array      $properties
173
     *
174
     * @throws InvalidArgumentException
175
     * @throws LogicException
176
     * @throws RuntimeException
177
     */
178
    public function startCell(int $index = null, array $properties = [])
179
    {
180
        $this->cellWrapper->start($index, $properties);
181
    }
182
183
    /**
184
     * @param null|mixed $value
185
     *
186
     * @throws Exception
187
     */
188
    public function setCellValue($value = null)
189
    {
190
        $this->cellWrapper->value($value);
191
    }
192
193
    public function endCell()
194
    {
195
        $this->cellWrapper->end();
196
    }
197
198
    /**
199
     * @param string      $baseType
200
     * @param string|null $type
201
     * @param array       $properties
202
     *
203
     * @throws LogicException
204
     * @throws RuntimeException
205
     * @throws InvalidArgumentException
206
     */
207
    public function startHeaderFooter(string $baseType, string $type = null, array $properties = [])
208
    {
209
        $this->headerFooterWrapper->start($baseType, $type, $properties);
210
    }
211
212
    /**
213
     * @throws LogicException
214
     * @throws InvalidArgumentException
215
     */
216
    public function endHeaderFooter()
217
    {
218
        $this->headerFooterWrapper->end();
219
    }
220
221
    /**
222
     * @param null|string $type
223
     * @param array       $properties
224
     *
225
     * @throws InvalidArgumentException
226
     * @throws LogicException
227
     */
228
    public function startAlignment(string $type = null, array $properties = [])
229
    {
230
        $this->headerFooterWrapper->startAlignment($type, $properties);
231
    }
232
233
    /**
234
     * @param null|string $value
235
     *
236
     * @throws InvalidArgumentException
237
     * @throws LogicException
238
     */
239
    public function endAlignment(string $value = null)
240
    {
241
        $this->headerFooterWrapper->endAlignment($value);
242
    }
243
244
    /**
245
     * @param string $path
246
     * @param array $properties
247
     *
248
     * @throws IOException
249
     * @throws InvalidArgumentException
250
     * @throws LogicException
251
     * @throws RuntimeException
252
     * @throws Exception
253
     */
254
    public function startDrawing(string $path, array $properties = [])
255
    {
256
        $this->drawingWrapper->start($path, $properties);
257
    }
258
259
    public function endDrawing()
260
    {
261
        $this->drawingWrapper->end();
262
    }
263
}
264