Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
25 / 25 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
RuleCheckerStatus | |
100.00% |
25 / 25 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getResult | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getWarmCache | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toArray | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
2 | |||
fromArray | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\AbuseFilter\Parser; |
4 | |
5 | use MediaWiki\Extension\AbuseFilter\Parser\Exception\ExceptionBase; |
6 | use MediaWiki\Extension\AbuseFilter\Parser\Exception\UserVisibleWarning; |
7 | |
8 | class RuleCheckerStatus extends ParserStatus { |
9 | /** @var bool */ |
10 | private $result; |
11 | /** @var bool */ |
12 | private $warmCache; |
13 | |
14 | /** |
15 | * @param bool $result Whether the rule matched |
16 | * @param bool $warmCache Whether we retrieved the AST from cache |
17 | * @param ExceptionBase|null $excep An exception thrown while parsing, or null if it parsed correctly |
18 | * @param UserVisibleWarning[] $warnings |
19 | * @param int $condsUsed |
20 | */ |
21 | public function __construct( |
22 | bool $result, |
23 | bool $warmCache, |
24 | ?ExceptionBase $excep, |
25 | array $warnings, |
26 | int $condsUsed |
27 | ) { |
28 | parent::__construct( $excep, $warnings, $condsUsed ); |
29 | $this->result = $result; |
30 | $this->warmCache = $warmCache; |
31 | } |
32 | |
33 | /** |
34 | * @return bool |
35 | */ |
36 | public function getResult(): bool { |
37 | return $this->result; |
38 | } |
39 | |
40 | /** |
41 | * @return bool |
42 | */ |
43 | public function getWarmCache(): bool { |
44 | return $this->warmCache; |
45 | } |
46 | |
47 | /** |
48 | * Serialize data for edit stash |
49 | * @return array |
50 | */ |
51 | public function toArray(): array { |
52 | return [ |
53 | 'result' => $this->result, |
54 | 'warmCache' => $this->warmCache, |
55 | 'exception' => $this->excep ? $this->excep->toArray() : null, |
56 | 'warnings' => array_map( |
57 | static function ( $warn ) { |
58 | return $warn->toArray(); |
59 | }, |
60 | $this->warnings |
61 | ), |
62 | 'condsUsed' => $this->condsUsed, |
63 | ]; |
64 | } |
65 | |
66 | /** |
67 | * Deserialize data from edit stash |
68 | * @param array $value |
69 | * @return self |
70 | */ |
71 | public static function fromArray( array $value ): self { |
72 | $excClass = $value['exception']['class'] ?? null; |
73 | return new self( |
74 | $value['result'], |
75 | $value['warmCache'], |
76 | $excClass !== null ? call_user_func( [ $excClass, 'fromArray' ], $value['exception'] ) : null, |
77 | array_map( [ UserVisibleWarning::class, 'fromArray' ], $value['warnings'] ), |
78 | $value['condsUsed'] |
79 | ); |
80 | } |
81 | } |