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