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