@@ -40,243 +40,243 @@ |
||
40 | 40 | public const PROPERTY_SCOPE_CHECKER = 'WBQC_PropertyScopeChecker'; |
41 | 41 | public const CONTEMPORARY_CHECKER = 'WBQC_ContemporaryChecker'; |
42 | 42 | |
43 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
44 | - if ( $services === null ) { |
|
43 | + private static function getService(?MediaWikiServices $services, $name) { |
|
44 | + if ($services === null) { |
|
45 | 45 | $services = MediaWikiServices::getInstance(); |
46 | 46 | } |
47 | - return $services->getService( $name ); |
|
47 | + return $services->getService($name); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * @param MediaWikiServices|null $services |
52 | 52 | * @return ConstraintChecker |
53 | 53 | */ |
54 | - public static function getConflictsWithChecker( MediaWikiServices $services = null ) { |
|
55 | - return self::getService( $services, self::CONFLICTS_WITH_CHECKER ); |
|
54 | + public static function getConflictsWithChecker(MediaWikiServices $services = null) { |
|
55 | + return self::getService($services, self::CONFLICTS_WITH_CHECKER); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @param MediaWikiServices|null $services |
60 | 60 | * @return ConstraintChecker |
61 | 61 | */ |
62 | - public static function getItemChecker( MediaWikiServices $services = null ) { |
|
63 | - return self::getService( $services, self::ITEM_CHECKER ); |
|
62 | + public static function getItemChecker(MediaWikiServices $services = null) { |
|
63 | + return self::getService($services, self::ITEM_CHECKER); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @param MediaWikiServices|null $services |
68 | 68 | * @return ConstraintChecker |
69 | 69 | */ |
70 | - public static function getTargetRequiredClaimChecker( MediaWikiServices $services = null ) { |
|
71 | - return self::getService( $services, self::TARGET_REQUIRED_CLAIM_CHECKER ); |
|
70 | + public static function getTargetRequiredClaimChecker(MediaWikiServices $services = null) { |
|
71 | + return self::getService($services, self::TARGET_REQUIRED_CLAIM_CHECKER); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @param MediaWikiServices|null $services |
76 | 76 | * @return ConstraintChecker |
77 | 77 | */ |
78 | - public static function getSymmetricChecker( MediaWikiServices $services = null ) { |
|
79 | - return self::getService( $services, self::SYMMETRIC_CHECKER ); |
|
78 | + public static function getSymmetricChecker(MediaWikiServices $services = null) { |
|
79 | + return self::getService($services, self::SYMMETRIC_CHECKER); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * @param MediaWikiServices|null $services |
84 | 84 | * @return ConstraintChecker |
85 | 85 | */ |
86 | - public static function getInverseChecker( MediaWikiServices $services = null ) { |
|
87 | - return self::getService( $services, self::INVERSE_CHECKER ); |
|
86 | + public static function getInverseChecker(MediaWikiServices $services = null) { |
|
87 | + return self::getService($services, self::INVERSE_CHECKER); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * @param MediaWikiServices|null $services |
92 | 92 | * @return ConstraintChecker |
93 | 93 | */ |
94 | - public static function getQualifierChecker( MediaWikiServices $services = null ) { |
|
95 | - return self::getService( $services, self::QUALIFIER_CHECKER ); |
|
94 | + public static function getQualifierChecker(MediaWikiServices $services = null) { |
|
95 | + return self::getService($services, self::QUALIFIER_CHECKER); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @param MediaWikiServices|null $services |
100 | 100 | * @return ConstraintChecker |
101 | 101 | */ |
102 | - public static function getQualifiersChecker( MediaWikiServices $services = null ) { |
|
103 | - return self::getService( $services, self::QUALIFIERS_CHECKER ); |
|
102 | + public static function getQualifiersChecker(MediaWikiServices $services = null) { |
|
103 | + return self::getService($services, self::QUALIFIERS_CHECKER); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @param MediaWikiServices|null $services |
108 | 108 | * @return ConstraintChecker |
109 | 109 | */ |
110 | - public static function getMandatoryQualifiersChecker( MediaWikiServices $services = null ) { |
|
111 | - return self::getService( $services, self::MANDATORY_QUALIFIERS_CHECKER ); |
|
110 | + public static function getMandatoryQualifiersChecker(MediaWikiServices $services = null) { |
|
111 | + return self::getService($services, self::MANDATORY_QUALIFIERS_CHECKER); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @param MediaWikiServices|null $services |
116 | 116 | * @return ConstraintChecker |
117 | 117 | */ |
118 | - public static function getRangeChecker( MediaWikiServices $services = null ) { |
|
119 | - return self::getService( $services, self::RANGE_CHECKER ); |
|
118 | + public static function getRangeChecker(MediaWikiServices $services = null) { |
|
119 | + return self::getService($services, self::RANGE_CHECKER); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @param MediaWikiServices|null $services |
124 | 124 | * @return ConstraintChecker |
125 | 125 | */ |
126 | - public static function getDiffWithinRangeChecker( MediaWikiServices $services = null ) { |
|
127 | - return self::getService( $services, self::DIFF_WITHIN_RANGE_CHECKER ); |
|
126 | + public static function getDiffWithinRangeChecker(MediaWikiServices $services = null) { |
|
127 | + return self::getService($services, self::DIFF_WITHIN_RANGE_CHECKER); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * @param MediaWikiServices|null $services |
132 | 132 | * @return ConstraintChecker |
133 | 133 | */ |
134 | - public static function getTypeChecker( MediaWikiServices $services = null ) { |
|
135 | - return self::getService( $services, self::TYPE_CHECKER ); |
|
134 | + public static function getTypeChecker(MediaWikiServices $services = null) { |
|
135 | + return self::getService($services, self::TYPE_CHECKER); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * @param MediaWikiServices|null $services |
140 | 140 | * @return ConstraintChecker |
141 | 141 | */ |
142 | - public static function getValueTypeChecker( MediaWikiServices $services = null ) { |
|
143 | - return self::getService( $services, self::VALUE_TYPE_CHECKER ); |
|
142 | + public static function getValueTypeChecker(MediaWikiServices $services = null) { |
|
143 | + return self::getService($services, self::VALUE_TYPE_CHECKER); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | 147 | * @param MediaWikiServices|null $services |
148 | 148 | * @return ConstraintChecker |
149 | 149 | */ |
150 | - public static function getSingleValueChecker( MediaWikiServices $services = null ) { |
|
151 | - return self::getService( $services, self::SINGLE_VALUE_CHECKER ); |
|
150 | + public static function getSingleValueChecker(MediaWikiServices $services = null) { |
|
151 | + return self::getService($services, self::SINGLE_VALUE_CHECKER); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | 155 | * @param MediaWikiServices|null $services |
156 | 156 | * @return ConstraintChecker |
157 | 157 | */ |
158 | - public static function getMultiValueChecker( MediaWikiServices $services = null ) { |
|
159 | - return self::getService( $services, self::MULTI_VALUE_CHECKER ); |
|
158 | + public static function getMultiValueChecker(MediaWikiServices $services = null) { |
|
159 | + return self::getService($services, self::MULTI_VALUE_CHECKER); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | 163 | * @param MediaWikiServices|null $services |
164 | 164 | * @return ConstraintChecker |
165 | 165 | */ |
166 | - public static function getUniqueValueChecker( MediaWikiServices $services = null ) { |
|
167 | - return self::getService( $services, self::UNIQUE_VALUE_CHECKER ); |
|
166 | + public static function getUniqueValueChecker(MediaWikiServices $services = null) { |
|
167 | + return self::getService($services, self::UNIQUE_VALUE_CHECKER); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
171 | 171 | * @param MediaWikiServices|null $services |
172 | 172 | * @return ConstraintChecker |
173 | 173 | */ |
174 | - public static function getFormatChecker( MediaWikiServices $services = null ) { |
|
175 | - return self::getService( $services, self::FORMAT_CHECKER ); |
|
174 | + public static function getFormatChecker(MediaWikiServices $services = null) { |
|
175 | + return self::getService($services, self::FORMAT_CHECKER); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | 179 | * @param MediaWikiServices|null $services |
180 | 180 | * @return ConstraintChecker |
181 | 181 | */ |
182 | - public static function getCommonsLinkChecker( MediaWikiServices $services = null ) { |
|
183 | - return self::getService( $services, self::COMMONS_LINK_CHECKER ); |
|
182 | + public static function getCommonsLinkChecker(MediaWikiServices $services = null) { |
|
183 | + return self::getService($services, self::COMMONS_LINK_CHECKER); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
187 | 187 | * @param MediaWikiServices|null $services |
188 | 188 | * @return ConstraintChecker |
189 | 189 | */ |
190 | - public static function getOneOfChecker( MediaWikiServices $services = null ) { |
|
191 | - return self::getService( $services, self::ONE_OF_CHECKER ); |
|
190 | + public static function getOneOfChecker(MediaWikiServices $services = null) { |
|
191 | + return self::getService($services, self::ONE_OF_CHECKER); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
195 | 195 | * @param MediaWikiServices|null $services |
196 | 196 | * @return ConstraintChecker |
197 | 197 | */ |
198 | - public static function getValueOnlyChecker( MediaWikiServices $services = null ) { |
|
199 | - return self::getService( $services, self::VALUE_ONLY_CHECKER ); |
|
198 | + public static function getValueOnlyChecker(MediaWikiServices $services = null) { |
|
199 | + return self::getService($services, self::VALUE_ONLY_CHECKER); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
203 | 203 | * @param MediaWikiServices|null $services |
204 | 204 | * @return ConstraintChecker |
205 | 205 | */ |
206 | - public static function getReferenceChecker( MediaWikiServices $services = null ) { |
|
207 | - return self::getService( $services, self::REFERENCE_CHECKER ); |
|
206 | + public static function getReferenceChecker(MediaWikiServices $services = null) { |
|
207 | + return self::getService($services, self::REFERENCE_CHECKER); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * @param MediaWikiServices|null $services |
212 | 212 | * @return ConstraintChecker |
213 | 213 | */ |
214 | - public static function getNoBoundsChecker( MediaWikiServices $services = null ) { |
|
215 | - return self::getService( $services, self::NO_BOUNDS_CHECKER ); |
|
214 | + public static function getNoBoundsChecker(MediaWikiServices $services = null) { |
|
215 | + return self::getService($services, self::NO_BOUNDS_CHECKER); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | 219 | * @param MediaWikiServices|null $services |
220 | 220 | * @return ConstraintChecker |
221 | 221 | */ |
222 | - public static function getAllowedUnitsChecker( MediaWikiServices $services = null ) { |
|
223 | - return self::getService( $services, self::ALLOWED_UNITS_CHECKER ); |
|
222 | + public static function getAllowedUnitsChecker(MediaWikiServices $services = null) { |
|
223 | + return self::getService($services, self::ALLOWED_UNITS_CHECKER); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
227 | 227 | * @param MediaWikiServices|null $services |
228 | 228 | * @return ConstraintChecker |
229 | 229 | */ |
230 | - public static function getSingleBestValueChecker( MediaWikiServices $services = null ) { |
|
231 | - return self::getService( $services, self::SINGLE_BEST_VALUE_CHECKER ); |
|
230 | + public static function getSingleBestValueChecker(MediaWikiServices $services = null) { |
|
231 | + return self::getService($services, self::SINGLE_BEST_VALUE_CHECKER); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
235 | 235 | * @param MediaWikiServices|null $services |
236 | 236 | * @return ConstraintChecker |
237 | 237 | */ |
238 | - public static function getEntityTypeChecker( MediaWikiServices $services = null ) { |
|
239 | - return self::getService( $services, self::ENTITY_TYPE_CHECKER ); |
|
238 | + public static function getEntityTypeChecker(MediaWikiServices $services = null) { |
|
239 | + return self::getService($services, self::ENTITY_TYPE_CHECKER); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | 243 | * @param MediaWikiServices|null $services |
244 | 244 | * @return ConstraintChecker |
245 | 245 | */ |
246 | - public static function getNoneOfChecker( MediaWikiServices $services = null ) { |
|
247 | - return self::getService( $services, self::NONE_OF_CHECKER ); |
|
246 | + public static function getNoneOfChecker(MediaWikiServices $services = null) { |
|
247 | + return self::getService($services, self::NONE_OF_CHECKER); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
251 | 251 | * @param MediaWikiServices|null $services |
252 | 252 | * @return ConstraintChecker |
253 | 253 | */ |
254 | - public static function getIntegerChecker( MediaWikiServices $services = null ) { |
|
255 | - return self::getService( $services, self::INTEGER_CHECKER ); |
|
254 | + public static function getIntegerChecker(MediaWikiServices $services = null) { |
|
255 | + return self::getService($services, self::INTEGER_CHECKER); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
259 | 259 | * @param MediaWikiServices|null $services |
260 | 260 | * @return ConstraintChecker |
261 | 261 | */ |
262 | - public static function getCitationNeededChecker( MediaWikiServices $services = null ) { |
|
263 | - return self::getService( $services, self::CITATION_NEEDED_CHECKER ); |
|
262 | + public static function getCitationNeededChecker(MediaWikiServices $services = null) { |
|
263 | + return self::getService($services, self::CITATION_NEEDED_CHECKER); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | 267 | * @param MediaWikiServices|null $services |
268 | 268 | * @return ConstraintChecker |
269 | 269 | */ |
270 | - public static function getPropertyScopeChecker( MediaWikiServices $services = null ) { |
|
271 | - return self::getService( $services, self::PROPERTY_SCOPE_CHECKER ); |
|
270 | + public static function getPropertyScopeChecker(MediaWikiServices $services = null) { |
|
271 | + return self::getService($services, self::PROPERTY_SCOPE_CHECKER); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | 275 | * @param MediaWikiServices|null $services |
276 | 276 | * @return ConstraintChecker |
277 | 277 | */ |
278 | - public static function getContemporaryChecker( MediaWikiServices $services = null ) { |
|
279 | - return self::getService( $services, self::CONTEMPORARY_CHECKER ); |
|
278 | + public static function getContemporaryChecker(MediaWikiServices $services = null) { |
|
279 | + return self::getService($services, self::CONTEMPORARY_CHECKER); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | } |
@@ -24,22 +24,22 @@ |
||
24 | 24 | */ |
25 | 25 | private const NULL_PROPERTY_ID = 'P2147483647'; |
26 | 26 | |
27 | - public function __construct( ContextCursor $contextCursor ) { |
|
27 | + public function __construct(ContextCursor $contextCursor) { |
|
28 | 28 | $constraint = new Constraint( |
29 | 29 | 'null', |
30 | - new PropertyId( self::NULL_PROPERTY_ID ), |
|
30 | + new PropertyId(self::NULL_PROPERTY_ID), |
|
31 | 31 | 'none', |
32 | 32 | [] |
33 | 33 | ); |
34 | - parent::__construct( $contextCursor, $constraint ); |
|
34 | + parent::__construct($contextCursor, $constraint); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function getConstraint() { |
38 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
38 | + throw new DomainException('NullResult holds no constraint'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | public function getConstraintId() { |
42 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
42 | + throw new DomainException('NullResult holds no constraint'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | } |
@@ -20,35 +20,35 @@ |
||
20 | 20 | public const PROPERTY_DATA_TYPE_LOOKUP = 'WBQC_PropertyDataTypeLookup'; |
21 | 21 | public const ENTITY_LOOKUP_WITHOUT_CACHE = 'WBQC_EntityLookupWithoutCache'; |
22 | 22 | |
23 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
24 | - if ( $services === null ) { |
|
23 | + private static function getService(?MediaWikiServices $services, $name) { |
|
24 | + if ($services === null) { |
|
25 | 25 | $services = MediaWikiServices::getInstance(); |
26 | 26 | } |
27 | - return $services->getService( $name ); |
|
27 | + return $services->getService($name); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @param MediaWikiServices|null $services |
32 | 32 | * @return EntityLookup |
33 | 33 | */ |
34 | - public static function getEntityLookup( MediaWikiServices $services = null ) { |
|
35 | - return self::getService( $services, self::ENTITY_LOOKUP ); |
|
34 | + public static function getEntityLookup(MediaWikiServices $services = null) { |
|
35 | + return self::getService($services, self::ENTITY_LOOKUP); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @param MediaWikiServices|null $services |
40 | 40 | * @return PropertyDataTypeLookup |
41 | 41 | */ |
42 | - public static function getPropertyDataTypeLookup( MediaWikiServices $services = null ) { |
|
43 | - return self::getService( $services, self::PROPERTY_DATA_TYPE_LOOKUP ); |
|
42 | + public static function getPropertyDataTypeLookup(MediaWikiServices $services = null) { |
|
43 | + return self::getService($services, self::PROPERTY_DATA_TYPE_LOOKUP); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param MediaWikiServices|null $services |
48 | 48 | * @return EntityLookup |
49 | 49 | */ |
50 | - public static function getEntityLookupWithoutCache( MediaWikiServices $services = null ) { |
|
51 | - return self::getService( $services, self::ENTITY_LOOKUP_WITHOUT_CACHE ); |
|
50 | + public static function getEntityLookupWithoutCache(MediaWikiServices $services = null) { |
|
51 | + return self::getService($services, self::ENTITY_LOOKUP_WITHOUT_CACHE); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
@@ -77,17 +77,17 @@ discard block |
||
77 | 77 | * @param ViolationMessage $violationMessage |
78 | 78 | * @return string |
79 | 79 | */ |
80 | - public function render( ViolationMessage $violationMessage ) { |
|
80 | + public function render(ViolationMessage $violationMessage) { |
|
81 | 81 | $messageKey = $violationMessage->getMessageKey(); |
82 | - $paramsLists = [ [] ]; |
|
83 | - foreach ( $violationMessage->getArguments() as $argument ) { |
|
84 | - $params = $this->renderArgument( $argument ); |
|
82 | + $paramsLists = [[]]; |
|
83 | + foreach ($violationMessage->getArguments() as $argument) { |
|
84 | + $params = $this->renderArgument($argument); |
|
85 | 85 | $paramsLists[] = $params; |
86 | 86 | } |
87 | - $allParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
87 | + $allParams = call_user_func_array('array_merge', $paramsLists); |
|
88 | 88 | return $this->messageLocalizer |
89 | - ->msg( $messageKey ) |
|
90 | - ->params( $allParams ) |
|
89 | + ->msg($messageKey) |
|
90 | + ->params($allParams) |
|
91 | 91 | ->escaped(); |
92 | 92 | } |
93 | 93 | |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | * @param string|null $role one of the Role::* constants |
97 | 97 | * @return string HTML |
98 | 98 | */ |
99 | - protected function addRole( $value, $role ) { |
|
100 | - if ( $role === null ) { |
|
99 | + protected function addRole($value, $role) { |
|
100 | + if ($role === null) { |
|
101 | 101 | return $value; |
102 | 102 | } |
103 | 103 | |
104 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' . |
|
105 | - $value . |
|
104 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'. |
|
105 | + $value. |
|
106 | 106 | '</span>'; |
107 | 107 | } |
108 | 108 | |
@@ -110,15 +110,15 @@ discard block |
||
110 | 110 | * @param string $key message key |
111 | 111 | * @return string HTML |
112 | 112 | */ |
113 | - protected function msgEscaped( $key ) { |
|
114 | - return $this->messageLocalizer->msg( $key )->escaped(); |
|
113 | + protected function msgEscaped($key) { |
|
114 | + return $this->messageLocalizer->msg($key)->escaped(); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
118 | 118 | * @param array $argument |
119 | 119 | * @return array[] params (for Message::params) |
120 | 120 | */ |
121 | - protected function renderArgument( array $argument ) { |
|
121 | + protected function renderArgument(array $argument) { |
|
122 | 122 | $methods = [ |
123 | 123 | ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId', |
124 | 124 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList', |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | $value = $argument['value']; |
139 | 139 | $role = $argument['role']; |
140 | 140 | |
141 | - if ( array_key_exists( $type, $methods ) ) { |
|
141 | + if (array_key_exists($type, $methods)) { |
|
142 | 142 | $method = $methods[$type]; |
143 | - $params = $this->$method( $value, $role ); |
|
143 | + $params = $this->$method($value, $role); |
|
144 | 144 | } else { |
145 | 145 | throw new InvalidArgumentException( |
146 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
146 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
147 | 147 | ); |
148 | 148 | } |
149 | 149 | |
@@ -157,46 +157,46 @@ discard block |
||
157 | 157 | * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ]) |
158 | 158 | * @return array[] list of parameters as accepted by Message::params() |
159 | 159 | */ |
160 | - private function renderList( array $list, $role, callable $render ) { |
|
161 | - if ( $list === [] ) { |
|
160 | + private function renderList(array $list, $role, callable $render) { |
|
161 | + if ($list === []) { |
|
162 | 162 | return [ |
163 | - Message::numParam( 0 ), |
|
164 | - Message::rawParam( '<ul></ul>' ), |
|
163 | + Message::numParam(0), |
|
164 | + Message::rawParam('<ul></ul>'), |
|
165 | 165 | ]; |
166 | 166 | } |
167 | 167 | |
168 | - if ( count( $list ) > $this->maxListLength ) { |
|
169 | - $list = array_slice( $list, 0, $this->maxListLength ); |
|
168 | + if (count($list) > $this->maxListLength) { |
|
169 | + $list = array_slice($list, 0, $this->maxListLength); |
|
170 | 170 | $truncated = true; |
171 | 171 | } |
172 | 172 | |
173 | 173 | $renderedParamsLists = array_map( |
174 | 174 | $render, |
175 | 175 | $list, |
176 | - array_fill( 0, count( $list ), $role ) |
|
176 | + array_fill(0, count($list), $role) |
|
177 | 177 | ); |
178 | 178 | $renderedParams = array_map( |
179 | - function ( $params ) { |
|
179 | + function($params) { |
|
180 | 180 | return $params[0]; |
181 | 181 | }, |
182 | 182 | $renderedParamsLists |
183 | 183 | ); |
184 | 184 | $renderedElements = array_map( |
185 | - function ( $param ) { |
|
185 | + function($param) { |
|
186 | 186 | return $param['raw']; |
187 | 187 | }, |
188 | 188 | $renderedParams |
189 | 189 | ); |
190 | - if ( isset( $truncated ) ) { |
|
191 | - $renderedElements[] = $this->msgEscaped( 'ellipsis' ); |
|
190 | + if (isset($truncated)) { |
|
191 | + $renderedElements[] = $this->msgEscaped('ellipsis'); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | return array_merge( |
195 | 195 | [ |
196 | - Message::numParam( count( $list ) ), |
|
196 | + Message::numParam(count($list)), |
|
197 | 197 | Message::rawParam( |
198 | - '<ul><li>' . |
|
199 | - implode( '</li><li>', $renderedElements ) . |
|
198 | + '<ul><li>'. |
|
199 | + implode('</li><li>', $renderedElements). |
|
200 | 200 | '</li></ul>' |
201 | 201 | ), |
202 | 202 | ], |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | * @param string|null $role one of the Role::* constants |
210 | 210 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
211 | 211 | */ |
212 | - private function renderEntityId( EntityId $entityId, $role ) { |
|
213 | - return [ Message::rawParam( $this->addRole( |
|
214 | - $this->entityIdFormatter->formatEntityId( $entityId ), |
|
212 | + private function renderEntityId(EntityId $entityId, $role) { |
|
213 | + return [Message::rawParam($this->addRole( |
|
214 | + $this->entityIdFormatter->formatEntityId($entityId), |
|
215 | 215 | $role |
216 | - ) ) ]; |
|
216 | + ))]; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | * @param string|null $role one of the Role::* constants |
222 | 222 | * @return array[] list of parameters as accepted by Message::params() |
223 | 223 | */ |
224 | - private function renderEntityIdList( array $entityIdList, $role ) { |
|
225 | - return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] ); |
|
224 | + private function renderEntityIdList(array $entityIdList, $role) { |
|
225 | + return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -230,24 +230,24 @@ discard block |
||
230 | 230 | * @param string|null $role one of the Role::* constants |
231 | 231 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
232 | 232 | */ |
233 | - private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) { |
|
234 | - switch ( true ) { |
|
233 | + private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) { |
|
234 | + switch (true) { |
|
235 | 235 | case $value->isValue(): |
236 | - return $this->renderEntityId( $value->getItemId(), $role ); |
|
236 | + return $this->renderEntityId($value->getItemId(), $role); |
|
237 | 237 | case $value->isSomeValue(): |
238 | - return [ Message::rawParam( $this->addRole( |
|
239 | - '<span class="wikibase-snakview-variation-somevaluesnak">' . |
|
240 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-somevalue' ) . |
|
238 | + return [Message::rawParam($this->addRole( |
|
239 | + '<span class="wikibase-snakview-variation-somevaluesnak">'. |
|
240 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-somevalue'). |
|
241 | 241 | '</span>', |
242 | 242 | $role |
243 | - ) ) ]; |
|
243 | + ))]; |
|
244 | 244 | case $value->isNoValue(): |
245 | - return [ Message::rawParam( $this->addRole( |
|
246 | - '<span class="wikibase-snakview-variation-novaluesnak">' . |
|
247 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-novalue' ) . |
|
245 | + return [Message::rawParam($this->addRole( |
|
246 | + '<span class="wikibase-snakview-variation-novaluesnak">'. |
|
247 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-novalue'). |
|
248 | 248 | '</span>', |
249 | 249 | $role |
250 | - ) ) ]; |
|
250 | + ))]; |
|
251 | 251 | default: |
252 | 252 | // @codeCoverageIgnoreStart |
253 | 253 | throw new LogicException( |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | * @param string|null $role one of the Role::* constants |
263 | 263 | * @return array[] list of parameters as accepted by Message::params() |
264 | 264 | */ |
265 | - private function renderItemIdSnakValueList( array $valueList, $role ) { |
|
266 | - return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] ); |
|
265 | + private function renderItemIdSnakValueList(array $valueList, $role) { |
|
266 | + return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -271,11 +271,11 @@ discard block |
||
271 | 271 | * @param string|null $role one of the Role::* constants |
272 | 272 | * @return array[] list of parameters as accepted by Message::params() |
273 | 273 | */ |
274 | - private function renderDataValue( DataValue $dataValue, $role ) { |
|
275 | - return [ Message::rawParam( $this->addRole( |
|
276 | - $this->dataValueFormatter->format( $dataValue ), |
|
274 | + private function renderDataValue(DataValue $dataValue, $role) { |
|
275 | + return [Message::rawParam($this->addRole( |
|
276 | + $this->dataValueFormatter->format($dataValue), |
|
277 | 277 | $role |
278 | - ) ) ]; |
|
278 | + ))]; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @param string|null $role one of the Role::* constants |
284 | 284 | * @return array[] list of parameters as accepted by Message::params() |
285 | 285 | */ |
286 | - private function renderDataValueType( $dataValueType, $role ) { |
|
286 | + private function renderDataValueType($dataValueType, $role) { |
|
287 | 287 | $messageKeys = [ |
288 | 288 | 'string' => 'datatypes-type-string', |
289 | 289 | 'monolingualtext' => 'datatypes-type-monolingualtext', |
@@ -292,15 +292,15 @@ discard block |
||
292 | 292 | 'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid', |
293 | 293 | ]; |
294 | 294 | |
295 | - if ( array_key_exists( $dataValueType, $messageKeys ) ) { |
|
296 | - return [ Message::rawParam( $this->addRole( |
|
297 | - $this->msgEscaped( $messageKeys[$dataValueType] ), |
|
295 | + if (array_key_exists($dataValueType, $messageKeys)) { |
|
296 | + return [Message::rawParam($this->addRole( |
|
297 | + $this->msgEscaped($messageKeys[$dataValueType]), |
|
298 | 298 | $role |
299 | - ) ) ]; |
|
299 | + ))]; |
|
300 | 300 | } else { |
301 | 301 | // @codeCoverageIgnoreStart |
302 | 302 | throw new LogicException( |
303 | - 'Unknown data value type ' . $dataValueType |
|
303 | + 'Unknown data value type '.$dataValueType |
|
304 | 304 | ); |
305 | 305 | // @codeCoverageIgnoreEnd |
306 | 306 | } |
@@ -311,11 +311,11 @@ discard block |
||
311 | 311 | * @param string|null $role one of the Role::* constants |
312 | 312 | * @return array[] list of parameters as accepted by Message::params() |
313 | 313 | */ |
314 | - private function renderInlineCode( $code, $role ) { |
|
315 | - return [ Message::rawParam( $this->addRole( |
|
316 | - '<code>' . htmlspecialchars( $code ) . '</code>', |
|
314 | + private function renderInlineCode($code, $role) { |
|
315 | + return [Message::rawParam($this->addRole( |
|
316 | + '<code>'.htmlspecialchars($code).'</code>', |
|
317 | 317 | $role |
318 | - ) ) ]; |
|
318 | + ))]; |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | * @param string|null $role one of the Role::* constants |
324 | 324 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
325 | 325 | */ |
326 | - private function renderConstraintScope( $scope, $role ) { |
|
327 | - switch ( $scope ) { |
|
326 | + private function renderConstraintScope($scope, $role) { |
|
327 | + switch ($scope) { |
|
328 | 328 | case Context::TYPE_STATEMENT: |
329 | 329 | $itemId = $this->config->get( |
330 | 330 | 'WBQualityConstraintsConstraintCheckedOnMainValueId' |
@@ -344,10 +344,10 @@ discard block |
||
344 | 344 | // callers should never let this happen, but if it does happen, |
345 | 345 | // showing “unknown value” seems reasonable |
346 | 346 | // @codeCoverageIgnoreStart |
347 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
347 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
348 | 348 | // @codeCoverageIgnoreEnd |
349 | 349 | } |
350 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
350 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -355,8 +355,8 @@ discard block |
||
355 | 355 | * @param string|null $role one of the Role::* constants |
356 | 356 | * @return array[] list of parameters as accepted by Message::params() |
357 | 357 | */ |
358 | - private function renderConstraintScopeList( array $scopeList, $role ) { |
|
359 | - return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] ); |
|
358 | + private function renderConstraintScopeList(array $scopeList, $role) { |
|
359 | + return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
@@ -364,25 +364,25 @@ discard block |
||
364 | 364 | * @param string|null $role one of the Role::* constants |
365 | 365 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
366 | 366 | */ |
367 | - private function renderPropertyScope( $scope, $role ) { |
|
368 | - switch ( $scope ) { |
|
367 | + private function renderPropertyScope($scope, $role) { |
|
368 | + switch ($scope) { |
|
369 | 369 | case Context::TYPE_STATEMENT: |
370 | - $itemId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
370 | + $itemId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
371 | 371 | break; |
372 | 372 | case Context::TYPE_QUALIFIER: |
373 | - $itemId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
373 | + $itemId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
374 | 374 | break; |
375 | 375 | case Context::TYPE_REFERENCE: |
376 | - $itemId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
376 | + $itemId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
377 | 377 | break; |
378 | 378 | default: |
379 | 379 | // callers should never let this happen, but if it does happen, |
380 | 380 | // showing “unknown value” seems reasonable |
381 | 381 | // @codeCoverageIgnoreStart |
382 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
382 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
383 | 383 | // @codeCoverageIgnoreEnd |
384 | 384 | } |
385 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
385 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -390,8 +390,8 @@ discard block |
||
390 | 390 | * @param string|null $role one of the Role::* constants |
391 | 391 | * @return array[] list of parameters as accepted by Message::params() |
392 | 392 | */ |
393 | - private function renderPropertyScopeList( array $scopeList, $role ) { |
|
394 | - return $this->renderList( $scopeList, $role, [ $this, 'renderPropertyScope' ] ); |
|
393 | + private function renderPropertyScopeList(array $scopeList, $role) { |
|
394 | + return $this->renderList($scopeList, $role, [$this, 'renderPropertyScope']); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
@@ -399,10 +399,10 @@ discard block |
||
399 | 399 | * @param string|null $role one of the Role::* constants |
400 | 400 | * @return array[] list of parameters as accepted by Message::params() |
401 | 401 | */ |
402 | - private function renderLanguage( $languageCode, $role ) { |
|
402 | + private function renderLanguage($languageCode, $role) { |
|
403 | 403 | return [ |
404 | - Message::plaintextParam( Language::fetchLanguageName( $languageCode ) ), |
|
405 | - Message::plaintextParam( $languageCode ), |
|
404 | + Message::plaintextParam(Language::fetchLanguageName($languageCode)), |
|
405 | + Message::plaintextParam($languageCode), |
|
406 | 406 | ]; |
407 | 407 | } |
408 | 408 |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | * @param ViolationMessage $violationMessage |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - public function render( ViolationMessage $violationMessage ) { |
|
58 | - if ( !array_key_exists( $violationMessage->getMessageKey(), $this->alternativeMessageKeys ) ) { |
|
59 | - return parent::render( $violationMessage ); |
|
57 | + public function render(ViolationMessage $violationMessage) { |
|
58 | + if (!array_key_exists($violationMessage->getMessageKey(), $this->alternativeMessageKeys)) { |
|
59 | + return parent::render($violationMessage); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $arguments = $violationMessage->getArguments(); |
63 | - $multilingualTextArgument = array_pop( $arguments ); |
|
63 | + $multilingualTextArgument = array_pop($arguments); |
|
64 | 64 | $multilingualTextParams = $this->renderMultilingualText( |
65 | 65 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable TODO Ensure this is not an actual issue |
66 | 66 | $multilingualTextArgument['value'], |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | $multilingualTextArgument['role'] |
69 | 69 | ); |
70 | 70 | |
71 | - $paramsLists = [ [] ]; |
|
72 | - foreach ( $arguments as $argument ) { |
|
73 | - $paramsLists[] = $this->renderArgument( $argument ); |
|
71 | + $paramsLists = [[]]; |
|
72 | + foreach ($arguments as $argument) { |
|
73 | + $paramsLists[] = $this->renderArgument($argument); |
|
74 | 74 | } |
75 | - $regularParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
75 | + $regularParams = call_user_func_array('array_merge', $paramsLists); |
|
76 | 76 | |
77 | - if ( $multilingualTextParams === null ) { |
|
77 | + if ($multilingualTextParams === null) { |
|
78 | 78 | return $this->messageLocalizer |
79 | - ->msg( $this->alternativeMessageKeys[$violationMessage->getMessageKey()] ) |
|
80 | - ->params( $regularParams ) |
|
79 | + ->msg($this->alternativeMessageKeys[$violationMessage->getMessageKey()]) |
|
80 | + ->params($regularParams) |
|
81 | 81 | ->escaped(); |
82 | 82 | } else { |
83 | 83 | return $this->messageLocalizer |
84 | - ->msg( $violationMessage->getMessageKey() ) |
|
85 | - ->params( $regularParams ) |
|
86 | - ->params( $multilingualTextParams ) |
|
84 | + ->msg($violationMessage->getMessageKey()) |
|
85 | + ->params($regularParams) |
|
86 | + ->params($multilingualTextParams) |
|
87 | 87 | ->escaped(); |
88 | 88 | } |
89 | 89 | } |
@@ -94,18 +94,18 @@ discard block |
||
94 | 94 | * @return array[]|null list of parameters as accepted by Message::params(), |
95 | 95 | * or null if the text is not available in the user’s language |
96 | 96 | */ |
97 | - protected function renderMultilingualText( MultilingualTextValue $text, $role ) { |
|
97 | + protected function renderMultilingualText(MultilingualTextValue $text, $role) { |
|
98 | 98 | global $wgLang; |
99 | 99 | $languageCodes = $wgLang->getFallbackLanguages(); |
100 | - array_unshift( $languageCodes, $wgLang->getCode() ); |
|
100 | + array_unshift($languageCodes, $wgLang->getCode()); |
|
101 | 101 | |
102 | 102 | $texts = $text->getTexts(); |
103 | - foreach ( $languageCodes as $languageCode ) { |
|
104 | - if ( array_key_exists( $languageCode, $texts ) ) { |
|
105 | - return [ Message::rawParam( $this->addRole( |
|
106 | - htmlspecialchars( $texts[$languageCode]->getText() ), |
|
103 | + foreach ($languageCodes as $languageCode) { |
|
104 | + if (array_key_exists($languageCode, $texts)) { |
|
105 | + return [Message::rawParam($this->addRole( |
|
106 | + htmlspecialchars($texts[$languageCode]->getText()), |
|
107 | 107 | $role |
108 | - ) ) ]; |
|
108 | + ))]; |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 |
@@ -199,73 +199,73 @@ discard block |
||
199 | 199 | $this->defaultUserAgent = $defaultUserAgent; |
200 | 200 | $this->requestFactory = $requestFactory; |
201 | 201 | $this->entityPrefixes = []; |
202 | - foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) { |
|
203 | - $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName ); |
|
202 | + foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) { |
|
203 | + $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName); |
|
204 | 204 | } |
205 | 205 | |
206 | - $this->endpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
207 | - $this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
208 | - $this->instanceOfId = $config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
209 | - $this->subclassOfId = $config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
210 | - $this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
206 | + $this->endpoint = $config->get('WBQualityConstraintsSparqlEndpoint'); |
|
207 | + $this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
208 | + $this->instanceOfId = $config->get('WBQualityConstraintsInstanceOfId'); |
|
209 | + $this->subclassOfId = $config->get('WBQualityConstraintsSubclassOfId'); |
|
210 | + $this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
211 | 211 | $this->timeoutExceptionClasses = $config->get( |
212 | 212 | 'WBQualityConstraintsSparqlTimeoutExceptionClasses' |
213 | 213 | ); |
214 | 214 | $this->sparqlHasWikibaseSupport = $config->get( |
215 | 215 | 'WBQualityConstraintsSparqlHasWikibaseSupport' |
216 | 216 | ); |
217 | - $this->sparqlThrottlingFallbackDuration = (int)$config->get( |
|
217 | + $this->sparqlThrottlingFallbackDuration = (int) $config->get( |
|
218 | 218 | 'WBQualityConstraintsSparqlThrottlingFallbackDuration' |
219 | 219 | ); |
220 | 220 | |
221 | - $this->prefixes = $this->getQueryPrefixes( $rdfVocabulary ); |
|
221 | + $this->prefixes = $this->getQueryPrefixes($rdfVocabulary); |
|
222 | 222 | } |
223 | 223 | |
224 | - private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ) { |
|
224 | + private function getQueryPrefixes(RdfVocabulary $rdfVocabulary) { |
|
225 | 225 | // TODO: it would probably be smarter that RdfVocubulary exposed these prefixes somehow |
226 | 226 | $prefixes = ''; |
227 | - foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) { |
|
227 | + foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) { |
|
228 | 228 | $prefixes .= <<<END |
229 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
229 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
230 | 230 | END; |
231 | 231 | } |
232 | 232 | $prefixes .= <<<END |
233 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
234 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>\n |
|
233 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
234 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>\n |
|
235 | 235 | END; |
236 | 236 | |
237 | - foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) { |
|
237 | + foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) { |
|
238 | 238 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM]; |
239 | 239 | $prefixes .= <<<END |
240 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
240 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
241 | 241 | END; |
242 | 242 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM]; |
243 | 243 | $prefixes .= <<<END |
244 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
244 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
245 | 245 | END; |
246 | 246 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT]; |
247 | 247 | $prefixes .= <<<END |
248 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
248 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
249 | 249 | END; |
250 | 250 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER]; |
251 | 251 | $prefixes .= <<<END |
252 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
252 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
253 | 253 | END; |
254 | 254 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE]; |
255 | 255 | $prefixes .= <<<END |
256 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
256 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
257 | 257 | END; |
258 | 258 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE]; |
259 | 259 | $prefixes .= <<<END |
260 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
260 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
261 | 261 | END; |
262 | 262 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE]; |
263 | 263 | $prefixes .= <<<END |
264 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
264 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
265 | 265 | END; |
266 | 266 | } |
267 | 267 | $prefixes .= <<<END |
268 | -PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>\n |
|
268 | +PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>\n |
|
269 | 269 | END; |
270 | 270 | return $prefixes; |
271 | 271 | } |
@@ -277,21 +277,20 @@ discard block |
||
277 | 277 | * @return CachedBool |
278 | 278 | * @throws SparqlHelperException if the query times out or some other error occurs |
279 | 279 | */ |
280 | - public function hasType( $id, array $classes ) { |
|
280 | + public function hasType($id, array $classes) { |
|
281 | 281 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
282 | 282 | $gearingHint = $this->sparqlHasWikibaseSupport ? |
283 | - ' hint:Prior hint:gearing "forward".' : |
|
284 | - ''; |
|
283 | + ' hint:Prior hint:gearing "forward".' : ''; |
|
285 | 284 | |
286 | 285 | $metadatas = []; |
287 | 286 | |
288 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
289 | - $classesValues = implode( ' ', array_map( |
|
290 | - function ( $class ) { |
|
291 | - return 'wd:' . $class; |
|
287 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
288 | + $classesValues = implode(' ', array_map( |
|
289 | + function($class) { |
|
290 | + return 'wd:'.$class; |
|
292 | 291 | }, |
293 | 292 | $classesChunk |
294 | - ) ); |
|
293 | + )); |
|
295 | 294 | |
296 | 295 | $query = <<<EOF |
297 | 296 | ASK { |
@@ -301,19 +300,19 @@ discard block |
||
301 | 300 | } |
302 | 301 | EOF; |
303 | 302 | |
304 | - $result = $this->runQuery( $query ); |
|
303 | + $result = $this->runQuery($query); |
|
305 | 304 | $metadatas[] = $result->getMetadata(); |
306 | - if ( $result->getArray()['boolean'] ) { |
|
305 | + if ($result->getArray()['boolean']) { |
|
307 | 306 | return new CachedBool( |
308 | 307 | true, |
309 | - Metadata::merge( $metadatas ) |
|
308 | + Metadata::merge($metadatas) |
|
310 | 309 | ); |
311 | 310 | } |
312 | 311 | } |
313 | 312 | |
314 | 313 | return new CachedBool( |
315 | 314 | false, |
316 | - Metadata::merge( $metadatas ) |
|
315 | + Metadata::merge($metadatas) |
|
317 | 316 | ); |
318 | 317 | } |
319 | 318 | |
@@ -329,10 +328,10 @@ discard block |
||
329 | 328 | $ignoreDeprecatedStatements |
330 | 329 | ) { |
331 | 330 | $pid = $statement->getPropertyId()->serialize(); |
332 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
331 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
333 | 332 | |
334 | 333 | $deprecatedFilter = ''; |
335 | - if ( $ignoreDeprecatedStatements ) { |
|
334 | + if ($ignoreDeprecatedStatements) { |
|
336 | 335 | $deprecatedFilter = 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
337 | 336 | } |
338 | 337 | |
@@ -351,9 +350,9 @@ discard block |
||
351 | 350 | LIMIT 10 |
352 | 351 | EOF; |
353 | 352 | |
354 | - $result = $this->runQuery( $query ); |
|
353 | + $result = $this->runQuery($query); |
|
355 | 354 | |
356 | - return $this->getOtherEntities( $result ); |
|
355 | + return $this->getOtherEntities($result); |
|
357 | 356 | } |
358 | 357 | |
359 | 358 | /** |
@@ -378,16 +377,15 @@ discard block |
||
378 | 377 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
379 | 378 | $snak->getPropertyId() |
380 | 379 | ); |
381 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
382 | - if ( $isFullValue ) { |
|
380 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
381 | + if ($isFullValue) { |
|
383 | 382 | $prefix .= 'v'; |
384 | 383 | } |
385 | 384 | $path = $type === Context::TYPE_QUALIFIER ? |
386 | - "$prefix:$pid" : |
|
387 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
385 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
388 | 386 | |
389 | 387 | $deprecatedFilter = ''; |
390 | - if ( $ignoreDeprecatedStatements ) { |
|
388 | + if ($ignoreDeprecatedStatements) { |
|
391 | 389 | $deprecatedFilter = <<< EOF |
392 | 390 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
393 | 391 | EOF; |
@@ -407,9 +405,9 @@ discard block |
||
407 | 405 | LIMIT 10 |
408 | 406 | EOF; |
409 | 407 | |
410 | - $result = $this->runQuery( $query ); |
|
408 | + $result = $this->runQuery($query); |
|
411 | 409 | |
412 | - return $this->getOtherEntities( $result ); |
|
410 | + return $this->getOtherEntities($result); |
|
413 | 411 | } |
414 | 412 | |
415 | 413 | /** |
@@ -419,8 +417,8 @@ discard block |
||
419 | 417 | * |
420 | 418 | * @return string |
421 | 419 | */ |
422 | - private function stringLiteral( $text ) { |
|
423 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
420 | + private function stringLiteral($text) { |
|
421 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
424 | 422 | } |
425 | 423 | |
426 | 424 | /** |
@@ -430,18 +428,18 @@ discard block |
||
430 | 428 | * |
431 | 429 | * @return CachedEntityIds |
432 | 430 | */ |
433 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
434 | - return new CachedEntityIds( array_map( |
|
435 | - function ( $resultBindings ) { |
|
431 | + private function getOtherEntities(CachedQueryResults $results) { |
|
432 | + return new CachedEntityIds(array_map( |
|
433 | + function($resultBindings) { |
|
436 | 434 | $entityIRI = $resultBindings['otherEntity']['value']; |
437 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
438 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
439 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
435 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
436 | + $entityPrefixLength = strlen($entityPrefix); |
|
437 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
440 | 438 | try { |
441 | 439 | return $this->entityIdParser->parse( |
442 | - substr( $entityIRI, $entityPrefixLength ) |
|
440 | + substr($entityIRI, $entityPrefixLength) |
|
443 | 441 | ); |
444 | - } catch ( EntityIdParsingException $e ) { |
|
442 | + } catch (EntityIdParsingException $e) { |
|
445 | 443 | // fall through |
446 | 444 | } |
447 | 445 | } |
@@ -452,7 +450,7 @@ discard block |
||
452 | 450 | return null; |
453 | 451 | }, |
454 | 452 | $results->getArray()['results']['bindings'] |
455 | - ), $results->getMetadata() ); |
|
453 | + ), $results->getMetadata()); |
|
456 | 454 | } |
457 | 455 | |
458 | 456 | // @codingStandardsIgnoreStart cyclomatic complexity of this function is too high |
@@ -465,49 +463,49 @@ discard block |
||
465 | 463 | * @return array the literal or IRI as a string in SPARQL syntax, |
466 | 464 | * and a boolean indicating whether it refers to a full value node or not |
467 | 465 | */ |
468 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
469 | - switch ( $dataType ) { |
|
466 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
467 | + switch ($dataType) { |
|
470 | 468 | case 'string': |
471 | 469 | case 'external-id': |
472 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
470 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
473 | 471 | case 'commonsMedia': |
474 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
475 | - return [ '<' . $url . '>', false ]; |
|
472 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
473 | + return ['<'.$url.'>', false]; |
|
476 | 474 | case 'geo-shape': |
477 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
478 | - return [ '<' . $url . '>', false ]; |
|
475 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
476 | + return ['<'.$url.'>', false]; |
|
479 | 477 | case 'tabular-data': |
480 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
481 | - return [ '<' . $url . '>', false ]; |
|
478 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
479 | + return ['<'.$url.'>', false]; |
|
482 | 480 | case 'url': |
483 | 481 | $url = $dataValue->getValue(); |
484 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
482 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
485 | 483 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
486 | 484 | // such an URL should never reach us, so just throw |
487 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
485 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
488 | 486 | } |
489 | - return [ '<' . $url . '>', false ]; |
|
487 | + return ['<'.$url.'>', false]; |
|
490 | 488 | case 'wikibase-item': |
491 | 489 | case 'wikibase-property': |
492 | 490 | /** @var EntityIdValue $dataValue */ |
493 | 491 | '@phan-var EntityIdValue $dataValue'; |
494 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
492 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
495 | 493 | case 'monolingualtext': |
496 | 494 | /** @var MonolingualTextValue $dataValue */ |
497 | 495 | '@phan-var MonolingualTextValue $dataValue'; |
498 | 496 | $lang = $dataValue->getLanguageCode(); |
499 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
497 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
500 | 498 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
501 | 499 | // such a language tag should never reach us, so just throw |
502 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
500 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
503 | 501 | } |
504 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
502 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
505 | 503 | case 'globe-coordinate': |
506 | 504 | case 'quantity': |
507 | 505 | case 'time': |
508 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
506 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
509 | 507 | default: |
510 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
508 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
511 | 509 | } |
512 | 510 | } |
513 | 511 | // @codingStandardsIgnoreEnd |
@@ -520,43 +518,43 @@ discard block |
||
520 | 518 | * @throws SparqlHelperException if the query times out or some other error occurs |
521 | 519 | * @throws ConstraintParameterException if the $regex is invalid |
522 | 520 | */ |
523 | - public function matchesRegularExpression( $text, $regex ) { |
|
521 | + public function matchesRegularExpression($text, $regex) { |
|
524 | 522 | // caching wrapper around matchesRegularExpressionWithSparql |
525 | 523 | |
526 | - $textHash = hash( 'sha256', $text ); |
|
524 | + $textHash = hash('sha256', $text); |
|
527 | 525 | $cacheKey = $this->cache->makeKey( |
528 | 526 | 'WikibaseQualityConstraints', // extension |
529 | 527 | 'regex', // action |
530 | 528 | 'WDQS-Java', // regex flavor |
531 | - hash( 'sha256', $regex ) |
|
529 | + hash('sha256', $regex) |
|
532 | 530 | ); |
533 | 531 | |
534 | 532 | $cacheMapArray = $this->cache->getWithSetCallback( |
535 | 533 | $cacheKey, |
536 | 534 | WANObjectCache::TTL_DAY, |
537 | - function ( $cacheMapArray ) use ( $text, $regex, $textHash ) { |
|
535 | + function($cacheMapArray) use ($text, $regex, $textHash) { |
|
538 | 536 | // Initialize the cache map if not set |
539 | - if ( $cacheMapArray === false ) { |
|
537 | + if ($cacheMapArray === false) { |
|
540 | 538 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
541 | - $this->dataFactory->increment( $key ); |
|
539 | + $this->dataFactory->increment($key); |
|
542 | 540 | return []; |
543 | 541 | } |
544 | 542 | |
545 | 543 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
546 | - $this->dataFactory->increment( $key ); |
|
547 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize ); |
|
548 | - if ( $cacheMap->has( $textHash ) ) { |
|
544 | + $this->dataFactory->increment($key); |
|
545 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize); |
|
546 | + if ($cacheMap->has($textHash)) { |
|
549 | 547 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
550 | - $this->dataFactory->increment( $key ); |
|
551 | - $cacheMap->get( $textHash ); // ping cache |
|
548 | + $this->dataFactory->increment($key); |
|
549 | + $cacheMap->get($textHash); // ping cache |
|
552 | 550 | } else { |
553 | 551 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
554 | - $this->dataFactory->increment( $key ); |
|
552 | + $this->dataFactory->increment($key); |
|
555 | 553 | try { |
556 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
557 | - } catch ( ConstraintParameterException $e ) { |
|
558 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
559 | - } catch ( SparqlHelperException $e ) { |
|
554 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
555 | + } catch (ConstraintParameterException $e) { |
|
556 | + $matches = $this->serializeConstraintParameterException($e); |
|
557 | + } catch (SparqlHelperException $e) { |
|
560 | 558 | // don’t cache this |
561 | 559 | return $cacheMap->toArray(); |
562 | 560 | } |
@@ -580,42 +578,42 @@ discard block |
||
580 | 578 | ] |
581 | 579 | ); |
582 | 580 | |
583 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
581 | + if (isset($cacheMapArray[$textHash])) { |
|
584 | 582 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
585 | - $this->dataFactory->increment( $key ); |
|
583 | + $this->dataFactory->increment($key); |
|
586 | 584 | $matches = $cacheMapArray[$textHash]; |
587 | - if ( is_bool( $matches ) ) { |
|
585 | + if (is_bool($matches)) { |
|
588 | 586 | return $matches; |
589 | - } elseif ( is_array( $matches ) && |
|
590 | - $matches['type'] == ConstraintParameterException::class ) { |
|
591 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
587 | + } elseif (is_array($matches) && |
|
588 | + $matches['type'] == ConstraintParameterException::class) { |
|
589 | + throw $this->deserializeConstraintParameterException($matches); |
|
592 | 590 | } else { |
593 | 591 | throw new MWException( |
594 | - 'Value of unknown type in object cache (' . |
|
595 | - 'cache key: ' . $cacheKey . ', ' . |
|
596 | - 'cache map key: ' . $textHash . ', ' . |
|
597 | - 'value type: ' . gettype( $matches ) . ')' |
|
592 | + 'Value of unknown type in object cache ('. |
|
593 | + 'cache key: '.$cacheKey.', '. |
|
594 | + 'cache map key: '.$textHash.', '. |
|
595 | + 'value type: '.gettype($matches).')' |
|
598 | 596 | ); |
599 | 597 | } |
600 | 598 | } else { |
601 | 599 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
602 | - $this->dataFactory->increment( $key ); |
|
603 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
600 | + $this->dataFactory->increment($key); |
|
601 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
604 | 602 | } |
605 | 603 | } |
606 | 604 | |
607 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
605 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
608 | 606 | return [ |
609 | 607 | 'type' => ConstraintParameterException::class, |
610 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
608 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
611 | 609 | ]; |
612 | 610 | } |
613 | 611 | |
614 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
612 | + private function deserializeConstraintParameterException(array $serialization) { |
|
615 | 613 | $message = $this->violationMessageDeserializer->deserialize( |
616 | 614 | $serialization['violationMessage'] |
617 | 615 | ); |
618 | - return new ConstraintParameterException( $message ); |
|
616 | + return new ConstraintParameterException($message); |
|
619 | 617 | } |
620 | 618 | |
621 | 619 | /** |
@@ -629,25 +627,25 @@ discard block |
||
629 | 627 | * @throws SparqlHelperException if the query times out or some other error occurs |
630 | 628 | * @throws ConstraintParameterException if the $regex is invalid |
631 | 629 | */ |
632 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
633 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
634 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
630 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
631 | + $textStringLiteral = $this->stringLiteral($text); |
|
632 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
635 | 633 | |
636 | 634 | $query = <<<EOF |
637 | 635 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
638 | 636 | EOF; |
639 | 637 | |
640 | - $result = $this->runQuery( $query, false ); |
|
638 | + $result = $this->runQuery($query, false); |
|
641 | 639 | |
642 | 640 | $vars = $result->getArray()['results']['bindings'][0]; |
643 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
641 | + if (array_key_exists('matches', $vars)) { |
|
644 | 642 | // true or false ⇒ regex okay, text matches or not |
645 | 643 | return $vars['matches']['value'] === 'true'; |
646 | 644 | } else { |
647 | 645 | // empty result: regex broken |
648 | 646 | throw new ConstraintParameterException( |
649 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
650 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
647 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
648 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
651 | 649 | ); |
652 | 650 | } |
653 | 651 | } |
@@ -659,14 +657,14 @@ discard block |
||
659 | 657 | * |
660 | 658 | * @return boolean |
661 | 659 | */ |
662 | - public function isTimeout( $responseContent ) { |
|
663 | - $timeoutRegex = implode( '|', array_map( |
|
664 | - function ( $fqn ) { |
|
665 | - return preg_quote( $fqn, '/' ); |
|
660 | + public function isTimeout($responseContent) { |
|
661 | + $timeoutRegex = implode('|', array_map( |
|
662 | + function($fqn) { |
|
663 | + return preg_quote($fqn, '/'); |
|
666 | 664 | }, |
667 | 665 | $this->timeoutExceptionClasses |
668 | - ) ); |
|
669 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
666 | + )); |
|
667 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
670 | 668 | } |
671 | 669 | |
672 | 670 | /** |
@@ -678,17 +676,17 @@ discard block |
||
678 | 676 | * @return int|boolean the max-age (in seconds) |
679 | 677 | * or a plain boolean if no max-age can be determined |
680 | 678 | */ |
681 | - public function getCacheMaxAge( $responseHeaders ) { |
|
679 | + public function getCacheMaxAge($responseHeaders) { |
|
682 | 680 | if ( |
683 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
684 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
681 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
682 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
685 | 683 | ) { |
686 | 684 | $maxage = []; |
687 | 685 | if ( |
688 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
689 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
686 | + array_key_exists('cache-control', $responseHeaders) && |
|
687 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
690 | 688 | ) { |
691 | - return intval( $maxage[1] ); |
|
689 | + return intval($maxage[1]); |
|
692 | 690 | } else { |
693 | 691 | return true; |
694 | 692 | } |
@@ -709,34 +707,34 @@ discard block |
||
709 | 707 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
710 | 708 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
711 | 709 | */ |
712 | - public function getThrottling( MWHttpRequest $request ) { |
|
713 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
714 | - if ( $retryAfterValue === null ) { |
|
710 | + public function getThrottling(MWHttpRequest $request) { |
|
711 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
712 | + if ($retryAfterValue === null) { |
|
715 | 713 | return self::NO_RETRY_AFTER; |
716 | 714 | } |
717 | 715 | |
718 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
719 | - if ( empty( $trimmedRetryAfterValue ) ) { |
|
716 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
717 | + if (empty($trimmedRetryAfterValue)) { |
|
720 | 718 | return self::EMPTY_RETRY_AFTER; |
721 | 719 | } |
722 | 720 | |
723 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
724 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
725 | - if ( $delaySeconds >= 0 ) { |
|
726 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
721 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
722 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
723 | + if ($delaySeconds >= 0) { |
|
724 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
727 | 725 | } |
728 | 726 | } else { |
729 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
730 | - if ( !empty( $return ) ) { |
|
731 | - return new ConvertibleTimestamp( $return ); |
|
727 | + $return = strtotime($trimmedRetryAfterValue); |
|
728 | + if (!empty($return)) { |
|
729 | + return new ConvertibleTimestamp($return); |
|
732 | 730 | } |
733 | 731 | } |
734 | 732 | return self::INVALID_RETRY_AFTER; |
735 | 733 | } |
736 | 734 | |
737 | - private function getTimestampInFuture( DateInterval $delta ) { |
|
735 | + private function getTimestampInFuture(DateInterval $delta) { |
|
738 | 736 | $now = new ConvertibleTimestamp(); |
739 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
737 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
740 | 738 | } |
741 | 739 | |
742 | 740 | /** |
@@ -750,65 +748,64 @@ discard block |
||
750 | 748 | * |
751 | 749 | * @throws SparqlHelperException if the query times out or some other error occurs |
752 | 750 | */ |
753 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
751 | + public function runQuery($query, $needsPrefixes = true) { |
|
754 | 752 | |
755 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
756 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
753 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
754 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
757 | 755 | throw new TooManySparqlRequestsException(); |
758 | 756 | } |
759 | 757 | |
760 | - if ( $this->sparqlHasWikibaseSupport ) { |
|
758 | + if ($this->sparqlHasWikibaseSupport) { |
|
761 | 759 | $needsPrefixes = false; |
762 | 760 | } |
763 | 761 | |
764 | - if ( $needsPrefixes ) { |
|
765 | - $query = $this->prefixes . $query; |
|
762 | + if ($needsPrefixes) { |
|
763 | + $query = $this->prefixes.$query; |
|
766 | 764 | } |
767 | - $query = "#wbqc\n" . $query; |
|
765 | + $query = "#wbqc\n".$query; |
|
768 | 766 | |
769 | - $url = $this->endpoint . '?' . http_build_query( |
|
767 | + $url = $this->endpoint.'?'.http_build_query( |
|
770 | 768 | [ |
771 | 769 | 'query' => $query, |
772 | 770 | 'format' => 'json', |
773 | 771 | 'maxQueryTimeMillis' => $this->maxQueryTimeMillis, |
774 | 772 | ], |
775 | - null, ini_get( 'arg_separator.output' ), |
|
773 | + null, ini_get('arg_separator.output'), |
|
776 | 774 | // encode spaces with %20, not + |
777 | 775 | PHP_QUERY_RFC3986 |
778 | 776 | ); |
779 | 777 | |
780 | 778 | $options = [ |
781 | 779 | 'method' => 'GET', |
782 | - 'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ), |
|
780 | + 'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000), |
|
783 | 781 | 'connectTimeout' => 'default', |
784 | 782 | 'userAgent' => $this->defaultUserAgent, |
785 | 783 | ]; |
786 | - $request = $this->requestFactory->create( $url, $options, __METHOD__ ); |
|
787 | - $startTime = microtime( true ); |
|
784 | + $request = $this->requestFactory->create($url, $options, __METHOD__); |
|
785 | + $startTime = microtime(true); |
|
788 | 786 | $requestStatus = $request->execute(); |
789 | - $endTime = microtime( true ); |
|
787 | + $endTime = microtime(true); |
|
790 | 788 | $this->dataFactory->timing( |
791 | 789 | 'wikibase.quality.constraints.sparql.timing', |
792 | - ( $endTime - $startTime ) * 1000 |
|
790 | + ($endTime - $startTime) * 1000 |
|
793 | 791 | ); |
794 | 792 | |
795 | - $this->guardAgainstTooManyRequestsError( $request ); |
|
793 | + $this->guardAgainstTooManyRequestsError($request); |
|
796 | 794 | |
797 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
798 | - if ( $maxAge ) { |
|
799 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
795 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
796 | + if ($maxAge) { |
|
797 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
800 | 798 | } |
801 | 799 | |
802 | - if ( $requestStatus->isOK() ) { |
|
800 | + if ($requestStatus->isOK()) { |
|
803 | 801 | $json = $request->getContent(); |
804 | - $jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
|
805 | - if ( $jsonStatus->isOK() ) { |
|
802 | + $jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC); |
|
803 | + if ($jsonStatus->isOK()) { |
|
806 | 804 | return new CachedQueryResults( |
807 | 805 | $jsonStatus->getValue(), |
808 | 806 | Metadata::ofCachingMetadata( |
809 | 807 | $maxAge ? |
810 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
811 | - CachingMetadata::fresh() |
|
808 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
812 | 809 | ) |
813 | 810 | ); |
814 | 811 | } else { |
@@ -825,9 +822,9 @@ discard block |
||
825 | 822 | // fall through to general error handling |
826 | 823 | } |
827 | 824 | |
828 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
825 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
829 | 826 | |
830 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
827 | + if ($this->isTimeout($request->getContent())) { |
|
831 | 828 | $this->dataFactory->increment( |
832 | 829 | 'wikibase.quality.constraints.sparql.error.timeout' |
833 | 830 | ); |
@@ -842,29 +839,29 @@ discard block |
||
842 | 839 | * @param MWHttpRequest $request |
843 | 840 | * @throws TooManySparqlRequestsException |
844 | 841 | */ |
845 | - private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void { |
|
846 | - if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) { |
|
842 | + private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void { |
|
843 | + if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) { |
|
847 | 844 | return; |
848 | 845 | } |
849 | 846 | |
850 | 847 | $fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration; |
851 | 848 | |
852 | - if ( $fallbackBlockDuration < 0 ) { |
|
853 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' . |
|
854 | - $fallbackBlockDuration ); |
|
849 | + if ($fallbackBlockDuration < 0) { |
|
850 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
851 | + $fallbackBlockDuration); |
|
855 | 852 | } |
856 | 853 | |
857 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
858 | - $throttlingUntil = $this->getThrottling( $request ); |
|
859 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
860 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
854 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
855 | + $throttlingUntil = $this->getThrottling($request); |
|
856 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
857 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
861 | 858 | $this->throttlingLock->lock( |
862 | 859 | self::EXPIRY_LOCK_ID, |
863 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
860 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
864 | 861 | ); |
865 | 862 | } else { |
866 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
867 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
863 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
864 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
868 | 865 | } |
869 | 866 | throw new TooManySparqlRequestsException(); |
870 | 867 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param WANObjectCache $cache |
37 | 37 | * @param string $formatVersion The version of the API response format. |
38 | 38 | */ |
39 | - public function __construct( WANObjectCache $cache, $formatVersion ) { |
|
39 | + public function __construct(WANObjectCache $cache, $formatVersion) { |
|
40 | 40 | $this->cache = $cache; |
41 | 41 | $this->formatVersion = $formatVersion; |
42 | 42 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param EntityId $entityId |
46 | 46 | * @return string cache key |
47 | 47 | */ |
48 | - public function makeKey( EntityId $entityId ) { |
|
48 | + public function makeKey(EntityId $entityId) { |
|
49 | 49 | return $this->cache->makeKey( |
50 | 50 | 'WikibaseQualityConstraints', // extension |
51 | 51 | 'checkConstraints', // action |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param mixed|null &$info |
62 | 62 | * @return mixed |
63 | 63 | */ |
64 | - public function get( EntityId $key, &$curTTL = null, array $checkKeys = [], &$info = null ) { |
|
65 | - return $this->cache->get( $this->makeKey( $key ), $curTTL, $checkKeys, $info ); |
|
64 | + public function get(EntityId $key, &$curTTL = null, array $checkKeys = [], &$info = null) { |
|
65 | + return $this->cache->get($this->makeKey($key), $curTTL, $checkKeys, $info); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -72,16 +72,16 @@ discard block |
||
72 | 72 | * @param array $opts |
73 | 73 | * @return bool |
74 | 74 | */ |
75 | - public function set( EntityId $key, $value, $ttl = 0, array $opts = [] ) { |
|
76 | - return $this->cache->set( $this->makeKey( $key ), $value, $ttl, $opts ); |
|
75 | + public function set(EntityId $key, $value, $ttl = 0, array $opts = []) { |
|
76 | + return $this->cache->set($this->makeKey($key), $value, $ttl, $opts); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @param EntityId $key |
81 | 81 | * @return bool |
82 | 82 | */ |
83 | - public function delete( EntityId $key ) { |
|
84 | - return $this->cache->delete( $this->makeKey( $key ) ); |
|
83 | + public function delete(EntityId $key) { |
|
84 | + return $this->cache->delete($this->makeKey($key)); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | } |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | DelegatingConstraintChecker $delegatingConstraintChecker |
79 | 79 | ): self { |
80 | 80 | $repo = WikibaseRepo::getDefaultInstance(); |
81 | - $helperFactory = $repo->getApiHelperFactory( RequestContext::getMain() ); |
|
81 | + $helperFactory = $repo->getApiHelperFactory(RequestContext::getMain()); |
|
82 | 82 | $language = $repo->getUserLanguage(); |
83 | 83 | |
84 | 84 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
85 | 85 | $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory |
86 | - ->getEntityIdFormatter( $language ); |
|
86 | + ->getEntityIdFormatter($language); |
|
87 | 87 | $formatterOptions = new FormatterOptions(); |
88 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
88 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
89 | 89 | $dataValueFormatter = $valueFormatterFactory |
90 | - ->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
90 | + ->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
91 | 91 | $violationMessageRenderer = new MultilingualTextViolationMessageRenderer( |
92 | 92 | $entityIdHtmlLinkFormatter, |
93 | 93 | $dataValueFormatter, |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | StatementGuidParser $statementGuidParser, |
124 | 124 | IBufferingStatsdDataFactory $dataFactory |
125 | 125 | ) { |
126 | - parent::__construct( $main, $name ); |
|
126 | + parent::__construct($main, $name); |
|
127 | 127 | |
128 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
128 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
129 | 129 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
130 | 130 | $this->violationMessageRenderer = $violationMessageRenderer; |
131 | 131 | $this->statementGuidParser = $statementGuidParser; |
@@ -140,39 +140,39 @@ discard block |
||
140 | 140 | $params = $this->extractRequestParams(); |
141 | 141 | $result = $this->getResult(); |
142 | 142 | |
143 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
144 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
143 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
144 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
145 | 145 | |
146 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
147 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
146 | + $this->checkPropertyIds($propertyIds, $result); |
|
147 | + $this->checkConstraintIds($constraintIds, $result); |
|
148 | 148 | |
149 | - $result->addValue( null, 'success', 1 ); |
|
149 | + $result->addValue(null, 'success', 1); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
153 | 153 | * @param array|null $propertyIdSerializations |
154 | 154 | * @return PropertyId[] |
155 | 155 | */ |
156 | - private function parsePropertyIds( $propertyIdSerializations ) { |
|
157 | - if ( $propertyIdSerializations === null ) { |
|
156 | + private function parsePropertyIds($propertyIdSerializations) { |
|
157 | + if ($propertyIdSerializations === null) { |
|
158 | 158 | return []; |
159 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
159 | + } elseif (empty($propertyIdSerializations)) { |
|
160 | 160 | $this->apiErrorReporter->dieError( |
161 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
161 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
162 | 162 | 'no-data' |
163 | 163 | ); |
164 | 164 | } |
165 | 165 | |
166 | 166 | return array_map( |
167 | - function ( $propertyIdSerialization ) { |
|
167 | + function($propertyIdSerialization) { |
|
168 | 168 | try { |
169 | - return new PropertyId( $propertyIdSerialization ); |
|
170 | - } catch ( InvalidArgumentException $e ) { |
|
169 | + return new PropertyId($propertyIdSerialization); |
|
170 | + } catch (InvalidArgumentException $e) { |
|
171 | 171 | $this->apiErrorReporter->dieError( |
172 | 172 | "Invalid id: $propertyIdSerialization", |
173 | 173 | 'invalid-property-id', |
174 | 174 | 0, // default argument |
175 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
175 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
176 | 176 | ); |
177 | 177 | } |
178 | 178 | }, |
@@ -184,35 +184,35 @@ discard block |
||
184 | 184 | * @param array|null $constraintIds |
185 | 185 | * @return string[] |
186 | 186 | */ |
187 | - private function parseConstraintIds( $constraintIds ) { |
|
188 | - if ( $constraintIds === null ) { |
|
187 | + private function parseConstraintIds($constraintIds) { |
|
188 | + if ($constraintIds === null) { |
|
189 | 189 | return []; |
190 | - } elseif ( empty( $constraintIds ) ) { |
|
190 | + } elseif (empty($constraintIds)) { |
|
191 | 191 | $this->apiErrorReporter->dieError( |
192 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
192 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
193 | 193 | 'no-data' |
194 | 194 | ); |
195 | 195 | } |
196 | 196 | |
197 | 197 | return array_map( |
198 | - function ( $constraintId ) { |
|
198 | + function($constraintId) { |
|
199 | 199 | try { |
200 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
201 | - if ( !$propertyId instanceof PropertyId ) { |
|
200 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
201 | + if (!$propertyId instanceof PropertyId) { |
|
202 | 202 | $this->apiErrorReporter->dieError( |
203 | 203 | "Invalid property ID: {$propertyId->getSerialization()}", |
204 | 204 | 'invalid-property-id', |
205 | 205 | 0, // default argument |
206 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
206 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
207 | 207 | ); |
208 | 208 | } |
209 | 209 | return $constraintId; |
210 | - } catch ( StatementGuidParsingException $e ) { |
|
210 | + } catch (StatementGuidParsingException $e) { |
|
211 | 211 | $this->apiErrorReporter->dieError( |
212 | 212 | "Invalid statement GUID: $constraintId", |
213 | 213 | 'invalid-guid', |
214 | 214 | 0, // default argument |
215 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
215 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
216 | 216 | ); |
217 | 217 | } |
218 | 218 | }, |
@@ -224,12 +224,12 @@ discard block |
||
224 | 224 | * @param PropertyId[] $propertyIds |
225 | 225 | * @param ApiResult $result |
226 | 226 | */ |
227 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ) { |
|
228 | - foreach ( $propertyIds as $propertyId ) { |
|
229 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
227 | + private function checkPropertyIds(array $propertyIds, ApiResult $result) { |
|
228 | + foreach ($propertyIds as $propertyId) { |
|
229 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
230 | 230 | $allConstraintExceptions = $this->delegatingConstraintChecker |
231 | - ->checkConstraintParametersOnPropertyId( $propertyId ); |
|
232 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
231 | + ->checkConstraintParametersOnPropertyId($propertyId); |
|
232 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
233 | 233 | $this->addConstraintParameterExceptionsToResult( |
234 | 234 | $constraintId, |
235 | 235 | $constraintParameterExceptions, |
@@ -243,15 +243,15 @@ discard block |
||
243 | 243 | * @param string[] $constraintIds |
244 | 244 | * @param ApiResult $result |
245 | 245 | */ |
246 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ) { |
|
247 | - foreach ( $constraintIds as $constraintId ) { |
|
248 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
246 | + private function checkConstraintIds(array $constraintIds, ApiResult $result) { |
|
247 | + foreach ($constraintIds as $constraintId) { |
|
248 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
249 | 249 | // already checked as part of checkPropertyIds() |
250 | 250 | continue; |
251 | 251 | } |
252 | 252 | $constraintParameterExceptions = $this->delegatingConstraintChecker |
253 | - ->checkConstraintParametersOnConstraintId( $constraintId ); |
|
254 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
253 | + ->checkConstraintParametersOnConstraintId($constraintId); |
|
254 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
@@ -259,18 +259,18 @@ discard block |
||
259 | 259 | * @param PropertyId $propertyId |
260 | 260 | * @return string[] |
261 | 261 | */ |
262 | - private function getResultPathForPropertyId( PropertyId $propertyId ) { |
|
263 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
262 | + private function getResultPathForPropertyId(PropertyId $propertyId) { |
|
263 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | 267 | * @param string $constraintId |
268 | 268 | * @return string[] |
269 | 269 | */ |
270 | - private function getResultPathForConstraintId( $constraintId ) { |
|
271 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
270 | + private function getResultPathForConstraintId($constraintId) { |
|
271 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
272 | 272 | '@phan-var PropertyId $propertyId'; |
273 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
273 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | $constraintParameterExceptions, |
286 | 286 | ApiResult $result |
287 | 287 | ) { |
288 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
289 | - if ( $constraintParameterExceptions === null ) { |
|
288 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
289 | + if ($constraintParameterExceptions === null) { |
|
290 | 290 | $result->addValue( |
291 | 291 | $path, |
292 | 292 | self::KEY_STATUS, |
@@ -296,12 +296,12 @@ discard block |
||
296 | 296 | $result->addValue( |
297 | 297 | $path, |
298 | 298 | self::KEY_STATUS, |
299 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
299 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
300 | 300 | ); |
301 | 301 | $result->addValue( |
302 | 302 | $path, |
303 | 303 | self::KEY_PROBLEMS, |
304 | - array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions ) |
|
304 | + array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions) |
|
305 | 305 | ); |
306 | 306 | } |
307 | 307 | } |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | * @param ConstraintParameterException $e |
313 | 313 | * @return string[] |
314 | 314 | */ |
315 | - private function formatConstraintParameterException( ConstraintParameterException $e ) { |
|
315 | + private function formatConstraintParameterException(ConstraintParameterException $e) { |
|
316 | 316 | return [ |
317 | 317 | self::KEY_MESSAGE_HTML => $this->violationMessageRenderer->render( |
318 | 318 | $e->getViolationMessage() |
@@ -345,8 +345,8 @@ discard block |
||
345 | 345 | return [ |
346 | 346 | 'action=wbcheckconstraintparameters&propertyid=P247' |
347 | 347 | => 'apihelp-wbcheckconstraintparameters-example-propertyid-1', |
348 | - 'action=wbcheckconstraintparameters&' . |
|
349 | - 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' . |
|
348 | + 'action=wbcheckconstraintparameters&'. |
|
349 | + 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'. |
|
350 | 350 | 'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f' |
351 | 351 | => 'apihelp-wbcheckconstraintparameters-example-constraintid-2', |
352 | 352 | ]; |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | |
87 | 87 | $language = $repo->getUserLanguage(); |
88 | 88 | $formatterOptions = new FormatterOptions(); |
89 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
90 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
89 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
90 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
91 | 91 | |
92 | 92 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
93 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $language ); |
|
93 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($language); |
|
94 | 94 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
95 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $language ); |
|
95 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($language); |
|
96 | 96 | |
97 | 97 | $checkResultsRenderer = new CheckResultsRenderer( |
98 | 98 | $entityTitleLookup, |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $name, |
111 | 111 | $entityIdParser, |
112 | 112 | $statementGuidValidator, |
113 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
113 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
114 | 114 | $resultsSource, |
115 | 115 | $checkResultsRenderer, |
116 | 116 | $dataFactory |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | CheckResultsRenderer $checkResultsRenderer, |
138 | 138 | IBufferingStatsdDataFactory $dataFactory |
139 | 139 | ) { |
140 | - parent::__construct( $main, $name ); |
|
140 | + parent::__construct($main, $name); |
|
141 | 141 | $this->entityIdParser = $entityIdParser; |
142 | 142 | $this->statementGuidValidator = $statementGuidValidator; |
143 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
144 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
143 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
144 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
145 | 145 | $this->resultsSource = $resultsSource; |
146 | 146 | $this->checkResultsRenderer = $checkResultsRenderer; |
147 | 147 | $this->dataFactory = $dataFactory; |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | |
158 | 158 | $params = $this->extractRequestParams(); |
159 | 159 | |
160 | - $this->validateParameters( $params ); |
|
161 | - $entityIds = $this->parseEntityIds( $params ); |
|
162 | - $claimIds = $this->parseClaimIds( $params ); |
|
160 | + $this->validateParameters($params); |
|
161 | + $entityIds = $this->parseEntityIds($params); |
|
162 | + $claimIds = $this->parseClaimIds($params); |
|
163 | 163 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
164 | 164 | $statuses = $params[self::PARAM_STATUS]; |
165 | 165 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | ) |
176 | 176 | )->getArray() |
177 | 177 | ); |
178 | - $this->resultBuilder->markSuccess( 1 ); |
|
178 | + $this->resultBuilder->markSuccess(1); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -183,24 +183,24 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return EntityId[] |
185 | 185 | */ |
186 | - private function parseEntityIds( array $params ) { |
|
186 | + private function parseEntityIds(array $params) { |
|
187 | 187 | $ids = $params[self::PARAM_ID]; |
188 | 188 | |
189 | - if ( $ids === null ) { |
|
189 | + if ($ids === null) { |
|
190 | 190 | return []; |
191 | - } elseif ( $ids === [] ) { |
|
191 | + } elseif ($ids === []) { |
|
192 | 192 | $this->errorReporter->dieError( |
193 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
193 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
194 | 194 | } |
195 | 195 | |
196 | - return array_map( function ( $id ) { |
|
196 | + return array_map(function($id) { |
|
197 | 197 | try { |
198 | - return $this->entityIdParser->parse( $id ); |
|
199 | - } catch ( EntityIdParsingException $e ) { |
|
198 | + return $this->entityIdParser->parse($id); |
|
199 | + } catch (EntityIdParsingException $e) { |
|
200 | 200 | $this->errorReporter->dieError( |
201 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
201 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
202 | 202 | } |
203 | - }, $ids ); |
|
203 | + }, $ids); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -208,35 +208,35 @@ discard block |
||
208 | 208 | * |
209 | 209 | * @return string[] |
210 | 210 | */ |
211 | - private function parseClaimIds( array $params ) { |
|
211 | + private function parseClaimIds(array $params) { |
|
212 | 212 | $ids = $params[self::PARAM_CLAIM_ID]; |
213 | 213 | |
214 | - if ( $ids === null ) { |
|
214 | + if ($ids === null) { |
|
215 | 215 | return []; |
216 | - } elseif ( $ids === [] ) { |
|
216 | + } elseif ($ids === []) { |
|
217 | 217 | $this->errorReporter->dieError( |
218 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
218 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
219 | 219 | } |
220 | 220 | |
221 | - foreach ( $ids as $id ) { |
|
222 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
221 | + foreach ($ids as $id) { |
|
222 | + if (!$this->statementGuidValidator->validate($id)) { |
|
223 | 223 | $this->errorReporter->dieError( |
224 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
224 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
228 | 228 | return $ids; |
229 | 229 | } |
230 | 230 | |
231 | - private function validateParameters( array $params ) { |
|
232 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
233 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
231 | + private function validateParameters(array $params) { |
|
232 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
233 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
234 | 234 | ) { |
235 | 235 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
236 | 236 | $this->errorReporter->dieError( |
237 | 237 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
238 | 238 | } |
239 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
239 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
240 | 240 | $paramId = self::PARAM_ID; |
241 | 241 | $paramClaimId = self::PARAM_CLAIM_ID; |
242 | 242 | $this->errorReporter->dieError( |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | ], |
278 | 278 | ApiBase::PARAM_ISMULTI => true, |
279 | 279 | ApiBase::PARAM_ALL => true, |
280 | - ApiBase::PARAM_DFLT => implode( '|', CachingResultsSource::CACHED_STATUSES ), |
|
280 | + ApiBase::PARAM_DFLT => implode('|', CachingResultsSource::CACHED_STATUSES), |
|
281 | 281 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
282 | 282 | ], |
283 | 283 | ]; |