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.
Passed
Push — master ( b43f4a...009a79 )
by Mewes
10:25
created

CellWrapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
3
namespace MewesK\TwigSpreadsheetBundle\Wrapper;
4
5
use PhpOffice\PhpSpreadsheet\Cell;
6
7
/**
8
 * Class CellWrapper.
9
 */
10
class CellWrapper extends BaseWrapper
11
{
12
    /**
13
     * @var SheetWrapper
14
     */
15
    protected $sheetWrapper;
16
17
    /**
18
     * @var Cell|null
19
     */
20
    protected $object;
21
22
    /**
23
     * CellWrapper constructor.
24
     *
25
     * @param array             $context
26
     * @param \Twig_Environment $environment
27
     * @param SheetWrapper      $sheetWrapper
28
     */
29 115
    public function __construct(array $context, \Twig_Environment $environment, SheetWrapper $sheetWrapper)
30
    {
31 115
        parent::__construct($context, $environment);
32
33 115
        $this->sheetWrapper = $sheetWrapper;
34
35 115
        $this->object = null;
36 115
    }
37
38
    /**
39
     * @param int|null   $index
40
     * @param mixed|null $value
41
     * @param array      $properties
42
     *
43
     * @throws \InvalidArgumentException
44
     * @throws \LogicException
45
     * @throws \PhpOffice\PhpSpreadsheet\Exception
46
     * @throws \RuntimeException
47
     */
48 73
    public function start(int $index = null, $value = null, array $properties = [])
49
    {
50 73
        if ($this->sheetWrapper->getObject() === null) {
51
            throw new \LogicException();
52
        }
53
54 73
        if ($index === null) {
55 73
            $this->sheetWrapper->increaseColumn();
56
        } else {
57 13
            $this->sheetWrapper->setColumn($index);
58
        }
59
60 73
        $this->object = $this->sheetWrapper->getObject()->getCellByColumnAndRow($this->sheetWrapper->getColumn(),
61 73
            $this->sheetWrapper->getRow());
62
63 73
        if ($value !== null) {
64 73
            if (isset($properties['dataType'])) {
65 7
                $this->object->setValueExplicit($value, $properties['dataType']);
66
            } else {
67 73
                $this->object->setValue($value);
68
            }
69
        }
70
71 73
        $this->parameters['value'] = $value;
72 73
        $this->parameters['properties'] = $properties;
73
74 73
        $this->setProperties($properties);
75 73
    }
76
77 73
    public function end()
78
    {
79 73
        $this->object = null;
80 73
        $this->parameters = [];
81 73
    }
82
83
    /**
84
     * @return Cell|null
85
     */
86
    public function getObject()
87
    {
88
        return $this->object;
89
    }
90
91
    /**
92
     * @param Cell|null $object
93
     */
94
    public function setObject(Cell $object = null)
95
    {
96
        $this->object = $object;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 115
    protected function configureMappings(): array
103
    {
104
        return [
105
            'break' => function ($value) { $this->sheetWrapper->getObject()->setBreak($this->object->getCoordinate(), $value); },
106
            'dataType' => function ($value) { $this->object->setDataType($value); },
107
            'dataValidation' => [
108
                'allowBlank' => function ($value) { $this->object->getDataValidation()->setAllowBlank($value); },
109
                'error' => function ($value) { $this->object->getDataValidation()->setError($value); },
110
                'errorStyle' => function ($value) { $this->object->getDataValidation()->setErrorStyle($value); },
111
                'errorTitle' => function ($value) { $this->object->getDataValidation()->setErrorTitle($value); },
112
                'formula1' => function ($value) { $this->object->getDataValidation()->setFormula1($value); },
113
                'formula2' => function ($value) { $this->object->getDataValidation()->setFormula2($value); },
114
                'operator' => function ($value) { $this->object->getDataValidation()->setOperator($value); },
115
                'prompt' => function ($value) { $this->object->getDataValidation()->setPrompt($value); },
116
                'promptTitle' => function ($value) { $this->object->getDataValidation()->setPromptTitle($value); },
117
                'showDropDown' => function ($value) { $this->object->getDataValidation()->setShowDropDown($value); },
118
                'showErrorMessage' => function ($value) { $this->object->getDataValidation()->setShowErrorMessage($value); },
119
                'showInputMessage' => function ($value) { $this->object->getDataValidation()->setShowInputMessage($value); },
120
                'type' => function ($value) { $this->object->getDataValidation()->setType($value); },
121
            ],
122
            'merge' => function ($value) {
123 2
                if (is_int($value)) {
124 2
                    $value = Cell::stringFromColumnIndex($value).$this->sheetWrapper->getRow();
125
                }
126 2
                $this->sheetWrapper->getObject()->mergeCells(sprintf('%s:%s', $this->object->getCoordinate(), $value));
127 115
            },
128
            'style' => function ($value) { $this->sheetWrapper->getObject()->getStyle($this->object->getCoordinate())->applyFromArray($value); },
129
            'url' => function ($value) { $this->object->getHyperlink()->setUrl($value); },
130
        ];
131
    }
132
}
133