Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
27 / 27 |
|
100.00% |
17 / 17 |
CRAP | |
100.00% |
1 / 1 |
MutableFilter | |
100.00% |
27 / 27 |
|
100.00% |
17 / 17 |
19 | |
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 | |||
setHidden | |
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 | |||
setUserID | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setUserName | |
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 | |
7 | /** |
8 | * Value object representing a filter that can be mutated (i.e. provides setters); this representation can |
9 | * be used to modify an existing database filter before saving it back to the DB. |
10 | */ |
11 | class MutableFilter extends Filter { |
12 | /** |
13 | * Convenience shortcut to get a 'default' filter, using the defaults for the editing interface. |
14 | * |
15 | * @return self |
16 | * @codeCoverageIgnore |
17 | */ |
18 | public static function newDefault(): self { |
19 | return new self( |
20 | new Specs( |
21 | '', |
22 | '', |
23 | '', |
24 | [], |
25 | '' |
26 | ), |
27 | new Flags( |
28 | true, |
29 | false, |
30 | false, |
31 | false |
32 | ), |
33 | [], |
34 | new LastEditInfo( |
35 | 0, |
36 | '', |
37 | '' |
38 | ) |
39 | ); |
40 | } |
41 | |
42 | /** |
43 | * @param Filter $filter |
44 | * @return self |
45 | */ |
46 | public static function newFromParentFilter( Filter $filter ): self { |
47 | return new self( |
48 | $filter->getSpecs(), |
49 | $filter->getFlags(), |
50 | // @phan-suppress-next-line PhanTypeMismatchArgumentNullable One is guaranteed to be set |
51 | $filter->actions ?? $filter->actionsCallback, |
52 | $filter->getLastEditInfo(), |
53 | $filter->getID(), |
54 | $filter->getHitCount(), |
55 | $filter->isThrottled() |
56 | ); |
57 | } |
58 | |
59 | /** |
60 | * @param string $rules |
61 | */ |
62 | public function setRules( string $rules ): void { |
63 | $this->specs->setRules( $rules ); |
64 | } |
65 | |
66 | /** |
67 | * @param string $comments |
68 | */ |
69 | public function setComments( string $comments ): void { |
70 | $this->specs->setComments( $comments ); |
71 | } |
72 | |
73 | /** |
74 | * @param string $name |
75 | */ |
76 | public function setName( string $name ): void { |
77 | $this->specs->setName( $name ); |
78 | } |
79 | |
80 | /** |
81 | * @throws LogicException if $actions are already set; use $this->setActions to update names |
82 | * @param string[] $actionsNames |
83 | */ |
84 | public function setActionsNames( array $actionsNames ): void { |
85 | if ( $this->actions !== null ) { |
86 | throw new LogicException( 'Cannot set actions names with actions already set' ); |
87 | } |
88 | $this->specs->setActionsNames( $actionsNames ); |
89 | } |
90 | |
91 | /** |
92 | * @param string $group |
93 | */ |
94 | public function setGroup( string $group ): void { |
95 | $this->specs->setGroup( $group ); |
96 | } |
97 | |
98 | /** |
99 | * @param bool $enabled |
100 | */ |
101 | public function setEnabled( bool $enabled ): void { |
102 | $this->flags->setEnabled( $enabled ); |
103 | } |
104 | |
105 | /** |
106 | * @param bool $deleted |
107 | */ |
108 | public function setDeleted( bool $deleted ): void { |
109 | $this->flags->setDeleted( $deleted ); |
110 | } |
111 | |
112 | /** |
113 | * @param bool $hidden |
114 | */ |
115 | public function setHidden( bool $hidden ): void { |
116 | $this->flags->setHidden( $hidden ); |
117 | } |
118 | |
119 | /** |
120 | * @param bool $global |
121 | */ |
122 | public function setGlobal( bool $global ): void { |
123 | $this->flags->setGlobal( $global ); |
124 | } |
125 | |
126 | /** |
127 | * @note This also updates action names |
128 | * @param array[] $actions |
129 | */ |
130 | public function setActions( array $actions ): void { |
131 | parent::setActions( $actions ); |
132 | } |
133 | |
134 | /** |
135 | * @param int $id |
136 | */ |
137 | public function setUserID( int $id ): void { |
138 | $this->lastEditInfo->setUserID( $id ); |
139 | } |
140 | |
141 | /** |
142 | * @param string $name |
143 | */ |
144 | public function setUserName( string $name ): void { |
145 | $this->lastEditInfo->setUserName( $name ); |
146 | } |
147 | |
148 | /** |
149 | * @param string $timestamp |
150 | */ |
151 | public function setTimestamp( string $timestamp ): void { |
152 | $this->lastEditInfo->setTimestamp( $timestamp ); |
153 | } |
154 | |
155 | /** |
156 | * @param int|null $id |
157 | */ |
158 | public function setID( ?int $id ): void { |
159 | $this->id = $id; |
160 | } |
161 | |
162 | /** |
163 | * @param int $hitCount |
164 | */ |
165 | public function setHitCount( int $hitCount ): void { |
166 | $this->hitCount = $hitCount; |
167 | } |
168 | |
169 | /** |
170 | * @param bool $throttled |
171 | */ |
172 | public function setThrottled( bool $throttled ): void { |
173 | $this->throttled = $throttled; |
174 | } |
175 | } |