Debian Codegraph @

extensions/AbuseFilter/includes/Filter/MutableFilter.php

raw symbols SCIP
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 Flags::FILTER_PUBLIC,
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 $protected
121 */
122 public function setProtected( bool $protected ): void {
123 $this->flags->setProtected( $protected );
124 }
125
126 /**
127 * @param bool $global
128 */
129 public function setGlobal( bool $global ): void {
130 $this->flags->setGlobal( $global );
131 }
132
133 /**
134 * @note This also updates action names
135 * @param array[] $actions
136 */
137 public function setActions( array $actions ): void {
138 parent::setActions( $actions );
139 }
140
141 /**
142 * @param int $id
143 */
144 public function setUserID( int $id ): void {
145 $this->lastEditInfo->setUserID( $id );
146 }
147
148 /**
149 * @param string $name
150 */
151 public function setUserName( string $name ): void {
152 $this->lastEditInfo->setUserName( $name );
153 }
154
155 /**
156 * @param string $timestamp
157 */
158 public function setTimestamp( string $timestamp ): void {
159 $this->lastEditInfo->setTimestamp( $timestamp );
160 }
161
162 /**
163 * @param int|null $id
164 */
165 public function setID( ?int $id ): void {
166 $this->id = $id;
167 }
168
169 /**
170 * @param int $hitCount
171 */
172 public function setHitCount( int $hitCount ): void {
173 $this->hitCount = $hitCount;
174 }
175
176 /**
177 * @param bool $throttled
178 */
179 public function setThrottled( bool $throttled ): void {
180 $this->throttled = $throttled;
181 }
182 }