PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Style / ConditionalFormatting / Wizard / Errors.php

Errors.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/Errors.php

92 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Exception;
6 use TablePress\PhpOffice\PhpSpreadsheet\Style\Conditional;
7 use TablePress\PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard;
8
9 /**
10 * @method Errors notError()
11 * @method Errors isError()
12 */
13 class Errors extends WizardAbstract implements WizardInterface
14 {
15 protected const OPERATORS = [
16 'notError' => false,
17 'isError' => true,
18 ];
19
20 protected const EXPRESSIONS = [
21 Wizard::NOT_ERRORS => 'NOT(ISERROR(%s))',
22 Wizard::ERRORS => 'ISERROR(%s)',
23 ];
24
25 protected bool $inverse;
26
27 public function __construct(string $cellRange, bool $inverse = false)
28 {
29 parent::__construct($cellRange);
30 $this->inverse = $inverse;
31 }
32
33 protected function inverse(bool $inverse): void
34 {
35 $this->inverse = $inverse;
36 }
37
38 protected function getExpression(): void
39 {
40 $this->expression = sprintf(
41 self::EXPRESSIONS[$this->inverse ? Wizard::ERRORS : Wizard::NOT_ERRORS],
42 $this->referenceCell
43 );
44 }
45
46 public function getConditional(): Conditional
47 {
48 $this->getExpression();
49
50 $conditional = new Conditional();
51 $conditional->setConditionType(
52 $this->inverse ? Conditional::CONDITION_CONTAINSERRORS : Conditional::CONDITION_NOTCONTAINSERRORS
53 );
54 $conditional->setConditions([$this->expression]);
55 $conditional->setStyle($this->getStyle());
56 $conditional->setStopIfTrue($this->getStopIfTrue());
57
58 return $conditional;
59 }
60
61 public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface
62 {
63 if (
64 $conditional->getConditionType() !== Conditional::CONDITION_CONTAINSERRORS
65 && $conditional->getConditionType() !== Conditional::CONDITION_NOTCONTAINSERRORS
66 ) {
67 throw new Exception('Conditional is not an Errors CF Rule conditional');
68 }
69
70 $wizard = new self($cellRange);
71 $wizard->style = $conditional->getStyle();
72 $wizard->stopIfTrue = $conditional->getStopIfTrue();
73 $wizard->inverse = $conditional->getConditionType() === Conditional::CONDITION_CONTAINSERRORS;
74
75 return $wizard;
76 }
77
78 /**
79 * @param mixed[] $arguments
80 */
81 public function __call(string $methodName, array $arguments): self
82 {
83 if (!array_key_exists($methodName, self::OPERATORS)) {
84 throw new Exception('Invalid Operation for Errors CF Rule Wizard');
85 }
86
87 $this->inverse(self::OPERATORS[$methodName]);
88
89 return $this;
90 }
91 }
92