Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
15 / 15 |
CRAP | |
100.00% |
1 / 1 |
| Flags | |
100.00% |
23 / 23 |
|
100.00% |
15 / 15 |
18 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getEnabled | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setEnabled | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDeleted | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setDeleted | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSuppressed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setSuppressed | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getHidden | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setHidden | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getProtected | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setProtected | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| updatePrivacyLevel | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
4 | |||
| getPrivacyLevel | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getGlobal | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setGlobal | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\AbuseFilter\Filter; |
| 4 | |
| 5 | /** |
| 6 | * (Mutable) value object to represent flags that can be *manually* set on a filter. |
| 7 | */ |
| 8 | class Flags { |
| 9 | private bool $suppressed; |
| 10 | |
| 11 | private bool $hidden; |
| 12 | |
| 13 | private bool $protected; |
| 14 | |
| 15 | public const FILTER_PUBLIC = 0b000; |
| 16 | public const FILTER_SUPPRESSED = 0b100; |
| 17 | public const FILTER_HIDDEN = 0b001; |
| 18 | public const FILTER_USES_PROTECTED_VARS = 0b010; |
| 19 | |
| 20 | public function __construct( |
| 21 | private bool $enabled, |
| 22 | private bool $deleted, |
| 23 | private int $privacyLevel, |
| 24 | private bool $global |
| 25 | ) { |
| 26 | $this->suppressed = (bool)( self::FILTER_SUPPRESSED & $privacyLevel ); |
| 27 | $this->hidden = (bool)( self::FILTER_HIDDEN & $privacyLevel ); |
| 28 | $this->protected = (bool)( self::FILTER_USES_PROTECTED_VARS & $privacyLevel ); |
| 29 | } |
| 30 | |
| 31 | public function getEnabled(): bool { |
| 32 | return $this->enabled; |
| 33 | } |
| 34 | |
| 35 | public function setEnabled( bool $enabled ): void { |
| 36 | $this->enabled = $enabled; |
| 37 | } |
| 38 | |
| 39 | public function getDeleted(): bool { |
| 40 | return $this->deleted; |
| 41 | } |
| 42 | |
| 43 | public function setDeleted( bool $deleted ): void { |
| 44 | $this->deleted = $deleted; |
| 45 | } |
| 46 | |
| 47 | public function getSuppressed(): bool { |
| 48 | return $this->suppressed; |
| 49 | } |
| 50 | |
| 51 | public function setSuppressed( bool $suppressed ): void { |
| 52 | $this->suppressed = $suppressed; |
| 53 | $this->updatePrivacyLevel(); |
| 54 | } |
| 55 | |
| 56 | public function getHidden(): bool { |
| 57 | return $this->hidden; |
| 58 | } |
| 59 | |
| 60 | public function setHidden( bool $hidden ): void { |
| 61 | $this->hidden = $hidden; |
| 62 | $this->updatePrivacyLevel(); |
| 63 | } |
| 64 | |
| 65 | public function getProtected(): bool { |
| 66 | return $this->protected; |
| 67 | } |
| 68 | |
| 69 | public function setProtected( bool $protected ): void { |
| 70 | $this->protected = $protected; |
| 71 | $this->updatePrivacyLevel(); |
| 72 | } |
| 73 | |
| 74 | private function updatePrivacyLevel() { |
| 75 | $suppressed = $this->suppressed ? self::FILTER_SUPPRESSED : 0; |
| 76 | $hidden = $this->hidden ? self::FILTER_HIDDEN : 0; |
| 77 | $protected = $this->protected ? self::FILTER_USES_PROTECTED_VARS : 0; |
| 78 | $this->privacyLevel = $suppressed | $hidden | $protected; |
| 79 | } |
| 80 | |
| 81 | public function getPrivacyLevel(): int { |
| 82 | return $this->privacyLevel; |
| 83 | } |
| 84 | |
| 85 | public function getGlobal(): bool { |
| 86 | return $this->global; |
| 87 | } |
| 88 | |
| 89 | public function setGlobal( bool $global ): void { |
| 90 | $this->global = $global; |
| 91 | } |
| 92 | } |