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 / Expression.php

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

71 lines 1.9 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 Expression formula(string $expression)
11 */
12 class Expression extends WizardAbstract implements WizardInterface
13 {
14 protected string $expression;
15
16 public function __construct(string $cellRange)
17 {
18 parent::__construct($cellRange);
19 }
20
21 public function expression(string $expression): self
22 {
23 $expression = $this->validateOperand($expression, Wizard::VALUE_TYPE_FORMULA);
24 $this->expression = $expression;
25
26 return $this;
27 }
28
29 public function getConditional(): Conditional
30 {
31 /** @var string[] */
32 $expression = $this->adjustConditionsForCellReferences([$this->expression]);
33
34 $conditional = new Conditional();
35 $conditional->setConditionType(Conditional::CONDITION_EXPRESSION);
36 $conditional->setConditions($expression);
37 $conditional->setStyle($this->getStyle());
38 $conditional->setStopIfTrue($this->getStopIfTrue());
39
40 return $conditional;
41 }
42
43 public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface
44 {
45 if ($conditional->getConditionType() !== Conditional::CONDITION_EXPRESSION) {
46 throw new Exception('Conditional is not an Expression CF Rule conditional');
47 }
48
49 $wizard = new self($cellRange);
50 $wizard->style = $conditional->getStyle();
51 $wizard->stopIfTrue = $conditional->getStopIfTrue();
52 $wizard->expression = self::reverseAdjustCellRef((string) ($conditional->getConditions()[0]), $cellRange);
53
54 return $wizard;
55 }
56
57 /**
58 * @param string[] $arguments
59 */
60 public function __call(string $methodName, array $arguments): self
61 {
62 if ($methodName !== 'formula') {
63 throw new Exception('Invalid Operation for Expression CF Rule Wizard');
64 }
65
66 $this->expression(...$arguments);
67
68 return $this;
69 }
70 }
71