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

CellWrapper::value()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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