@@ -40,243 +40,243 @@ |
||
40 | 40 | const PROPERTY_SCOPE_CHECKER = 'WBQC_PropertyScopeChecker'; |
41 | 41 | 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 | } |
@@ -38,90 +38,90 @@ |
||
38 | 38 | const RESULTS_SOURCE = 'WBQC_ResultsSource'; |
39 | 39 | const EXPIRY_LOCK = 'WBQC_ExpiryLock'; |
40 | 40 | |
41 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
42 | - if ( $services === null ) { |
|
41 | + private static function getService(?MediaWikiServices $services, $name) { |
|
42 | + if ($services === null) { |
|
43 | 43 | $services = MediaWikiServices::getInstance(); |
44 | 44 | } |
45 | - return $services->getService( $name ); |
|
45 | + return $services->getService($name); |
|
46 | 46 | } |
47 | 47 | |
48 | - public static function getLoggingHelper( MediaWikiServices $services = null ): LoggingHelper { |
|
49 | - return self::getService( $services, self::LOGGING_HELPER ); |
|
48 | + public static function getLoggingHelper(MediaWikiServices $services = null): LoggingHelper { |
|
49 | + return self::getService($services, self::LOGGING_HELPER); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public static function getConstraintRepository( |
53 | 53 | MediaWikiServices $services = null |
54 | 54 | ): ConstraintRepository { |
55 | - return self::getService( $services, self::CONSTRAINT_REPOSITORY ); |
|
55 | + return self::getService($services, self::CONSTRAINT_REPOSITORY); |
|
56 | 56 | } |
57 | 57 | |
58 | - public static function getConstraintLookup( MediaWikiServices $services = null ): ConstraintLookup { |
|
59 | - return self::getService( $services, self::CONSTRAINT_LOOKUP ); |
|
58 | + public static function getConstraintLookup(MediaWikiServices $services = null): ConstraintLookup { |
|
59 | + return self::getService($services, self::CONSTRAINT_LOOKUP); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | public static function getCheckResultSerializer( |
63 | 63 | MediaWikiServices $services = null |
64 | 64 | ): CheckResultSerializer { |
65 | - return self::getService( $services, self::CHECK_RESULT_SERIALIZER ); |
|
65 | + return self::getService($services, self::CHECK_RESULT_SERIALIZER); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | public static function getCheckResultDeserializer( |
69 | 69 | MediaWikiServices $services = null |
70 | 70 | ): CheckResultDeserializer { |
71 | - return self::getService( $services, self::CHECK_RESULT_DESERIALIZER ); |
|
71 | + return self::getService($services, self::CHECK_RESULT_DESERIALIZER); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | public static function getViolationMessageSerializer( |
75 | 75 | MediaWikiServices $services = null |
76 | 76 | ): ViolationMessageSerializer { |
77 | - return self::getService( $services, self::VIOLATION_MESSAGE_SERIALIZER ); |
|
77 | + return self::getService($services, self::VIOLATION_MESSAGE_SERIALIZER); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | public static function getViolationMessageDeserializer( |
81 | 81 | MediaWikiServices $services = null |
82 | 82 | ): ViolationMessageDeserializer { |
83 | - return self::getService( $services, self::VIOLATION_MESSAGE_DESERIALIZER ); |
|
83 | + return self::getService($services, self::VIOLATION_MESSAGE_DESERIALIZER); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | public static function getConstraintParameterParser( |
87 | 87 | MediaWikiServices $services = null |
88 | 88 | ): ConstraintParameterParser { |
89 | - return self::getService( $services, self::CONSTRAINT_PARAMETER_PARSER ); |
|
89 | + return self::getService($services, self::CONSTRAINT_PARAMETER_PARSER); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | public static function getConnectionCheckerHelper( |
93 | 93 | MediaWikiServices $services = null |
94 | 94 | ): ConnectionCheckerHelper { |
95 | - return self::getService( $services, self::CONNECTION_CHECKER_HELPER ); |
|
95 | + return self::getService($services, self::CONNECTION_CHECKER_HELPER); |
|
96 | 96 | } |
97 | 97 | |
98 | - public static function getRangeCheckerHelper( MediaWikiServices $services = null ): RangeCheckerHelper { |
|
99 | - return self::getService( $services, self::RANGE_CHECKER_HELPER ); |
|
98 | + public static function getRangeCheckerHelper(MediaWikiServices $services = null): RangeCheckerHelper { |
|
99 | + return self::getService($services, self::RANGE_CHECKER_HELPER); |
|
100 | 100 | } |
101 | 101 | |
102 | - public static function getSparqlHelper( MediaWikiServices $services = null ): SparqlHelper { |
|
103 | - return self::getService( $services, self::SPARQL_HELPER ); |
|
102 | + public static function getSparqlHelper(MediaWikiServices $services = null): SparqlHelper { |
|
103 | + return self::getService($services, self::SPARQL_HELPER); |
|
104 | 104 | } |
105 | 105 | |
106 | - public static function getTypeCheckerHelper( MediaWikiServices $services = null ): TypeCheckerHelper { |
|
107 | - return self::getService( $services, self::TYPE_CHECKER_HELPER ); |
|
106 | + public static function getTypeCheckerHelper(MediaWikiServices $services = null): TypeCheckerHelper { |
|
107 | + return self::getService($services, self::TYPE_CHECKER_HELPER); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | public static function getDelegatingConstraintChecker( |
111 | 111 | MediaWikiServices $services = null |
112 | 112 | ): DelegatingConstraintChecker { |
113 | - return self::getService( $services, self::DELEGATING_CONSTRAINT_CHECKER ); |
|
113 | + return self::getService($services, self::DELEGATING_CONSTRAINT_CHECKER); |
|
114 | 114 | } |
115 | 115 | |
116 | - public static function getResultsSource( MediaWikiServices $services = null ): ResultsSource { |
|
117 | - return self::getService( $services, self::RESULTS_SOURCE ); |
|
116 | + public static function getResultsSource(MediaWikiServices $services = null): ResultsSource { |
|
117 | + return self::getService($services, self::RESULTS_SOURCE); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @return ExpiryLock |
122 | 122 | */ |
123 | - public static function getExpiryLock( MediaWikiServices $services = null ) { |
|
124 | - return self::getService( $services, self::EXPIRY_LOCK ); |
|
123 | + public static function getExpiryLock(MediaWikiServices $services = null) { |
|
124 | + return self::getService($services, self::EXPIRY_LOCK); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | } |
@@ -143,14 +143,14 @@ discard block |
||
143 | 143 | ) { |
144 | 144 | $results = []; |
145 | 145 | $metadatas = []; |
146 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
146 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
147 | 147 | $storedEntityIds = []; |
148 | - foreach ( $entityIds as $entityId ) { |
|
149 | - $storedResults = $this->getStoredResults( $entityId ); |
|
150 | - if ( $storedResults !== null ) { |
|
151 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
152 | - foreach ( $storedResults->getArray() as $checkResult ) { |
|
153 | - if ( $this->statusSelected( $statuses, $checkResult ) ) { |
|
148 | + foreach ($entityIds as $entityId) { |
|
149 | + $storedResults = $this->getStoredResults($entityId); |
|
150 | + if ($storedResults !== null) { |
|
151 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
152 | + foreach ($storedResults->getArray() as $checkResult) { |
|
153 | + if ($this->statusSelected($statuses, $checkResult)) { |
|
154 | 154 | $results[] = $checkResult; |
155 | 155 | } |
156 | 156 | } |
@@ -158,19 +158,19 @@ discard block |
||
158 | 158 | $storedEntityIds[] = $entityId; |
159 | 159 | } |
160 | 160 | } |
161 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
161 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
162 | 162 | } |
163 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
164 | - if ( $entityIds !== [] ) { |
|
165 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
163 | + if ($entityIds !== [] || $claimIds !== []) { |
|
164 | + if ($entityIds !== []) { |
|
165 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
166 | 166 | } |
167 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
168 | - $results = array_merge( $results, $response->getArray() ); |
|
167 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
168 | + $results = array_merge($results, $response->getArray()); |
|
169 | 169 | $metadatas[] = $response->getMetadata(); |
170 | 170 | } |
171 | 171 | return new CachedCheckResults( |
172 | 172 | $results, |
173 | - Metadata::merge( $metadatas ) |
|
173 | + Metadata::merge($metadatas) |
|
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | ?array $constraintIds, |
194 | 194 | array $statuses |
195 | 195 | ) { |
196 | - if ( $claimIds !== [] ) { |
|
196 | + if ($claimIds !== []) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | - if ( $constraintIds !== null ) { |
|
199 | + if ($constraintIds !== null) { |
|
200 | 200 | return false; |
201 | 201 | } |
202 | - if ( array_diff( $statuses, self::CACHED_STATUSES ) !== [] ) { |
|
202 | + if (array_diff($statuses, self::CACHED_STATUSES) !== []) { |
|
203 | 203 | return false; |
204 | 204 | } |
205 | 205 | return true; |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | * @param CheckResult $result |
215 | 215 | * @return bool |
216 | 216 | */ |
217 | - private function statusSelected( array $statuses, CheckResult $result ) { |
|
218 | - return in_array( $result->getStatus(), $statuses, true ) || |
|
217 | + private function statusSelected(array $statuses, CheckResult $result) { |
|
218 | + return in_array($result->getStatus(), $statuses, true) || |
|
219 | 219 | $result instanceof NullResult; |
220 | 220 | } |
221 | 221 | |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | ?array $constraintIds, |
233 | 233 | array $statuses |
234 | 234 | ) { |
235 | - $results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
235 | + $results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
236 | 236 | |
237 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
238 | - foreach ( $entityIds as $entityId ) { |
|
239 | - $this->storeResults( $entityId, $results ); |
|
237 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
238 | + foreach ($entityIds as $entityId) { |
|
239 | + $this->storeResults($entityId, $results); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | ?array $constraintIds, |
268 | 268 | array $statuses |
269 | 269 | ) { |
270 | - if ( $constraintIds !== null ) { |
|
270 | + if ($constraintIds !== null) { |
|
271 | 271 | return false; |
272 | 272 | } |
273 | - if ( array_diff( self::CACHED_STATUSES, $statuses ) !== [] ) { |
|
273 | + if (array_diff(self::CACHED_STATUSES, $statuses) !== []) { |
|
274 | 274 | return false; |
275 | 275 | } |
276 | 276 | return true; |
@@ -284,21 +284,21 @@ discard block |
||
284 | 284 | * May include check results for other entity IDs as well, |
285 | 285 | * or check results with statuses that we’re not interested in caching. |
286 | 286 | */ |
287 | - private function storeResults( EntityId $entityId, CachedCheckResults $results ) { |
|
287 | + private function storeResults(EntityId $entityId, CachedCheckResults $results) { |
|
288 | 288 | $latestRevisionIds = $this->getLatestRevisionIds( |
289 | 289 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
290 | 290 | ); |
291 | - if ( $latestRevisionIds === null ) { |
|
291 | + if ($latestRevisionIds === null) { |
|
292 | 292 | return; |
293 | 293 | } |
294 | 294 | |
295 | 295 | $resultSerializations = []; |
296 | - foreach ( $results->getArray() as $checkResult ) { |
|
297 | - if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) { |
|
296 | + foreach ($results->getArray() as $checkResult) { |
|
297 | + if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) { |
|
298 | 298 | continue; |
299 | 299 | } |
300 | - if ( $this->statusSelected( self::CACHED_STATUSES, $checkResult ) ) { |
|
301 | - $resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult ); |
|
300 | + if ($this->statusSelected(self::CACHED_STATUSES, $checkResult)) { |
|
301 | + $resultSerializations[] = $this->checkResultSerializer->serialize($checkResult); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
@@ -307,11 +307,11 @@ discard block |
||
307 | 307 | 'latestRevisionIds' => $latestRevisionIds, |
308 | 308 | ]; |
309 | 309 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
310 | - if ( $futureTime !== null ) { |
|
310 | + if ($futureTime !== null) { |
|
311 | 311 | $value['futureTime'] = $futureTime->getArrayValue(); |
312 | 312 | } |
313 | 313 | |
314 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
314 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -325,31 +325,30 @@ discard block |
||
325 | 325 | EntityId $entityId, |
326 | 326 | $forRevision = 0 |
327 | 327 | ) { |
328 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
329 | - $now = call_user_func( $this->microtime, true ); |
|
328 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
329 | + $now = call_user_func($this->microtime, true); |
|
330 | 330 | |
331 | - $dependencyMetadata = $this->checkDependencyMetadata( $value, |
|
332 | - [ $entityId->getSerialization() => $forRevision ] ); |
|
333 | - if ( $dependencyMetadata === null ) { |
|
331 | + $dependencyMetadata = $this->checkDependencyMetadata($value, |
|
332 | + [$entityId->getSerialization() => $forRevision]); |
|
333 | + if ($dependencyMetadata === null) { |
|
334 | 334 | return null; |
335 | 335 | } |
336 | 336 | |
337 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
337 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
338 | 338 | $cachingMetadata = $ageInSeconds > 0 ? |
339 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
340 | - CachingMetadata::fresh(); |
|
339 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
341 | 340 | |
342 | 341 | $results = []; |
343 | - foreach ( $value['results'] as $resultSerialization ) { |
|
344 | - $results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata ); |
|
342 | + foreach ($value['results'] as $resultSerialization) { |
|
343 | + $results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata); |
|
345 | 344 | } |
346 | 345 | |
347 | 346 | return new CachedCheckResults( |
348 | 347 | $results, |
349 | - Metadata::merge( [ |
|
350 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
351 | - Metadata::ofDependencyMetadata( $dependencyMetadata ), |
|
352 | - ] ) |
|
348 | + Metadata::merge([ |
|
349 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
350 | + Metadata::ofDependencyMetadata($dependencyMetadata), |
|
351 | + ]) |
|
353 | 352 | ); |
354 | 353 | } |
355 | 354 | |
@@ -365,43 +364,43 @@ discard block |
||
365 | 364 | * @return DependencyMetadata|null the dependency metadata, |
366 | 365 | * or null if $value should no longer be used |
367 | 366 | */ |
368 | - private function checkDependencyMetadata( $value, $paramRevs ) { |
|
369 | - if ( $value === false ) { |
|
367 | + private function checkDependencyMetadata($value, $paramRevs) { |
|
368 | + if ($value === false) { |
|
370 | 369 | return null; |
371 | 370 | } |
372 | 371 | |
373 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
374 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
375 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
372 | + if (array_key_exists('futureTime', $value)) { |
|
373 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
374 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
376 | 375 | return null; |
377 | 376 | } |
378 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
377 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
379 | 378 | } else { |
380 | 379 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
381 | 380 | } |
382 | 381 | |
383 | - foreach ( $paramRevs as $id => $revision ) { |
|
384 | - if ( $revision > 0 ) { |
|
385 | - $value['latestRevisionIds'][$id] = min( $revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX ); |
|
382 | + foreach ($paramRevs as $id => $revision) { |
|
383 | + if ($revision > 0) { |
|
384 | + $value['latestRevisionIds'][$id] = min($revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX); |
|
386 | 385 | } |
387 | 386 | } |
388 | 387 | |
389 | 388 | $dependedEntityIds = array_map( |
390 | - [ $this->entityIdParser, "parse" ], |
|
391 | - array_keys( $value['latestRevisionIds'] ) |
|
389 | + [$this->entityIdParser, "parse"], |
|
390 | + array_keys($value['latestRevisionIds']) |
|
392 | 391 | ); |
393 | 392 | |
394 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
393 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
395 | 394 | return null; |
396 | 395 | } |
397 | 396 | |
398 | 397 | return array_reduce( |
399 | 398 | $dependedEntityIds, |
400 | - function( DependencyMetadata $metadata, EntityId $entityId ) { |
|
401 | - return DependencyMetadata::merge( [ |
|
399 | + function(DependencyMetadata $metadata, EntityId $entityId) { |
|
400 | + return DependencyMetadata::merge([ |
|
402 | 401 | $metadata, |
403 | - DependencyMetadata::ofEntityId( $entityId ) |
|
404 | - ] ); |
|
402 | + DependencyMetadata::ofEntityId($entityId) |
|
403 | + ]); |
|
405 | 404 | }, |
406 | 405 | $futureTimeDependencyMetadata |
407 | 406 | ); |
@@ -421,13 +420,13 @@ discard block |
||
421 | 420 | array $resultSerialization, |
422 | 421 | CachingMetadata $cachingMetadata |
423 | 422 | ) { |
424 | - $result = $this->checkResultDeserializer->deserialize( $resultSerialization ); |
|
425 | - if ( $this->isPossiblyStaleResult( $result ) ) { |
|
423 | + $result = $this->checkResultDeserializer->deserialize($resultSerialization); |
|
424 | + if ($this->isPossiblyStaleResult($result)) { |
|
426 | 425 | $result->withMetadata( |
427 | - Metadata::merge( [ |
|
426 | + Metadata::merge([ |
|
428 | 427 | $result->getMetadata(), |
429 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
430 | - ] ) |
|
428 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
429 | + ]) |
|
431 | 430 | ); |
432 | 431 | } |
433 | 432 | return $result; |
@@ -437,8 +436,8 @@ discard block |
||
437 | 436 | * @param CheckResult $result |
438 | 437 | * @return bool |
439 | 438 | */ |
440 | - private function isPossiblyStaleResult( CheckResult $result ) { |
|
441 | - if ( $result instanceof NullResult ) { |
|
439 | + private function isPossiblyStaleResult(CheckResult $result) { |
|
440 | + if ($result instanceof NullResult) { |
|
442 | 441 | return false; |
443 | 442 | } |
444 | 443 | |
@@ -453,14 +452,14 @@ discard block |
||
453 | 452 | * @return int[]|null array from entity ID serializations to revision ID, |
454 | 453 | * or null to indicate that not all revision IDs could be loaded |
455 | 454 | */ |
456 | - private function getLatestRevisionIds( array $entityIds ) { |
|
457 | - if ( $entityIds === [] ) { |
|
455 | + private function getLatestRevisionIds(array $entityIds) { |
|
456 | + if ($entityIds === []) { |
|
458 | 457 | $this->loggingHelper->logEmptyDependencyMetadata(); |
459 | 458 | return []; |
460 | 459 | } |
461 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
460 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
462 | 461 | // one of those entities will probably be edited soon, so might as well skip caching |
463 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
462 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
464 | 463 | return null; |
465 | 464 | } |
466 | 465 | |
@@ -468,7 +467,7 @@ discard block |
||
468 | 467 | $entityIds, |
469 | 468 | EntityRevisionLookup::LATEST_FROM_REPLICA |
470 | 469 | ); |
471 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
470 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
472 | 471 | return null; |
473 | 472 | } |
474 | 473 | return $latestRevisionIds; |
@@ -478,8 +477,8 @@ discard block |
||
478 | 477 | * @param array $array |
479 | 478 | * @return bool |
480 | 479 | */ |
481 | - private function hasFalseElements( array $array ) { |
|
482 | - return in_array( false, $array, true ); |
|
480 | + private function hasFalseElements(array $array) { |
|
481 | + return in_array(false, $array, true); |
|
483 | 482 | } |
484 | 483 | |
485 | 484 | /** |
@@ -487,7 +486,7 @@ discard block |
||
487 | 486 | * |
488 | 487 | * @param callable $microtime |
489 | 488 | */ |
490 | - public function setMicrotimeFunction( callable $microtime ) { |
|
489 | + public function setMicrotimeFunction(callable $microtime) { |
|
491 | 490 | $this->microtime = $microtime; |
492 | 491 | } |
493 | 492 |
@@ -15,10 +15,10 @@ discard block |
||
15 | 15 | use Wikibase\Repo\WikibaseRepo; |
16 | 16 | |
17 | 17 | // @codeCoverageIgnoreStart |
18 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
19 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
18 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
19 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
20 | 20 | |
21 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
21 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
22 | 22 | // @codeCoverageIgnoreEnd |
23 | 23 | |
24 | 24 | /** |
@@ -52,20 +52,20 @@ discard block |
||
52 | 52 | parent::__construct(); |
53 | 53 | |
54 | 54 | $this->addDescription( |
55 | - 'Import entities needed for constraint checks ' . |
|
55 | + 'Import entities needed for constraint checks '. |
|
56 | 56 | 'from Wikidata into the local repository.' |
57 | 57 | ); |
58 | 58 | $this->addOption( |
59 | 59 | 'config-format', |
60 | - 'The format in which the resulting configuration will be omitted: ' . |
|
61 | - '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' . |
|
60 | + 'The format in which the resulting configuration will be omitted: '. |
|
61 | + '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '. |
|
62 | 62 | 'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.' |
63 | 63 | ); |
64 | 64 | $this->addOption( |
65 | 65 | 'dry-run', |
66 | 66 | 'Don’t actually import entities, just print which ones would be imported.' |
67 | 67 | ); |
68 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
68 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | $this->entitySerializer = $repo->getAllTypesEntitySerializer(); |
77 | 77 | $this->entityDeserializer = $repo->getInternalFormatEntityDeserializer(); |
78 | 78 | $this->entityStore = $repo->getEntityStore(); |
79 | - if ( !$this->getOption( 'dry-run', false ) ) { |
|
80 | - $this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' ); |
|
79 | + if (!$this->getOption('dry-run', false)) { |
|
80 | + $this->user = User::newSystemUser('WikibaseQualityConstraints importer'); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
@@ -86,21 +86,21 @@ discard block |
||
86 | 86 | |
87 | 87 | $configUpdates = []; |
88 | 88 | |
89 | - $extensionJsonFile = __DIR__ . '/../extension.json'; |
|
90 | - $extensionJsonText = file_get_contents( $extensionJsonFile ); |
|
91 | - $extensionJson = json_decode( $extensionJsonText, /* assoc = */ true ); |
|
89 | + $extensionJsonFile = __DIR__.'/../extension.json'; |
|
90 | + $extensionJsonText = file_get_contents($extensionJsonFile); |
|
91 | + $extensionJson = json_decode($extensionJsonText, /* assoc = */ true); |
|
92 | 92 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
93 | - $wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() ); |
|
93 | + $wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig()); |
|
94 | 94 | |
95 | - foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) { |
|
96 | - $localEntityId = $this->importEntityFromWikidata( $wikidataEntityId ); |
|
95 | + foreach ($wikidataEntityIds as $key => $wikidataEntityId) { |
|
96 | + $localEntityId = $this->importEntityFromWikidata($wikidataEntityId); |
|
97 | 97 | $configUpdates[$key] = [ |
98 | 98 | 'wikidata' => $wikidataEntityId, |
99 | 99 | 'local' => $localEntityId, |
100 | 100 | ]; |
101 | 101 | } |
102 | 102 | |
103 | - $this->outputConfigUpdates( $configUpdates ); |
|
103 | + $this->outputConfigUpdates($configUpdates); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -108,18 +108,18 @@ discard block |
||
108 | 108 | * @param Config $wikiConfig |
109 | 109 | * @return string[] |
110 | 110 | */ |
111 | - private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) { |
|
111 | + private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) { |
|
112 | 112 | $wikidataEntityIds = []; |
113 | 113 | |
114 | - foreach ( $extensionJsonConfig as $key => $value ) { |
|
115 | - if ( !preg_match( '/Id$/', $key ) ) { |
|
114 | + foreach ($extensionJsonConfig as $key => $value) { |
|
115 | + if (!preg_match('/Id$/', $key)) { |
|
116 | 116 | continue; |
117 | 117 | } |
118 | 118 | |
119 | 119 | $wikidataEntityId = $value['value']; |
120 | - $localEntityId = $wikiConfig->get( $key ); |
|
120 | + $localEntityId = $wikiConfig->get($key); |
|
121 | 121 | |
122 | - if ( $localEntityId === $wikidataEntityId ) { |
|
122 | + if ($localEntityId === $wikidataEntityId) { |
|
123 | 123 | $wikidataEntityIds[$key] = $wikidataEntityId; |
124 | 124 | } |
125 | 125 | } |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | * @param string $wikidataEntityId |
132 | 132 | * @return string local entity ID |
133 | 133 | */ |
134 | - private function importEntityFromWikidata( $wikidataEntityId ) { |
|
134 | + private function importEntityFromWikidata($wikidataEntityId) { |
|
135 | 135 | $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json"; |
136 | - $wikidataEntitiesJson = file_get_contents( $wikidataEntityUrl ); |
|
137 | - return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ); |
|
136 | + $wikidataEntitiesJson = file_get_contents($wikidataEntityUrl); |
|
137 | + return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,24 +142,24 @@ discard block |
||
142 | 142 | * @param string $wikidataEntitiesJson |
143 | 143 | * @return string local entity ID |
144 | 144 | */ |
145 | - private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) { |
|
145 | + private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) { |
|
146 | 146 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
147 | - $wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId]; |
|
148 | - $wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray ); |
|
147 | + $wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId]; |
|
148 | + $wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray); |
|
149 | 149 | |
150 | - $wikidataEntity->setId( null ); |
|
150 | + $wikidataEntity->setId(null); |
|
151 | 151 | |
152 | - if ( $wikidataEntity instanceof StatementListProvider ) { |
|
152 | + if ($wikidataEntity instanceof StatementListProvider) { |
|
153 | 153 | $wikidataEntity->getStatements()->clear(); |
154 | 154 | } |
155 | 155 | |
156 | - if ( $wikidataEntity instanceof Item ) { |
|
157 | - $wikidataEntity->setSiteLinkList( new SiteLinkList() ); |
|
156 | + if ($wikidataEntity instanceof Item) { |
|
157 | + $wikidataEntity->setSiteLinkList(new SiteLinkList()); |
|
158 | 158 | } |
159 | 159 | |
160 | - if ( $this->getOption( 'dry-run', false ) ) { |
|
161 | - $wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) ); |
|
162 | - $this->output( $wikidataEntityJson . "\n" ); |
|
160 | + if ($this->getOption('dry-run', false)) { |
|
161 | + $wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity)); |
|
162 | + $this->output($wikidataEntityJson."\n"); |
|
163 | 163 | return "-$wikidataEntityId"; |
164 | 164 | } |
165 | 165 | |
@@ -172,12 +172,12 @@ discard block |
||
172 | 172 | )->getEntity(); |
173 | 173 | |
174 | 174 | return $localEntity->getId()->getSerialization(); |
175 | - } catch ( StorageException $storageException ) { |
|
176 | - return $this->storageExceptionToEntityId( $storageException ); |
|
175 | + } catch (StorageException $storageException) { |
|
176 | + return $this->storageExceptionToEntityId($storageException); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | - private function storageExceptionToEntityId( StorageException $storageException ) { |
|
180 | + private function storageExceptionToEntityId(StorageException $storageException) { |
|
181 | 181 | $message = $storageException->getMessage(); |
182 | 182 | // example messages: |
183 | 183 | // * Item [[Item:Q475|Q475]] already has label "as references" |
@@ -187,25 +187,25 @@ discard block |
||
187 | 187 | // * Property [[Property:P694|P694]] already has label "instance of" |
188 | 188 | // associated with language code en. |
189 | 189 | $pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/'; |
190 | - if ( preg_match( $pattern, $message, $matches ) ) { |
|
190 | + if (preg_match($pattern, $message, $matches)) { |
|
191 | 191 | return $matches[1]; |
192 | 192 | } else { |
193 | 193 | throw $storageException; |
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | - private function outputConfigUpdates( array $configUpdates ) { |
|
198 | - $configFormat = $this->getOption( 'config-format', 'globals' ); |
|
199 | - switch ( $configFormat ) { |
|
197 | + private function outputConfigUpdates(array $configUpdates) { |
|
198 | + $configFormat = $this->getOption('config-format', 'globals'); |
|
199 | + switch ($configFormat) { |
|
200 | 200 | case 'globals': |
201 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
201 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
202 | 202 | break; |
203 | 203 | case 'wgConf': |
204 | - $this->outputConfigUpdatesWgConf( $configUpdates ); |
|
204 | + $this->outputConfigUpdatesWgConf($configUpdates); |
|
205 | 205 | break; |
206 | 206 | default: |
207 | - $this->error( "Invalid config format \"$configFormat\", using \"globals\"" ); |
|
208 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
207 | + $this->error("Invalid config format \"$configFormat\", using \"globals\""); |
|
208 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
209 | 209 | break; |
210 | 210 | } |
211 | 211 | } |
@@ -213,22 +213,22 @@ discard block |
||
213 | 213 | /** |
214 | 214 | * @param array[] $configUpdates |
215 | 215 | */ |
216 | - private function outputConfigUpdatesGlobals( array $configUpdates ) { |
|
217 | - foreach ( $configUpdates as $key => $value ) { |
|
218 | - $localValueCode = var_export( $value['local'], true ); |
|
219 | - $this->output( "\$wg$key = $localValueCode;\n" ); |
|
216 | + private function outputConfigUpdatesGlobals(array $configUpdates) { |
|
217 | + foreach ($configUpdates as $key => $value) { |
|
218 | + $localValueCode = var_export($value['local'], true); |
|
219 | + $this->output("\$wg$key = $localValueCode;\n"); |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | 224 | * @param array[] $configUpdates |
225 | 225 | */ |
226 | - private function outputConfigUpdatesWgConf( array $configUpdates ) { |
|
227 | - foreach ( $configUpdates as $key => $value ) { |
|
228 | - $keyCode = var_export( "wg$key", true ); |
|
229 | - $wikidataValueCode = var_export( $value['wikidata'], true ); |
|
230 | - $localValueCode = var_export( $value['local'], true ); |
|
231 | - $wikiIdCode = var_export( wfWikiID(), true ); |
|
226 | + private function outputConfigUpdatesWgConf(array $configUpdates) { |
|
227 | + foreach ($configUpdates as $key => $value) { |
|
228 | + $keyCode = var_export("wg$key", true); |
|
229 | + $wikidataValueCode = var_export($value['wikidata'], true); |
|
230 | + $localValueCode = var_export($value['local'], true); |
|
231 | + $wikiIdCode = var_export(wfWikiID(), true); |
|
232 | 232 | $block = <<< EOF |
233 | 233 | $keyCode => [ |
234 | 234 | 'default' => $wikidataValueCode, |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | |
238 | 238 | |
239 | 239 | EOF; |
240 | - $this->output( $block ); |
|
240 | + $this->output($block); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param ItemId $itemId |
45 | 45 | * @return self |
46 | 46 | */ |
47 | - public static function fromItemId( ItemId $itemId ) { |
|
47 | + public static function fromItemId(ItemId $itemId) { |
|
48 | 48 | $ret = new self; |
49 | 49 | $ret->itemId = $itemId; |
50 | 50 | return $ret; |
@@ -80,14 +80,14 @@ discard block |
||
80 | 80 | * @throws InvalidArgumentException |
81 | 81 | * @return self |
82 | 82 | */ |
83 | - public static function fromSnak( Snak $snak ) { |
|
84 | - switch ( true ) { |
|
83 | + public static function fromSnak(Snak $snak) { |
|
84 | + switch (true) { |
|
85 | 85 | case $snak instanceof PropertyValueSnak: |
86 | 86 | $dataValue = $snak->getDataValue(); |
87 | - if ( $dataValue instanceof EntityIdValue ) { |
|
87 | + if ($dataValue instanceof EntityIdValue) { |
|
88 | 88 | $itemId = $dataValue->getEntityId(); |
89 | - if ( $itemId instanceof ItemId ) { |
|
90 | - return self::fromItemId( $itemId ); |
|
89 | + if ($itemId instanceof ItemId) { |
|
90 | + return self::fromItemId($itemId); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | break; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | return self::noValue(); |
98 | 98 | } |
99 | 99 | |
100 | - throw new InvalidArgumentException( 'Snak must contain item ID value or be a somevalue / novalue snak' ); |
|
100 | + throw new InvalidArgumentException('Snak must contain item ID value or be a somevalue / novalue snak'); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | * @return ItemId |
136 | 136 | */ |
137 | 137 | public function getItemId() { |
138 | - if ( !$this->isValue() ) { |
|
139 | - throw new DomainException( 'This value does not contain an item ID.' ); |
|
138 | + if (!$this->isValue()) { |
|
139 | + throw new DomainException('This value does not contain an item ID.'); |
|
140 | 140 | } |
141 | 141 | return $this->itemId; |
142 | 142 | } |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | * @param Snak $snak |
149 | 149 | * @return bool |
150 | 150 | */ |
151 | - public function matchesSnak( Snak $snak ) { |
|
152 | - switch ( true ) { |
|
151 | + public function matchesSnak(Snak $snak) { |
|
152 | + switch (true) { |
|
153 | 153 | case $snak instanceof PropertyValueSnak: |
154 | 154 | $dataValue = $snak->getDataValue(); |
155 | 155 | return $this->isValue() && |
156 | 156 | $dataValue instanceof EntityIdValue && |
157 | 157 | $dataValue->getEntityId() instanceof ItemId && |
158 | - $dataValue->getEntityId()->equals( $this->getItemId() ); |
|
158 | + $dataValue->getEntityId()->equals($this->getItemId()); |
|
159 | 159 | case $snak instanceof PropertySomeValueSnak: |
160 | 160 | return $this->isSomeValue(); |
161 | 161 | case $snak instanceof PropertyNoValueSnak: |
@@ -37,25 +37,25 @@ discard block |
||
37 | 37 | * @param Title $title |
38 | 38 | * @param string[] $params should contain 'entityId' => 'Q1234' |
39 | 39 | */ |
40 | - public function __construct( Title $title, array $params ) { |
|
41 | - parent::__construct( self::COMMAND, $title, $params ); |
|
40 | + public function __construct(Title $title, array $params) { |
|
41 | + parent::__construct(self::COMMAND, $title, $params); |
|
42 | 42 | $this->removeDuplicates = true; |
43 | 43 | |
44 | - Assert::parameterType( 'string', $params['entityId'], '$params[\'entityId\']' ); |
|
44 | + Assert::parameterType('string', $params['entityId'], '$params[\'entityId\']'); |
|
45 | 45 | |
46 | - $resultSource = ConstraintsServices::getResultsSource( MediaWikiServices::getInstance() ); |
|
46 | + $resultSource = ConstraintsServices::getResultsSource(MediaWikiServices::getInstance()); |
|
47 | 47 | '@phan-var CachingResultsSource $resultSource'; |
48 | 48 | // This job should only ever be used when caching result sources are used. |
49 | - $this->setResultsSource( $resultSource ); |
|
49 | + $this->setResultsSource($resultSource); |
|
50 | 50 | |
51 | - $this->setEntityIdParser( WikibaseRepo::getDefaultInstance()->getEntityIdParser() ); |
|
51 | + $this->setEntityIdParser(WikibaseRepo::getDefaultInstance()->getEntityIdParser()); |
|
52 | 52 | } |
53 | 53 | |
54 | - public function setResultsSource( CachingResultsSource $resultsSource ) { |
|
54 | + public function setResultsSource(CachingResultsSource $resultsSource) { |
|
55 | 55 | $this->resultsSource = $resultsSource; |
56 | 56 | } |
57 | 57 | |
58 | - public function setEntityIdParser( EntityIdParser $parser ) { |
|
58 | + public function setEntityIdParser(EntityIdParser $parser) { |
|
59 | 59 | $this->entityIdParser = $parser; |
60 | 60 | } |
61 | 61 | |
@@ -66,19 +66,19 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function run() { |
68 | 68 | try { |
69 | - $entityId = $this->entityIdParser->parse( $this->params['entityId'] ); |
|
70 | - } catch ( EntityIdParsingException $e ) { |
|
69 | + $entityId = $this->entityIdParser->parse($this->params['entityId']); |
|
70 | + } catch (EntityIdParsingException $e) { |
|
71 | 71 | return false; |
72 | 72 | } |
73 | 73 | |
74 | - $this->checkConstraints( $entityId ); |
|
74 | + $this->checkConstraints($entityId); |
|
75 | 75 | |
76 | 76 | return true; |
77 | 77 | } |
78 | 78 | |
79 | - private function checkConstraints( EntityId $entityId ) { |
|
79 | + private function checkConstraints(EntityId $entityId) { |
|
80 | 80 | $this->resultsSource->getResults( |
81 | - [ $entityId ], |
|
81 | + [$entityId], |
|
82 | 82 | [], |
83 | 83 | null, |
84 | 84 | [] |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | |
29 | 29 | const BATCH_SIZE = 10; |
30 | 30 | |
31 | - public static function newFromGlobalState( Title $title, array $params ) { |
|
32 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
31 | + public static function newFromGlobalState(Title $title, array $params) { |
|
32 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
33 | 33 | $repo = WikibaseRepo::getDefaultInstance(); |
34 | 34 | return new UpdateConstraintsTableJob( |
35 | 35 | $title, |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $params['revisionId'] ?? null, |
39 | 39 | MediaWikiServices::getInstance()->getMainConfig(), |
40 | 40 | ConstraintsServices::getConstraintRepository(), |
41 | - $repo->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ), |
|
41 | + $repo->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED), |
|
42 | 42 | $repo->getBaseDataModelSerializerFactory()->newSnakSerializer() |
43 | 43 | ); |
44 | 44 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | EntityRevisionLookup $entityRevisionLookup, |
94 | 94 | Serializer $snakSerializer |
95 | 95 | ) { |
96 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
96 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
97 | 97 | |
98 | 98 | $this->propertyId = $propertyId; |
99 | 99 | $this->revisionId = $revisionId; |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | $this->snakSerializer = $snakSerializer; |
104 | 104 | } |
105 | 105 | |
106 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
106 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
107 | 107 | $parameters = []; |
108 | - foreach ( $qualifiers as $qualifier ) { |
|
108 | + foreach ($qualifiers as $qualifier) { |
|
109 | 109 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
110 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
110 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
111 | 111 | $parameters[$qualifierId][] = $paramSerialization; |
112 | 112 | } |
113 | 113 | return $parameters; |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | '@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue'; |
125 | 125 | $entityId = $dataValue->getEntityId(); |
126 | 126 | $constraintTypeQid = $entityId->getSerialization(); |
127 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
127 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
128 | 128 | return new Constraint( |
129 | 129 | $constraintId, |
130 | 130 | $propertyId, |
@@ -139,17 +139,17 @@ discard block |
||
139 | 139 | PropertyId $propertyConstraintPropertyId |
140 | 140 | ) { |
141 | 141 | $constraintsStatements = $property->getStatements() |
142 | - ->getByPropertyId( $propertyConstraintPropertyId ) |
|
143 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
142 | + ->getByPropertyId($propertyConstraintPropertyId) |
|
143 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
144 | 144 | $constraints = []; |
145 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
146 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
147 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
148 | - $constraintRepo->insertBatch( $constraints ); |
|
145 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
146 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
147 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
148 | + $constraintRepo->insertBatch($constraints); |
|
149 | 149 | $constraints = []; |
150 | 150 | } |
151 | 151 | } |
152 | - $constraintRepo->insertBatch( $constraints ); |
|
152 | + $constraintRepo->insertBatch($constraints); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -160,19 +160,19 @@ discard block |
||
160 | 160 | public function run() { |
161 | 161 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
162 | 162 | |
163 | - $propertyId = new PropertyId( $this->propertyId ); |
|
163 | + $propertyId = new PropertyId($this->propertyId); |
|
164 | 164 | $propertyRevision = $this->entityRevisionLookup->getEntityRevision( |
165 | 165 | $propertyId, |
166 | 166 | 0, // latest |
167 | 167 | EntityRevisionLookup::LATEST_FROM_REPLICA |
168 | 168 | ); |
169 | 169 | |
170 | - if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) { |
|
171 | - JobQueueGroup::singleton()->push( $this ); |
|
170 | + if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) { |
|
171 | + JobQueueGroup::singleton()->push($this); |
|
172 | 172 | return true; |
173 | 173 | } |
174 | 174 | |
175 | - $this->constraintRepo->deleteForProperty( $propertyId ); |
|
175 | + $this->constraintRepo->deleteForProperty($propertyId); |
|
176 | 176 | |
177 | 177 | /** @var Property $property */ |
178 | 178 | $property = $propertyRevision->getEntity(); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | $this->importConstraintsForProperty( |
181 | 181 | $property, |
182 | 182 | $this->constraintRepo, |
183 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
183 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
184 | 184 | ); |
185 | 185 | |
186 | 186 | return true; |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | EntityIdLookup $entityIdLookup, |
40 | 40 | RdfVocabulary $rdfVocabulary |
41 | 41 | ) { |
42 | - parent::__construct( $page, $context ); |
|
42 | + parent::__construct($page, $context); |
|
43 | 43 | $this->resultsSource = $resultsSource; |
44 | 44 | $this->entityIdLookup = $entityIdLookup; |
45 | 45 | $this->rdfVocabulary = $rdfVocabulary; |
46 | 46 | } |
47 | 47 | |
48 | - public static function newFromGlobalState( Page $page, IContextSource $context ) { |
|
48 | + public static function newFromGlobalState(Page $page, IContextSource $context) { |
|
49 | 49 | $repo = WikibaseRepo::getDefaultInstance(); |
50 | 50 | |
51 | 51 | return new static( |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | * @param string $guid |
93 | 93 | * @return string |
94 | 94 | */ |
95 | - private function cleanupGuid( $guid ) { |
|
96 | - return preg_replace( '/[^\w-]/', '-', $guid ); |
|
95 | + private function cleanupGuid($guid) { |
|
96 | + return preg_replace('/[^\w-]/', '-', $guid); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -105,60 +105,60 @@ discard block |
||
105 | 105 | $response = $this->getRequest()->response(); |
106 | 106 | $this->getOutput()->disable(); |
107 | 107 | |
108 | - if ( !$this->resultsSource instanceof CachingResultsSource ) { |
|
108 | + if (!$this->resultsSource instanceof CachingResultsSource) { |
|
109 | 109 | // TODO: make configurable whether only cached results are returned |
110 | - $response->statusHeader( 501 ); // Not Implemented |
|
110 | + $response->statusHeader(501); // Not Implemented |
|
111 | 111 | return null; |
112 | 112 | } |
113 | 113 | |
114 | - $entityId = $this->entityIdLookup->getEntityIdForTitle( $this->getTitle() ); |
|
115 | - if ( $entityId === null ) { |
|
116 | - $response->statusHeader( 404 ); // Not Found |
|
114 | + $entityId = $this->entityIdLookup->getEntityIdForTitle($this->getTitle()); |
|
115 | + if ($entityId === null) { |
|
116 | + $response->statusHeader(404); // Not Found |
|
117 | 117 | return null; |
118 | 118 | } |
119 | - $revId = $this->getRequest()->getInt( 'revision' ); |
|
119 | + $revId = $this->getRequest()->getInt('revision'); |
|
120 | 120 | |
121 | - $results = $this->resultsSource->getStoredResults( $entityId, $revId ); |
|
122 | - if ( $results === null ) { |
|
123 | - $response->statusHeader( 204 ); // No Content |
|
121 | + $results = $this->resultsSource->getStoredResults($entityId, $revId); |
|
122 | + if ($results === null) { |
|
123 | + $response->statusHeader(204); // No Content |
|
124 | 124 | return null; |
125 | 125 | } |
126 | 126 | |
127 | 127 | $format = 'ttl'; // TODO: make format an option |
128 | 128 | |
129 | 129 | $writerFactory = new RdfWriterFactory(); |
130 | - $formatName = $writerFactory->getFormatName( $format ); |
|
131 | - $contentType = $writerFactory->getMimeTypes( $formatName )[0]; |
|
130 | + $formatName = $writerFactory->getFormatName($format); |
|
131 | + $contentType = $writerFactory->getMimeTypes($formatName)[0]; |
|
132 | 132 | |
133 | - $writer = $writerFactory->getWriter( $formatName ); |
|
134 | - foreach ( [ RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY ] as $ns ) { |
|
135 | - $writer->prefix( $ns, $this->rdfVocabulary->getNamespaceURI( $ns ) ); |
|
133 | + $writer = $writerFactory->getWriter($formatName); |
|
134 | + foreach ([RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY] as $ns) { |
|
135 | + $writer->prefix($ns, $this->rdfVocabulary->getNamespaceURI($ns)); |
|
136 | 136 | } |
137 | 137 | $writer->start(); |
138 | 138 | $writtenAny = false; |
139 | 139 | |
140 | - foreach ( $results->getArray() as $checkResult ) { |
|
141 | - if ( $checkResult instanceof NullResult ) { |
|
140 | + foreach ($results->getArray() as $checkResult) { |
|
141 | + if ($checkResult instanceof NullResult) { |
|
142 | 142 | continue; |
143 | 143 | } |
144 | - if ( $checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS ) { |
|
144 | + if ($checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS) { |
|
145 | 145 | continue; |
146 | 146 | } |
147 | 147 | $writtenAny = true; |
148 | - $writer->about( RdfVocabulary::NS_STATEMENT, |
|
149 | - $this->cleanupGuid( $checkResult->getContextCursor()->getStatementGuid() ) ) |
|
150 | - ->say( RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint' ) |
|
151 | - ->is( RdfVocabulary::NS_STATEMENT, |
|
152 | - $this->cleanupGuid( $checkResult->getConstraint()->getConstraintId() ) ); |
|
148 | + $writer->about(RdfVocabulary::NS_STATEMENT, |
|
149 | + $this->cleanupGuid($checkResult->getContextCursor()->getStatementGuid())) |
|
150 | + ->say(RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint') |
|
151 | + ->is(RdfVocabulary::NS_STATEMENT, |
|
152 | + $this->cleanupGuid($checkResult->getConstraint()->getConstraintId())); |
|
153 | 153 | } |
154 | 154 | $writer->finish(); |
155 | - if ( $writtenAny ) { |
|
156 | - $response->header( "Content-Type: $contentType; charset=UTF-8" ); |
|
155 | + if ($writtenAny) { |
|
156 | + $response->header("Content-Type: $contentType; charset=UTF-8"); |
|
157 | 157 | echo $writer->drain(); |
158 | 158 | } else { |
159 | 159 | // Do not output RDF if we haven't written any actual statements. Output 204 instead |
160 | 160 | $writer->drain(); |
161 | - $response->statusHeader( 204 ); // No Content |
|
161 | + $response->statusHeader(204); // No Content |
|
162 | 162 | } |
163 | 163 | return null; |
164 | 164 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** @var string|false */ |
22 | 22 | private $dbName; |
23 | 23 | |
24 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
24 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
25 | 25 | $this->lb = $lb; |
26 | 26 | $this->dbName = $dbName; |
27 | 27 | } |
@@ -31,27 +31,27 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @return Constraint[] |
33 | 33 | */ |
34 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
35 | - $dbr = $this->lb->getConnection( ILoadBalancer::DB_REPLICA, [], $this->dbName ); |
|
34 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
35 | + $dbr = $this->lb->getConnection(ILoadBalancer::DB_REPLICA, [], $this->dbName); |
|
36 | 36 | |
37 | 37 | $results = $dbr->select( |
38 | 38 | 'wbqc_constraints', |
39 | 39 | '*', |
40 | - [ 'pid' => $propertyId->getNumericId() ] |
|
40 | + ['pid' => $propertyId->getNumericId()] |
|
41 | 41 | ); |
42 | 42 | |
43 | - if ( $this->dbName !== false ) { |
|
44 | - $this->lb->reuseConnection( $dbr ); |
|
43 | + if ($this->dbName !== false) { |
|
44 | + $this->lb->reuseConnection($dbr); |
|
45 | 45 | } |
46 | 46 | |
47 | - return $this->convertToConstraints( $results ); |
|
47 | + return $this->convertToConstraints($results); |
|
48 | 48 | } |
49 | 49 | |
50 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
51 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
50 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
51 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
52 | 52 | |
53 | - if ( strlen( $json ) > 50000 ) { |
|
54 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
53 | + if (strlen($json) > 50000) { |
|
54 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | return $json; |
@@ -63,25 +63,25 @@ discard block |
||
63 | 63 | * @throws DBUnexpectedError |
64 | 64 | * @return bool |
65 | 65 | */ |
66 | - public function insertBatch( array $constraints ) { |
|
67 | - if ( $this->dbName !== false ) { |
|
68 | - throw new LogicException( __METHOD__ . ' should not be called when constraints defined in non-local database.' ); |
|
66 | + public function insertBatch(array $constraints) { |
|
67 | + if ($this->dbName !== false) { |
|
68 | + throw new LogicException(__METHOD__.' should not be called when constraints defined in non-local database.'); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $accumulator = array_map( |
72 | - function ( Constraint $constraint ) { |
|
72 | + function(Constraint $constraint) { |
|
73 | 73 | return [ |
74 | 74 | 'constraint_guid' => $constraint->getConstraintId(), |
75 | 75 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
76 | 76 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
77 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
77 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
78 | 78 | ]; |
79 | 79 | }, |
80 | 80 | $constraints |
81 | 81 | ); |
82 | 82 | |
83 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_MASTER ); |
|
84 | - return $dbw->insert( 'wbqc_constraints', $accumulator ); |
|
83 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_MASTER); |
|
84 | + return $dbw->insert('wbqc_constraints', $accumulator); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @throws DBUnexpectedError |
93 | 93 | */ |
94 | - public function deleteForProperty( PropertyId $propertyId ) { |
|
95 | - if ( $this->dbName !== false ) { |
|
96 | - throw new LogicException( __METHOD__ . ' should not be called when constraints defined in non-local database.' ); |
|
94 | + public function deleteForProperty(PropertyId $propertyId) { |
|
95 | + if ($this->dbName !== false) { |
|
96 | + throw new LogicException(__METHOD__.' should not be called when constraints defined in non-local database.'); |
|
97 | 97 | } |
98 | 98 | |
99 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_MASTER ); |
|
99 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_MASTER); |
|
100 | 100 | $dbw->delete( |
101 | 101 | 'wbqc_constraints', |
102 | 102 | [ |
@@ -110,26 +110,26 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return Constraint[] |
112 | 112 | */ |
113 | - private function convertToConstraints( IResultWrapper $results ) { |
|
113 | + private function convertToConstraints(IResultWrapper $results) { |
|
114 | 114 | $constraints = []; |
115 | - foreach ( $results as $result ) { |
|
115 | + foreach ($results as $result) { |
|
116 | 116 | $constraintTypeItemId = $result->constraint_type_qid; |
117 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
117 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
118 | 118 | |
119 | - if ( $constraintParameters === null ) { |
|
119 | + if ($constraintParameters === null) { |
|
120 | 120 | // T171295 |
121 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ) |
|
122 | - ->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
121 | + LoggerFactory::getInstance('WikibaseQualityConstraints') |
|
122 | + ->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
123 | 123 | 'method' => __METHOD__, |
124 | 124 | 'constraintId' => $result->constraint_guid, |
125 | 125 | 'constraintParameters' => $result->constraint_parameters, |
126 | - ] ); |
|
127 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
126 | + ]); |
|
127 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | $constraints[] = new Constraint( |
131 | 131 | $result->constraint_guid, |
132 | - PropertyId::newFromNumber( $result->pid ), |
|
132 | + PropertyId::newFromNumber($result->pid), |
|
133 | 133 | $constraintTypeItemId, |
134 | 134 | $constraintParameters |
135 | 135 | ); |