@@ -37,199 +37,199 @@ |
||
37 | 37 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker; |
38 | 38 | |
39 | 39 | return [ |
40 | - ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function ( MediaWikiServices $services ) { |
|
40 | + ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function(MediaWikiServices $services) { |
|
41 | 41 | return new ConflictsWithChecker( |
42 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
43 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
42 | + ConstraintsServices::getConstraintParameterParser($services), |
|
43 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
44 | 44 | ); |
45 | 45 | }, |
46 | 46 | |
47 | - ConstraintCheckerServices::ITEM_CHECKER => static function ( MediaWikiServices $services ) { |
|
47 | + ConstraintCheckerServices::ITEM_CHECKER => static function(MediaWikiServices $services) { |
|
48 | 48 | return new ItemChecker( |
49 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
50 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
49 | + ConstraintsServices::getConstraintParameterParser($services), |
|
50 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
51 | 51 | ); |
52 | 52 | }, |
53 | 53 | |
54 | - ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function ( MediaWikiServices $services ) { |
|
54 | + ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function(MediaWikiServices $services) { |
|
55 | 55 | return new TargetRequiredClaimChecker( |
56 | - WikibaseServices::getEntityLookup( $services ), |
|
57 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
58 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
56 | + WikibaseServices::getEntityLookup($services), |
|
57 | + ConstraintsServices::getConstraintParameterParser($services), |
|
58 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
59 | 59 | ); |
60 | 60 | }, |
61 | 61 | |
62 | - ConstraintCheckerServices::SYMMETRIC_CHECKER => static function ( MediaWikiServices $services ) { |
|
62 | + ConstraintCheckerServices::SYMMETRIC_CHECKER => static function(MediaWikiServices $services) { |
|
63 | 63 | return new SymmetricChecker( |
64 | - WikibaseServices::getEntityLookupWithoutCache( $services ), |
|
65 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
64 | + WikibaseServices::getEntityLookupWithoutCache($services), |
|
65 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
66 | 66 | ); |
67 | 67 | }, |
68 | 68 | |
69 | - ConstraintCheckerServices::INVERSE_CHECKER => static function ( MediaWikiServices $services ) { |
|
69 | + ConstraintCheckerServices::INVERSE_CHECKER => static function(MediaWikiServices $services) { |
|
70 | 70 | return new InverseChecker( |
71 | - WikibaseServices::getEntityLookup( $services ), |
|
72 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
73 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
71 | + WikibaseServices::getEntityLookup($services), |
|
72 | + ConstraintsServices::getConstraintParameterParser($services), |
|
73 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
74 | 74 | ); |
75 | 75 | }, |
76 | 76 | |
77 | - ConstraintCheckerServices::QUALIFIER_CHECKER => static function ( MediaWikiServices $services ) { |
|
77 | + ConstraintCheckerServices::QUALIFIER_CHECKER => static function(MediaWikiServices $services) { |
|
78 | 78 | return new QualifierChecker(); |
79 | 79 | }, |
80 | 80 | |
81 | - ConstraintCheckerServices::QUALIFIERS_CHECKER => static function ( MediaWikiServices $services ) { |
|
81 | + ConstraintCheckerServices::QUALIFIERS_CHECKER => static function(MediaWikiServices $services) { |
|
82 | 82 | return new QualifiersChecker( |
83 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
83 | + ConstraintsServices::getConstraintParameterParser($services) |
|
84 | 84 | ); |
85 | 85 | }, |
86 | 86 | |
87 | - ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function ( MediaWikiServices $services ) { |
|
87 | + ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function(MediaWikiServices $services) { |
|
88 | 88 | return new MandatoryQualifiersChecker( |
89 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
89 | + ConstraintsServices::getConstraintParameterParser($services) |
|
90 | 90 | ); |
91 | 91 | }, |
92 | 92 | |
93 | - ConstraintCheckerServices::RANGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
93 | + ConstraintCheckerServices::RANGE_CHECKER => static function(MediaWikiServices $services) { |
|
94 | 94 | return new RangeChecker( |
95 | - WikibaseServices::getPropertyDataTypeLookup( $services ), |
|
96 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
97 | - ConstraintsServices::getRangeCheckerHelper( $services ) |
|
95 | + WikibaseServices::getPropertyDataTypeLookup($services), |
|
96 | + ConstraintsServices::getConstraintParameterParser($services), |
|
97 | + ConstraintsServices::getRangeCheckerHelper($services) |
|
98 | 98 | ); |
99 | 99 | }, |
100 | 100 | |
101 | - ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
101 | + ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function(MediaWikiServices $services) { |
|
102 | 102 | return new DiffWithinRangeChecker( |
103 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
104 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
103 | + ConstraintsServices::getConstraintParameterParser($services), |
|
104 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
105 | 105 | $services->getMainConfig() |
106 | 106 | ); |
107 | 107 | }, |
108 | 108 | |
109 | - ConstraintCheckerServices::TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
109 | + ConstraintCheckerServices::TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
110 | 110 | return new TypeChecker( |
111 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
112 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
111 | + ConstraintsServices::getConstraintParameterParser($services), |
|
112 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
113 | 113 | $services->getMainConfig() |
114 | 114 | ); |
115 | 115 | }, |
116 | 116 | |
117 | - ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
117 | + ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
118 | 118 | return new ValueTypeChecker( |
119 | - WikibaseServices::getEntityLookup( $services ), |
|
120 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
121 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
119 | + WikibaseServices::getEntityLookup($services), |
|
120 | + ConstraintsServices::getConstraintParameterParser($services), |
|
121 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
122 | 122 | $services->getMainConfig() |
123 | 123 | ); |
124 | 124 | }, |
125 | 125 | |
126 | - ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
126 | + ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
127 | 127 | return new SingleValueChecker( |
128 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
128 | + ConstraintsServices::getConstraintParameterParser($services) |
|
129 | 129 | ); |
130 | 130 | }, |
131 | 131 | |
132 | - ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
132 | + ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
133 | 133 | return new MultiValueChecker( |
134 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
134 | + ConstraintsServices::getConstraintParameterParser($services) |
|
135 | 135 | ); |
136 | 136 | }, |
137 | 137 | |
138 | - ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
138 | + ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
139 | 139 | // TODO return a different, dummy implementation if SPARQL is not available |
140 | 140 | return new UniqueValueChecker( |
141 | - ConstraintsServices::getSparqlHelper( $services ) |
|
141 | + ConstraintsServices::getSparqlHelper($services) |
|
142 | 142 | ); |
143 | 143 | }, |
144 | 144 | |
145 | - ConstraintCheckerServices::FORMAT_CHECKER => static function ( MediaWikiServices $services ) { |
|
145 | + ConstraintCheckerServices::FORMAT_CHECKER => static function(MediaWikiServices $services) { |
|
146 | 146 | // TODO return a different, dummy implementation if SPARQL is not available |
147 | 147 | return new FormatChecker( |
148 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
148 | + ConstraintsServices::getConstraintParameterParser($services), |
|
149 | 149 | $services->getMainConfig(), |
150 | - ConstraintsServices::getSparqlHelper( $services ), |
|
150 | + ConstraintsServices::getSparqlHelper($services), |
|
151 | 151 | $services->getShellboxClientFactory() |
152 | 152 | ); |
153 | 153 | }, |
154 | 154 | |
155 | - ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function ( MediaWikiServices $services ) { |
|
155 | + ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function(MediaWikiServices $services) { |
|
156 | 156 | $pageNameNormalizer = new MediaWikiPageNameNormalizer(); |
157 | 157 | return new CommonsLinkChecker( |
158 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
158 | + ConstraintsServices::getConstraintParameterParser($services), |
|
159 | 159 | $pageNameNormalizer, |
160 | - WikibaseRepo::getPropertyDataTypeLookup( $services ) |
|
160 | + WikibaseRepo::getPropertyDataTypeLookup($services) |
|
161 | 161 | ); |
162 | 162 | }, |
163 | 163 | |
164 | - ConstraintCheckerServices::ONE_OF_CHECKER => static function ( MediaWikiServices $services ) { |
|
164 | + ConstraintCheckerServices::ONE_OF_CHECKER => static function(MediaWikiServices $services) { |
|
165 | 165 | return new OneOfChecker( |
166 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
166 | + ConstraintsServices::getConstraintParameterParser($services) |
|
167 | 167 | ); |
168 | 168 | }, |
169 | 169 | |
170 | - ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function ( MediaWikiServices $services ) { |
|
170 | + ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function(MediaWikiServices $services) { |
|
171 | 171 | return new ValueOnlyChecker(); |
172 | 172 | }, |
173 | 173 | |
174 | - ConstraintCheckerServices::REFERENCE_CHECKER => static function ( MediaWikiServices $services ) { |
|
174 | + ConstraintCheckerServices::REFERENCE_CHECKER => static function(MediaWikiServices $services) { |
|
175 | 175 | return new ReferenceChecker(); |
176 | 176 | }, |
177 | 177 | |
178 | - ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function ( MediaWikiServices $services ) { |
|
178 | + ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function(MediaWikiServices $services) { |
|
179 | 179 | return new NoBoundsChecker(); |
180 | 180 | }, |
181 | 181 | |
182 | - ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function ( MediaWikiServices $services ) { |
|
182 | + ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function(MediaWikiServices $services) { |
|
183 | 183 | return new AllowedUnitsChecker( |
184 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
185 | - WikibaseRepo::getUnitConverter( $services ) |
|
184 | + ConstraintsServices::getConstraintParameterParser($services), |
|
185 | + WikibaseRepo::getUnitConverter($services) |
|
186 | 186 | ); |
187 | 187 | }, |
188 | 188 | |
189 | - ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
189 | + ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
190 | 190 | return new SingleBestValueChecker( |
191 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
191 | + ConstraintsServices::getConstraintParameterParser($services) |
|
192 | 192 | ); |
193 | 193 | }, |
194 | 194 | |
195 | - ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
195 | + ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
196 | 196 | return new EntityTypeChecker( |
197 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
197 | + ConstraintsServices::getConstraintParameterParser($services) |
|
198 | 198 | ); |
199 | 199 | }, |
200 | 200 | |
201 | - ConstraintCheckerServices::NONE_OF_CHECKER => static function ( MediaWikiServices $services ) { |
|
201 | + ConstraintCheckerServices::NONE_OF_CHECKER => static function(MediaWikiServices $services) { |
|
202 | 202 | return new NoneOfChecker( |
203 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
203 | + ConstraintsServices::getConstraintParameterParser($services) |
|
204 | 204 | ); |
205 | 205 | }, |
206 | 206 | |
207 | - ConstraintCheckerServices::INTEGER_CHECKER => static function ( MediaWikiServices $services ) { |
|
207 | + ConstraintCheckerServices::INTEGER_CHECKER => static function(MediaWikiServices $services) { |
|
208 | 208 | return new IntegerChecker(); |
209 | 209 | }, |
210 | 210 | |
211 | - ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function ( MediaWikiServices $services ) { |
|
211 | + ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function(MediaWikiServices $services) { |
|
212 | 212 | return new CitationNeededChecker(); |
213 | 213 | }, |
214 | 214 | |
215 | - ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
215 | + ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function(MediaWikiServices $services) { |
|
216 | 216 | return new PropertyScopeChecker( |
217 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
217 | + ConstraintsServices::getConstraintParameterParser($services) |
|
218 | 218 | ); |
219 | 219 | }, |
220 | 220 | |
221 | - ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function ( MediaWikiServices $services ) { |
|
221 | + ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function(MediaWikiServices $services) { |
|
222 | 222 | return new ContemporaryChecker( |
223 | - WikibaseServices::getEntityLookup( $services ), |
|
224 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
223 | + WikibaseServices::getEntityLookup($services), |
|
224 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
225 | 225 | $services->getMainConfig() |
226 | 226 | ); |
227 | 227 | }, |
228 | 228 | |
229 | - ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
229 | + ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function(MediaWikiServices $services) { |
|
230 | 230 | return new LanguageChecker( |
231 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
232 | - WikibaseServices::getEntityLookup( $services ) |
|
231 | + ConstraintsServices::getConstraintParameterParser($services), |
|
232 | + WikibaseServices::getEntityLookup($services) |
|
233 | 233 | ); |
234 | 234 | }, |
235 | 235 | ]; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker; |
6 | 6 | |
@@ -77,26 +77,26 @@ discard block |
||
77 | 77 | * @return array first element is the namespace number (default namespace for TitleParser), |
78 | 78 | * second element is a string to prepend to the title before giving it to the TitleParser |
79 | 79 | */ |
80 | - private function getCommonsNamespace( string $namespace ): array { |
|
81 | - switch ( $namespace ) { |
|
80 | + private function getCommonsNamespace(string $namespace): array { |
|
81 | + switch ($namespace) { |
|
82 | 82 | case '': |
83 | - return [ NS_MAIN, '' ]; |
|
83 | + return [NS_MAIN, '']; |
|
84 | 84 | // extra namespaces, see operations/mediawiki-config.git, |
85 | 85 | // wmf-config/InitialiseSettings.php, 'wgExtraNamespaces' key, 'commonswiki' subkey |
86 | 86 | case 'Creator': |
87 | - return [ 100, '' ]; |
|
87 | + return [100, '']; |
|
88 | 88 | case 'TimedText': |
89 | - return [ 102, '' ]; |
|
89 | + return [102, '']; |
|
90 | 90 | case 'Sequence': |
91 | - return [ 104, '' ]; |
|
91 | + return [104, '']; |
|
92 | 92 | case 'Institution': |
93 | - return [ 106, '' ]; |
|
93 | + return [106, '']; |
|
94 | 94 | // extension namespace, see mediawiki/extensions/JsonConfig.git, |
95 | 95 | // extension.json, 'namespaces' key, third element |
96 | 96 | case 'Data': |
97 | - return [ 486, '' ]; |
|
97 | + return [486, '']; |
|
98 | 98 | default: |
99 | - return [ NS_MAIN, $namespace . ':' ]; |
|
99 | + return [NS_MAIN, $namespace.':']; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @throws ConstraintParameterException |
107 | 107 | */ |
108 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
108 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
109 | 109 | $parameters = []; |
110 | 110 | $constraintParameters = $constraint->getConstraintParameters(); |
111 | 111 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | $constraintParameters, |
115 | 115 | $constraintTypeItemId |
116 | 116 | ); |
117 | - $parameters['namespace'] = [ $namespace ]; |
|
117 | + $parameters['namespace'] = [$namespace]; |
|
118 | 118 | |
119 | 119 | $snak = $context->getSnak(); |
120 | 120 | |
121 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
121 | + if (!$snak instanceof PropertyValueSnak) { |
|
122 | 122 | // nothing to check |
123 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
123 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | $dataValue = $snak->getDataValue(); |
@@ -130,52 +130,52 @@ discard block |
||
130 | 130 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
131 | 131 | * parameter $namespace can be null, works for commons galleries |
132 | 132 | */ |
133 | - if ( $dataValue->getType() !== 'string' ) { |
|
134 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
135 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
136 | - ->withDataValueType( 'string' ); |
|
137 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
133 | + if ($dataValue->getType() !== 'string') { |
|
134 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
135 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
136 | + ->withDataValueType('string'); |
|
137 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $commonsLink = $dataValue->getValue(); |
141 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
142 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
143 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
141 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
142 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
143 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
144 | 144 | } |
145 | 145 | |
146 | - $dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty( $snak->getPropertyId() ); |
|
147 | - switch ( $dataType ) { |
|
146 | + $dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty($snak->getPropertyId()); |
|
147 | + switch ($dataType) { |
|
148 | 148 | case 'geo-shape': |
149 | 149 | case 'tabular-data': |
150 | - if ( strpos( $commonsLink, $namespace . ':' ) !== 0 ) { |
|
151 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
152 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
150 | + if (strpos($commonsLink, $namespace.':') !== 0) { |
|
151 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
152 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
153 | 153 | } |
154 | 154 | $pageName = $commonsLink; |
155 | 155 | break; |
156 | 156 | default: |
157 | - $pageName = $namespace ? $namespace . ':' . $commonsLink : $commonsLink; |
|
157 | + $pageName = $namespace ? $namespace.':'.$commonsLink : $commonsLink; |
|
158 | 158 | break; |
159 | 159 | } |
160 | 160 | |
161 | - $prefix = $this->getCommonsNamespace( $namespace )[1]; |
|
161 | + $prefix = $this->getCommonsNamespace($namespace)[1]; |
|
162 | 162 | $normalizedTitle = $this->pageNameNormalizer->normalizePageName( |
163 | 163 | $pageName, |
164 | 164 | 'https://commons.wikimedia.org/w/api.php' |
165 | 165 | ); |
166 | - if ( $normalizedTitle === false ) { |
|
167 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
168 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
169 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
166 | + if ($normalizedTitle === false) { |
|
167 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
168 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
169 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
170 | 170 | } |
171 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
172 | - new ViolationMessage( 'wbqc-violation-message-commons-link-no-existent' ) ); |
|
171 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
172 | + new ViolationMessage('wbqc-violation-message-commons-link-no-existent')); |
|
173 | 173 | } |
174 | 174 | |
175 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, null ); |
|
175 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, null); |
|
176 | 176 | } |
177 | 177 | |
178 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
178 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
179 | 179 | $constraintParameters = $constraint->getConstraintParameters(); |
180 | 180 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
181 | 181 | $exceptions = []; |
@@ -184,15 +184,15 @@ discard block |
||
184 | 184 | $constraintParameters, |
185 | 185 | $constraintTypeItemId |
186 | 186 | ); |
187 | - } catch ( ConstraintParameterException $e ) { |
|
187 | + } catch (ConstraintParameterException $e) { |
|
188 | 188 | $exceptions[] = $e; |
189 | 189 | } |
190 | 190 | return $exceptions; |
191 | 191 | } |
192 | 192 | |
193 | - private function commonsLinkIsWellFormed( string $commonsLink ): bool { |
|
194 | - $toReplace = [ "_", "%20" ]; |
|
195 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
193 | + private function commonsLinkIsWellFormed(string $commonsLink): bool { |
|
194 | + $toReplace = ["_", "%20"]; |
|
195 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
196 | 196 | |
197 | 197 | return $commonsLink === $compareString; |
198 | 198 | } |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | * Checks whether the value of the statement already includes the namespace. |
202 | 202 | * This special case should be reported as “malformed title” instead of “title does not exist”. |
203 | 203 | */ |
204 | - private function valueIncludesNamespace( string $value, string $namespace ): bool { |
|
204 | + private function valueIncludesNamespace(string $value, string $namespace): bool { |
|
205 | 205 | return $namespace !== '' && |
206 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
206 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | } |