Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
28 / 28 |
|
100.00% |
18 / 18 |
CRAP | |
100.00% |
1 / 1 |
| MutableFilter | |
100.00% |
28 / 28 |
|
100.00% |
18 / 18 |
20 | |
100.00% |
1 / 1 |
| newDefault | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| newFromParentFilter | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| setRules | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setComments | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setActionsNames | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| setGroup | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setEnabled | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setDeleted | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setSuppressed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setHidden | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setProtected | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setGlobal | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setActions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUserIdentity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setTimestamp | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setID | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setHitCount | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setThrottled | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\AbuseFilter\Filter; |
| 4 | |
| 5 | use LogicException; |
| 6 | use MediaWiki\User\UserIdentity; |
| 7 | use MediaWiki\User\UserIdentityValue; |
| 8 | |
| 9 | /** |
| 10 | * Value object representing a filter that can be mutated (i.e. provides setters); this representation can |
| 11 | * be used to modify an existing database filter before saving it back to the DB. |
| 12 | */ |
| 13 | class MutableFilter extends Filter { |
| 14 | /** |
| 15 | * Convenience shortcut to get a 'default' filter, using the defaults for the editing interface. |
| 16 | * |
| 17 | * @return self |
| 18 | * @codeCoverageIgnore |
| 19 | */ |
| 20 | public static function newDefault(): self { |
| 21 | return new self( |
| 22 | new Specs( |
| 23 | '', |
| 24 | '', |
| 25 | '', |
| 26 | [], |
| 27 | '' |
| 28 | ), |
| 29 | new Flags( |
| 30 | true, |
| 31 | false, |
| 32 | Flags::FILTER_PUBLIC, |
| 33 | false |
| 34 | ), |
| 35 | [], |
| 36 | new LastEditInfo( |
| 37 | UserIdentityValue::newAnonymous( '' ), |
| 38 | '' |
| 39 | ) |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | public static function newFromParentFilter( Filter $filter ): self { |
| 44 | return new self( |
| 45 | $filter->getSpecs(), |
| 46 | $filter->getFlags(), |
| 47 | $filter->actions ?? $filter->actionsCallback, |
| 48 | $filter->getLastEditInfo(), |
| 49 | $filter->getID(), |
| 50 | $filter->getHitCount(), |
| 51 | $filter->isThrottled() |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | public function setRules( string $rules ): void { |
| 56 | $this->specs->setRules( $rules ); |
| 57 | } |
| 58 | |
| 59 | public function setComments( string $comments ): void { |
| 60 | $this->specs->setComments( $comments ); |
| 61 | } |
| 62 | |
| 63 | public function setName( string $name ): void { |
| 64 | $this->specs->setName( $name ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @throws LogicException if $actions are already set; use $this->setActions to update names |
| 69 | * @param string[] $actionsNames |
| 70 | */ |
| 71 | public function setActionsNames( array $actionsNames ): void { |
| 72 | if ( $this->actions !== null ) { |
| 73 | throw new LogicException( 'Cannot set actions names with actions already set' ); |
| 74 | } |
| 75 | $this->specs->setActionsNames( $actionsNames ); |
| 76 | } |
| 77 | |
| 78 | public function setGroup( string $group ): void { |
| 79 | $this->specs->setGroup( $group ); |
| 80 | } |
| 81 | |
| 82 | public function setEnabled( bool $enabled ): void { |
| 83 | $this->flags->setEnabled( $enabled ); |
| 84 | } |
| 85 | |
| 86 | public function setDeleted( bool $deleted ): void { |
| 87 | $this->flags->setDeleted( $deleted ); |
| 88 | } |
| 89 | |
| 90 | public function setSuppressed( bool $suppressed ): void { |
| 91 | $this->flags->setSuppressed( $suppressed ); |
| 92 | } |
| 93 | |
| 94 | public function setHidden( bool $hidden ): void { |
| 95 | $this->flags->setHidden( $hidden ); |
| 96 | } |
| 97 | |
| 98 | public function setProtected( bool $protected ): void { |
| 99 | $this->flags->setProtected( $protected ); |
| 100 | } |
| 101 | |
| 102 | public function setGlobal( bool $global ): void { |
| 103 | $this->flags->setGlobal( $global ); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @note This also updates action names |
| 108 | * @param array[] $actions |
| 109 | */ |
| 110 | public function setActions( array $actions ): void { |
| 111 | parent::setActions( $actions ); |
| 112 | } |
| 113 | |
| 114 | public function setUserIdentity( UserIdentity $user ): void { |
| 115 | $this->lastEditInfo->setUserIdentity( $user ); |
| 116 | } |
| 117 | |
| 118 | public function setTimestamp( string $timestamp ): void { |
| 119 | $this->lastEditInfo->setTimestamp( $timestamp ); |
| 120 | } |
| 121 | |
| 122 | public function setID( ?int $id ): void { |
| 123 | $this->id = $id; |
| 124 | } |
| 125 | |
| 126 | public function setHitCount( int $hitCount ): void { |
| 127 | $this->hitCount = $hitCount; |
| 128 | } |
| 129 | |
| 130 | public function setThrottled( bool $throttled ): void { |
| 131 | $this->throttled = $throttled; |
| 132 | } |
| 133 | } |