Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| AbuseFilterPermissionStatus | |
100.00% |
15 / 15 |
|
100.00% |
7 / 7 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| newBlockedError | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| newPermissionError | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getBlock | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPermission | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setBlock | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setPermission | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\AbuseFilter; |
| 4 | |
| 5 | use MediaWiki\Block\Block; |
| 6 | use StatusValue; |
| 7 | |
| 8 | /** |
| 9 | * Type-safe StatusValue holding the result of a permission check performed in AbuseFilterPermissionManager. |
| 10 | * |
| 11 | * Modified copy of the CheckUserPermissionStatus from mediawiki/extensions/CheckUser. |
| 12 | * |
| 13 | * @template T |
| 14 | * @inherits StatusValue<T> |
| 15 | */ |
| 16 | class AbuseFilterPermissionStatus extends StatusValue { |
| 17 | /** @var Block|null The user block, if any, that caused this permission check to fail. */ |
| 18 | private ?Block $block = null; |
| 19 | |
| 20 | /** @var string|null The missing permission - if applicable - that caused this permission check to fail. */ |
| 21 | private ?string $permission = null; |
| 22 | |
| 23 | /** |
| 24 | * @suppress PhanGenericConstructorTypes |
| 25 | */ |
| 26 | protected function __construct() { |
| 27 | // Use typed static factory methods. |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Create a new fatal AbuseFilterPermissionStatus instance holding an user block. |
| 32 | * |
| 33 | * @param Block $block The block that caused the permission check to fail. |
| 34 | * @return AbuseFilterPermissionStatus |
| 35 | */ |
| 36 | public static function newBlockedError( Block $block ): AbuseFilterPermissionStatus { |
| 37 | $status = new static(); |
| 38 | $status->block = $block; |
| 39 | $status->ok = false; |
| 40 | |
| 41 | return $status; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Create a new fatal AbuseFilterPermissionStatus instance holding a permission error. |
| 46 | * |
| 47 | * @param string $permission The missing permission. |
| 48 | * @return AbuseFilterPermissionStatus |
| 49 | */ |
| 50 | public static function newPermissionError( string $permission ): AbuseFilterPermissionStatus { |
| 51 | $status = new static(); |
| 52 | $status->permission = $permission; |
| 53 | $status->ok = false; |
| 54 | |
| 55 | return $status; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Get the block that caused this permission check to fail. |
| 60 | * |
| 61 | * @return Block|null |
| 62 | */ |
| 63 | public function getBlock(): ?Block { |
| 64 | return $this->block; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Get the missing permission that caused this check to fail. |
| 69 | * |
| 70 | * @return string|null |
| 71 | */ |
| 72 | public function getPermission(): ?string { |
| 73 | return $this->permission; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Sets the block that caused the permission check to fail. |
| 78 | * |
| 79 | * Use this method if you are modifying an existing instance of the {@link AbuseFilterPermissionStatus}. |
| 80 | * Otherwise, it is recommended to use {@link AbuseFilterPermissionStatus::newBlockedError}. |
| 81 | * |
| 82 | * @param Block $block |
| 83 | */ |
| 84 | public function setBlock( Block $block ) { |
| 85 | $this->ok = false; |
| 86 | $this->block = $block; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Sets the missing permission that caused this check to fail. |
| 91 | * |
| 92 | * Use this method if you are modifying an existing instance of the {@link AbuseFilterPermissionStatus}. |
| 93 | * Otherwise, it is recommended to use {@link AbuseFilterPermissionStatus::newPermissionError}. |
| 94 | * |
| 95 | * @param string $permission |
| 96 | */ |
| 97 | public function setPermission( string $permission ) { |
| 98 | $this->ok = false; |
| 99 | $this->permission = $permission; |
| 100 | } |
| 101 | } |