tablepress
/
libraries
/
vendor
/
PhpSpreadsheet
/
Style
/
ConditionalFormatting
/
Wizard
/
Duplicates.php
Duplicates.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/Duplicates.php
| 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 | |
| 8 | /** |
| 9 | * @method Errors duplicates() |
| 10 | * @method Errors unique() |
| 11 | */ |
| 12 | class Duplicates extends WizardAbstract implements WizardInterface |
| 13 | { |
| 14 | protected const OPERATORS = [ |
| 15 | 'duplicates' => false, |
| 16 | 'unique' => true, |
| 17 | ]; |
| 18 | |
| 19 | protected bool $inverse; |
| 20 | |
| 21 | public function __construct(string $cellRange, bool $inverse = false) |
| 22 | { |
| 23 | parent::__construct($cellRange); |
| 24 | $this->inverse = $inverse; |
| 25 | } |
| 26 | |
| 27 | protected function inverse(bool $inverse): void |
| 28 | { |
| 29 | $this->inverse = $inverse; |
| 30 | } |
| 31 | |
| 32 | public function getConditional(): Conditional |
| 33 | { |
| 34 | $conditional = new Conditional(); |
| 35 | $conditional->setConditionType( |
| 36 | $this->inverse ? Conditional::CONDITION_UNIQUE : Conditional::CONDITION_DUPLICATES |
| 37 | ); |
| 38 | $conditional->setStyle($this->getStyle()); |
| 39 | $conditional->setStopIfTrue($this->getStopIfTrue()); |
| 40 | |
| 41 | return $conditional; |
| 42 | } |
| 43 | |
| 44 | public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface |
| 45 | { |
| 46 | if ( |
| 47 | $conditional->getConditionType() !== Conditional::CONDITION_DUPLICATES |
| 48 | && $conditional->getConditionType() !== Conditional::CONDITION_UNIQUE |
| 49 | ) { |
| 50 | throw new Exception('Conditional is not a Duplicates CF Rule conditional'); |
| 51 | } |
| 52 | |
| 53 | $wizard = new self($cellRange); |
| 54 | $wizard->style = $conditional->getStyle(); |
| 55 | $wizard->stopIfTrue = $conditional->getStopIfTrue(); |
| 56 | $wizard->inverse = $conditional->getConditionType() === Conditional::CONDITION_UNIQUE; |
| 57 | |
| 58 | return $wizard; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @param mixed[] $arguments |
| 63 | */ |
| 64 | public function __call(string $methodName, array $arguments): self |
| 65 | { |
| 66 | if (!array_key_exists($methodName, self::OPERATORS)) { |
| 67 | throw new Exception('Invalid Operation for Duplicates CF Rule Wizard'); |
| 68 | } |
| 69 | |
| 70 | $this->inverse(self::OPERATORS[$methodName]); |
| 71 | |
| 72 | return $this; |
| 73 | } |
| 74 | } |
| 75 |