@@ -69,32 +69,32 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
71 | 71 | */ |
72 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
73 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
74 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
72 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
73 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
74 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
75 | 75 | } |
76 | - if ( $context->getType() === Context::TYPE_REFERENCE ) { |
|
77 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
76 | + if ($context->getType() === Context::TYPE_REFERENCE) { |
|
77 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | $parameters = []; |
81 | 81 | $constraintParameters = $constraint->getConstraintParameters(); |
82 | 82 | |
83 | - $classes = $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
83 | + $classes = $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
84 | 84 | $parameters['class'] = array_map( |
85 | - function( $id ) { |
|
86 | - return new ItemId( $id ); |
|
85 | + function($id) { |
|
86 | + return new ItemId($id); |
|
87 | 87 | }, |
88 | 88 | $classes |
89 | 89 | ); |
90 | 90 | |
91 | - $relation = $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
92 | - if ( $relation === 'instance' ) { |
|
93 | - $relationId = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
94 | - } elseif ( $relation === 'subclass' ) { |
|
95 | - $relationId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
91 | + $relation = $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
92 | + if ($relation === 'instance') { |
|
93 | + $relationId = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
94 | + } elseif ($relation === 'subclass') { |
|
95 | + $relationId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
96 | 96 | } |
97 | - $parameters['relation'] = [ $relation ]; |
|
97 | + $parameters['relation'] = [$relation]; |
|
98 | 98 | |
99 | 99 | $result = $this->typeCheckerHelper->hasClassInRelation( |
100 | 100 | $context->getEntity()->getStatements(), |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $classes |
103 | 103 | ); |
104 | 104 | |
105 | - if ( $result->getBool() ) { |
|
105 | + if ($result->getBool()) { |
|
106 | 106 | $message = ''; |
107 | 107 | $status = CheckResult::STATUS_COMPLIANCE; |
108 | 108 | } else { |
@@ -116,21 +116,21 @@ discard block |
||
116 | 116 | $status = CheckResult::STATUS_VIOLATION; |
117 | 117 | } |
118 | 118 | |
119 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
120 | - ->withMetadata( $result->getMetadata() ); |
|
119 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
120 | + ->withMetadata($result->getMetadata()); |
|
121 | 121 | } |
122 | 122 | |
123 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
123 | + public function checkConstraintParameters(Constraint $constraint) { |
|
124 | 124 | $constraintParameters = $constraint->getConstraintParameters(); |
125 | 125 | $exceptions = []; |
126 | 126 | try { |
127 | - $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
128 | - } catch ( ConstraintParameterException $e ) { |
|
127 | + $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
128 | + } catch (ConstraintParameterException $e) { |
|
129 | 129 | $exceptions[] = $e; |
130 | 130 | } |
131 | 131 | try { |
132 | - $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
133 | - } catch ( ConstraintParameterException $e ) { |
|
132 | + $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
133 | + } catch (ConstraintParameterException $e) { |
|
134 | 134 | $exceptions[] = $e; |
135 | 135 | } |
136 | 136 | return $exceptions; |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return CheckResult |
62 | 62 | */ |
63 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
64 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
65 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
63 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
64 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
65 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
66 | 66 | } |
67 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
68 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
67 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
68 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $parameters = []; |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | $snak = $context->getSnak(); |
74 | 74 | $propertyId = $context->getSnak()->getPropertyId(); |
75 | 75 | |
76 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
76 | + if (!$snak instanceof PropertyValueSnak) { |
|
77 | 77 | // nothing to check |
78 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
78 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | $dataValue = $snak->getDataValue(); |
@@ -84,22 +84,22 @@ discard block |
||
84 | 84 | * error handling: |
85 | 85 | * type of $dataValue for properties with 'Symmetric' constraint has to be 'wikibase-entityid' |
86 | 86 | */ |
87 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
88 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
87 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
88 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
89 | 89 | ->rawParams( |
90 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
90 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
91 | 91 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
92 | 92 | ) |
93 | 93 | ->escaped(); |
94 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
94 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
95 | 95 | } |
96 | 96 | /** @var EntityIdValue $dataValue */ |
97 | 97 | |
98 | 98 | $targetEntityId = $dataValue->getEntityId(); |
99 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
100 | - if ( $targetEntity === null ) { |
|
101 | - $message = wfMessage( "wbqc-violation-message-target-entity-must-exist" )->escaped(); |
|
102 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
99 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
100 | + if ($targetEntity === null) { |
|
101 | + $message = wfMessage("wbqc-violation-message-target-entity-must-exist")->escaped(); |
|
102 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | $symmetricStatement = $this->connectionCheckerHelper->findStatementWithPropertyAndEntityIdValue( |
@@ -107,26 +107,26 @@ discard block |
||
107 | 107 | $propertyId, |
108 | 108 | $context->getEntity()->getId() |
109 | 109 | ); |
110 | - if ( $symmetricStatement !== null ) { |
|
110 | + if ($symmetricStatement !== null) { |
|
111 | 111 | $message = ''; |
112 | 112 | $status = CheckResult::STATUS_COMPLIANCE; |
113 | 113 | } else { |
114 | - $message = wfMessage( 'wbqc-violation-message-symmetric' ) |
|
114 | + $message = wfMessage('wbqc-violation-message-symmetric') |
|
115 | 115 | ->rawParams( |
116 | - $this->constraintParameterRenderer->formatEntityId( $targetEntityId, Role::SUBJECT ), |
|
117 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::PREDICATE ), |
|
118 | - $this->constraintParameterRenderer->formatEntityId( $context->getEntity()->getId(), Role::OBJECT ) |
|
116 | + $this->constraintParameterRenderer->formatEntityId($targetEntityId, Role::SUBJECT), |
|
117 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::PREDICATE), |
|
118 | + $this->constraintParameterRenderer->formatEntityId($context->getEntity()->getId(), Role::OBJECT) |
|
119 | 119 | ) |
120 | 120 | ->escaped(); |
121 | 121 | $status = CheckResult::STATUS_VIOLATION; |
122 | 122 | } |
123 | 123 | |
124 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
125 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
126 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
124 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
125 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
126 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
127 | 127 | } |
128 | 128 | |
129 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
129 | + public function checkConstraintParameters(Constraint $constraint) { |
|
130 | 130 | // no parameters |
131 | 131 | return []; |
132 | 132 | } |
@@ -20,7 +20,7 @@ |
||
20 | 20 | */ |
21 | 21 | private $metadata; |
22 | 22 | |
23 | - public function __construct( array $array, Metadata $metadata ) { |
|
23 | + public function __construct(array $array, Metadata $metadata) { |
|
24 | 24 | $this->array = $array; |
25 | 25 | $this->metadata = $metadata; |
26 | 26 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param EntityId $entityId An entity ID from which the value was derived. |
30 | 30 | * @return self Indication that a value is was derived from the entity with the given ID. |
31 | 31 | */ |
32 | - public static function ofEntityId( EntityId $entityId ) { |
|
32 | + public static function ofEntityId(EntityId $entityId) { |
|
33 | 33 | $ret = new self; |
34 | 34 | $ret->entityIds[] = $entityId; |
35 | 35 | return $ret; |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | * @param self[] $metadatas |
40 | 40 | * @return self |
41 | 41 | */ |
42 | - public static function merge( array $metadatas ) { |
|
43 | - Assert::parameterElementType( self::class, $metadatas, '$metadatas' ); |
|
42 | + public static function merge(array $metadatas) { |
|
43 | + Assert::parameterElementType(self::class, $metadatas, '$metadatas'); |
|
44 | 44 | $ret = new self; |
45 | - foreach ( $metadatas as $metadata ) { |
|
46 | - $ret->entityIds = array_merge( $ret->entityIds, $metadata->entityIds ); |
|
45 | + foreach ($metadatas as $metadata) { |
|
46 | + $ret->entityIds = array_merge($ret->entityIds, $metadata->entityIds); |
|
47 | 47 | } |
48 | 48 | return $ret; |
49 | 49 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * @param bool $bool |
25 | 25 | * @param Metadata $metadata |
26 | 26 | */ |
27 | - public function __construct( $bool, Metadata $metadata ) { |
|
27 | + public function __construct($bool, Metadata $metadata) { |
|
28 | 28 | $this->bool = $bool; |
29 | 29 | $this->metadata = $metadata; |
30 | 30 | } |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | return $ret; |
33 | 33 | } |
34 | 34 | |
35 | - public static function ofCachingMetadata( CachingMetadata $cachingMetadata ) { |
|
35 | + public static function ofCachingMetadata(CachingMetadata $cachingMetadata) { |
|
36 | 36 | $ret = new self; |
37 | 37 | $ret->cachingMetadata = $cachingMetadata; |
38 | 38 | $ret->dependencyMetadata = DependencyMetadata::blank(); |
39 | 39 | return $ret; |
40 | 40 | } |
41 | 41 | |
42 | - public static function ofDependencyMetadata( DependencyMetadata $dependencyMetadata ) { |
|
42 | + public static function ofDependencyMetadata(DependencyMetadata $dependencyMetadata) { |
|
43 | 43 | $ret = new self; |
44 | 44 | $ret->cachingMetadata = CachingMetadata::fresh(); |
45 | 45 | $ret->dependencyMetadata = $dependencyMetadata; |
@@ -50,17 +50,17 @@ discard block |
||
50 | 50 | * @param self[] $metadatas |
51 | 51 | * @return self |
52 | 52 | */ |
53 | - public static function merge( array $metadatas ) { |
|
54 | - Assert::parameterElementType( self::class, $metadatas, '$metadatas' ); |
|
53 | + public static function merge(array $metadatas) { |
|
54 | + Assert::parameterElementType(self::class, $metadatas, '$metadatas'); |
|
55 | 55 | $cachingMetadatas = []; |
56 | 56 | $dependencyMetadatas = []; |
57 | - foreach ( $metadatas as $metadata ) { |
|
57 | + foreach ($metadatas as $metadata) { |
|
58 | 58 | $cachingMetadatas[] = $metadata->cachingMetadata; |
59 | 59 | $dependencyMetadatas[] = $metadata->dependencyMetadata; |
60 | 60 | } |
61 | 61 | $ret = new self; |
62 | - $ret->cachingMetadata = CachingMetadata::merge( $cachingMetadatas ); |
|
63 | - $ret->dependencyMetadata = DependencyMetadata::merge( $dependencyMetadatas ); |
|
62 | + $ret->cachingMetadata = CachingMetadata::merge($cachingMetadatas); |
|
63 | + $ret->dependencyMetadata = DependencyMetadata::merge($dependencyMetadatas); |
|
64 | 64 | return $ret; |
65 | 65 | } |
66 | 66 |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * @param int $maxAge The maximum age of the cached value (in seconds). |
30 | 30 | * @return self Indication that a value is possibly outdated by up to this many seconds. |
31 | 31 | */ |
32 | - public static function ofMaximumAgeInSeconds( $maxAge ) { |
|
33 | - Assert::parameterType( 'integer', $maxAge, '$maxAge' ); |
|
34 | - Assert::parameter( $maxAge > 0, '$maxAge', '$maxage > 0' ); |
|
32 | + public static function ofMaximumAgeInSeconds($maxAge) { |
|
33 | + Assert::parameterType('integer', $maxAge, '$maxAge'); |
|
34 | + Assert::parameter($maxAge > 0, '$maxAge', '$maxage > 0'); |
|
35 | 35 | $ret = new self; |
36 | 36 | $ret->maxAge = $maxAge; |
37 | 37 | return $ret; |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * @param array|null $array As returned by toArray. |
43 | 43 | * @return CachingMetadata |
44 | 44 | */ |
45 | - public static function ofArray( array $array = null ) { |
|
45 | + public static function ofArray(array $array = null) { |
|
46 | 46 | $ret = new self; |
47 | - if ( $array !== null ) { |
|
47 | + if ($array !== null) { |
|
48 | 48 | $ret->maxAge = $array['maximumAgeInSeconds']; |
49 | 49 | } |
50 | 50 | return $ret; |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | * @param self[] $metadatas |
55 | 55 | * @return self |
56 | 56 | */ |
57 | - public static function merge( array $metadatas ) { |
|
58 | - Assert::parameterElementType( self::class, $metadatas, '$metadatas' ); |
|
57 | + public static function merge(array $metadatas) { |
|
58 | + Assert::parameterElementType(self::class, $metadatas, '$metadatas'); |
|
59 | 59 | $ret = new self; |
60 | - foreach ( $metadatas as $metadata ) { |
|
61 | - $ret->maxAge = max( $ret->maxAge, $metadata->maxAge ); |
|
60 | + foreach ($metadatas as $metadata) { |
|
61 | + $ret->maxAge = max($ret->maxAge, $metadata->maxAge); |
|
62 | 62 | } |
63 | 63 | return $ret; |
64 | 64 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * For a fresh value, returns 0. |
77 | 77 | */ |
78 | 78 | public function getMaximumAgeInSeconds() { |
79 | - if ( is_int( $this->maxAge ) ) { |
|
79 | + if (is_int($this->maxAge)) { |
|
80 | 80 | return $this->maxAge; |
81 | 81 | } else { |
82 | 82 | return 0; |
@@ -91,8 +91,7 @@ discard block |
||
91 | 91 | return $this->isCached() ? |
92 | 92 | [ |
93 | 93 | 'maximumAgeInSeconds' => $this->maxAge, |
94 | - ] : |
|
95 | - null; |
|
94 | + ] : null; |
|
96 | 95 | } |
97 | 96 | |
98 | 97 | } |
@@ -137,14 +137,14 @@ discard block |
||
137 | 137 | callable $defaultResults = null |
138 | 138 | ) { |
139 | 139 | |
140 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
141 | - if ( $entity instanceof StatementListProvider ) { |
|
140 | + $entity = $this->entityLookup->getEntity($entityId); |
|
141 | + if ($entity instanceof StatementListProvider) { |
|
142 | 142 | $result = $this->checkEveryStatement( |
143 | - $this->entityLookup->getEntity( $entityId ), |
|
143 | + $this->entityLookup->getEntity($entityId), |
|
144 | 144 | $constraintIds, |
145 | 145 | $defaultResults |
146 | 146 | ); |
147 | - $output = $this->sortResult( $result ); |
|
147 | + $output = $this->sortResult($result); |
|
148 | 148 | return $output; |
149 | 149 | } |
150 | 150 | |
@@ -170,19 +170,19 @@ discard block |
||
170 | 170 | callable $defaultResults = null |
171 | 171 | ) { |
172 | 172 | |
173 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
173 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
174 | 174 | $entityId = $parsedGuid->getEntityId(); |
175 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
176 | - if ( $entity instanceof StatementListProvider ) { |
|
177 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
178 | - if ( $statement ) { |
|
175 | + $entity = $this->entityLookup->getEntity($entityId); |
|
176 | + if ($entity instanceof StatementListProvider) { |
|
177 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
178 | + if ($statement) { |
|
179 | 179 | $result = $this->checkStatement( |
180 | 180 | $entity, |
181 | 181 | $statement, |
182 | 182 | $constraintIds, |
183 | 183 | $defaultResults |
184 | 184 | ); |
185 | - $output = $this->sortResult( $result ); |
|
185 | + $output = $this->sortResult($result); |
|
186 | 186 | return $output; |
187 | 187 | } |
188 | 188 | } |
@@ -198,23 +198,23 @@ discard block |
||
198 | 198 | * |
199 | 199 | * @return ConstraintParameterException[] |
200 | 200 | */ |
201 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
201 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
202 | 202 | $constraintParameters = $constraint->getConstraintParameters(); |
203 | 203 | try { |
204 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
205 | - } catch ( ConstraintParameterException $e ) { |
|
206 | - return [ $e ]; |
|
204 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
205 | + } catch (ConstraintParameterException $e) { |
|
206 | + return [$e]; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | $problems = []; |
210 | 210 | try { |
211 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
212 | - } catch ( ConstraintParameterException $e ) { |
|
211 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
212 | + } catch (ConstraintParameterException $e) { |
|
213 | 213 | $problems[] = $e; |
214 | 214 | } |
215 | 215 | try { |
216 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
217 | - } catch ( ConstraintParameterException $e ) { |
|
216 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
217 | + } catch (ConstraintParameterException $e) { |
|
218 | 218 | $problems[] = $e; |
219 | 219 | } |
220 | 220 | return $problems; |
@@ -227,16 +227,16 @@ discard block |
||
227 | 227 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
228 | 228 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
229 | 229 | */ |
230 | - public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) { |
|
231 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
230 | + public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) { |
|
231 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
232 | 232 | $result = []; |
233 | 233 | |
234 | - foreach ( $constraints as $constraint ) { |
|
235 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
234 | + foreach ($constraints as $constraint) { |
|
235 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
236 | 236 | |
237 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
237 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
238 | 238 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
239 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
239 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | $result[$constraint->getConstraintId()] = $problems; |
@@ -253,17 +253,17 @@ discard block |
||
253 | 253 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
254 | 254 | * (empty means all parameters okay), or null if constraint is not found |
255 | 255 | */ |
256 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
257 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
258 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
256 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
257 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
258 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
259 | 259 | |
260 | - foreach ( $constraints as $constraint ) { |
|
261 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
262 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
260 | + foreach ($constraints as $constraint) { |
|
261 | + if ($constraint->getConstraintId() === $constraintId) { |
|
262 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
263 | 263 | |
264 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
264 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
265 | 265 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
266 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
266 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | return $problems; |
@@ -288,14 +288,14 @@ discard block |
||
288 | 288 | $result = []; |
289 | 289 | |
290 | 290 | /** @var Statement $statement */ |
291 | - foreach ( $entity->getStatements() as $statement ) { |
|
292 | - $result = array_merge( $result, |
|
291 | + foreach ($entity->getStatements() as $statement) { |
|
292 | + $result = array_merge($result, |
|
293 | 293 | $this->checkStatement( |
294 | 294 | $entity, |
295 | 295 | $statement, |
296 | 296 | $constraintIds, |
297 | 297 | $defaultResults |
298 | - ) ); |
|
298 | + )); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | return $result; |
@@ -317,32 +317,32 @@ discard block |
||
317 | 317 | ) { |
318 | 318 | $result = []; |
319 | 319 | |
320 | - $result = array_merge( $result, |
|
320 | + $result = array_merge($result, |
|
321 | 321 | $this->checkConstraintsForMainSnak( |
322 | 322 | $entity, |
323 | 323 | $statement, |
324 | 324 | $constraintIds, |
325 | 325 | $defaultResults |
326 | - ) ); |
|
326 | + )); |
|
327 | 327 | |
328 | - if ( $this->checkQualifiers ) { |
|
329 | - $result = array_merge( $result, |
|
328 | + if ($this->checkQualifiers) { |
|
329 | + $result = array_merge($result, |
|
330 | 330 | $this->checkConstraintsForQualifiers( |
331 | 331 | $entity, |
332 | 332 | $statement, |
333 | 333 | $constraintIds, |
334 | 334 | $defaultResults |
335 | - ) ); |
|
335 | + )); |
|
336 | 336 | } |
337 | 337 | |
338 | - if ( $this->checkReferences ) { |
|
339 | - $result = array_merge( $result, |
|
338 | + if ($this->checkReferences) { |
|
339 | + $result = array_merge($result, |
|
340 | 340 | $this->checkConstraintsForReferences( |
341 | 341 | $entity, |
342 | 342 | $statement, |
343 | 343 | $constraintIds, |
344 | 344 | $defaultResults |
345 | - ) ); |
|
345 | + )); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | return $result; |
@@ -357,12 +357,12 @@ discard block |
||
357 | 357 | * @param string[]|null $constraintIds |
358 | 358 | * @return Constraint[] |
359 | 359 | */ |
360 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
361 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
362 | - if ( $constraintIds !== null ) { |
|
360 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
361 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
362 | + if ($constraintIds !== null) { |
|
363 | 363 | $constraintsToUse = []; |
364 | - foreach ( $constraints as $constraint ) { |
|
365 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
364 | + foreach ($constraints as $constraint) { |
|
365 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
366 | 366 | $constraintsToUse[] = $constraint; |
367 | 367 | } |
368 | 368 | } |
@@ -386,29 +386,29 @@ discard block |
||
386 | 386 | array $constraintIds = null, |
387 | 387 | callable $defaultResults = null |
388 | 388 | ) { |
389 | - $context = new MainSnakContext( $entity, $statement ); |
|
389 | + $context = new MainSnakContext($entity, $statement); |
|
390 | 390 | $constraints = $this->getConstraintsToUse( |
391 | 391 | $statement->getPropertyId(), |
392 | 392 | $constraintIds |
393 | 393 | ); |
394 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
394 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
395 | 395 | |
396 | - foreach ( $constraints as $constraint ) { |
|
396 | + foreach ($constraints as $constraint) { |
|
397 | 397 | $parameters = $constraint->getConstraintParameters(); |
398 | 398 | try { |
399 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
400 | - } catch ( ConstraintParameterException $e ) { |
|
401 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
399 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
400 | + } catch (ConstraintParameterException $e) { |
|
401 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
402 | 402 | continue; |
403 | 403 | } |
404 | 404 | |
405 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
406 | - $message = wfMessage( 'wbqc-exception-message' )->escaped(); |
|
407 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
405 | + if (in_array($entity->getId(), $exceptions)) { |
|
406 | + $message = wfMessage('wbqc-exception-message')->escaped(); |
|
407 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
408 | 408 | continue; |
409 | 409 | } |
410 | 410 | |
411 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
411 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | return $result; |
@@ -430,24 +430,24 @@ discard block |
||
430 | 430 | ) { |
431 | 431 | $result = []; |
432 | 432 | |
433 | - if ( in_array( |
|
433 | + if (in_array( |
|
434 | 434 | $statement->getPropertyId()->getSerialization(), |
435 | 435 | $this->propertiesWithViolatingQualifiers |
436 | - ) ) { |
|
436 | + )) { |
|
437 | 437 | return $result; |
438 | 438 | } |
439 | 439 | |
440 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
441 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
442 | - if ( $defaultResults !== null ) { |
|
443 | - $result = array_merge( $result, $defaultResults( $qualifierContext ) ); |
|
440 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
441 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
442 | + if ($defaultResults !== null) { |
|
443 | + $result = array_merge($result, $defaultResults($qualifierContext)); |
|
444 | 444 | } |
445 | 445 | $qualifierConstraints = $this->getConstraintsToUse( |
446 | 446 | $qualifierContext->getSnak()->getPropertyId(), |
447 | 447 | $constraintIds |
448 | 448 | ); |
449 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
450 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
449 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
450 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
451 | 451 | } |
452 | 452 | } |
453 | 453 | |
@@ -471,19 +471,19 @@ discard block |
||
471 | 471 | $result = []; |
472 | 472 | |
473 | 473 | /** @var Reference $reference */ |
474 | - foreach ( $statement->getReferences() as $reference ) { |
|
475 | - foreach ( $reference->getSnaks() as $snak ) { |
|
474 | + foreach ($statement->getReferences() as $reference) { |
|
475 | + foreach ($reference->getSnaks() as $snak) { |
|
476 | 476 | $referenceContext = new ReferenceContext( |
477 | 477 | $entity, $statement, $reference, $snak |
478 | 478 | ); |
479 | - if ( $defaultResults !== null ) { |
|
480 | - $result = array_merge( $result, $defaultResults( $referenceContext ) ); |
|
479 | + if ($defaultResults !== null) { |
|
480 | + $result = array_merge($result, $defaultResults($referenceContext)); |
|
481 | 481 | } |
482 | 482 | $referenceConstraints = $this->getConstraintsToUse( |
483 | 483 | $referenceContext->getSnak()->getPropertyId(), |
484 | 484 | $constraintIds |
485 | 485 | ); |
486 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
486 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
487 | 487 | $result[] = $this->getCheckResultFor( |
488 | 488 | $referenceContext, |
489 | 489 | $referenceConstraint |
@@ -502,70 +502,70 @@ discard block |
||
502 | 502 | * @throws InvalidArgumentException |
503 | 503 | * @return CheckResult |
504 | 504 | */ |
505 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
506 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
505 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
506 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
507 | 507 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
508 | 508 | |
509 | - $startTime = microtime( true ); |
|
509 | + $startTime = microtime(true); |
|
510 | 510 | try { |
511 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
512 | - } catch ( ConstraintParameterException $e ) { |
|
513 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
514 | - } catch ( SparqlHelperException $e ) { |
|
515 | - $message = wfMessage( 'wbqc-violation-message-sparql-error' )->escaped(); |
|
516 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
511 | + $result = $checker->checkConstraint($context, $constraint); |
|
512 | + } catch (ConstraintParameterException $e) { |
|
513 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
514 | + } catch (SparqlHelperException $e) { |
|
515 | + $message = wfMessage('wbqc-violation-message-sparql-error')->escaped(); |
|
516 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
517 | 517 | } |
518 | - $endTime = microtime( true ); |
|
518 | + $endTime = microtime(true); |
|
519 | 519 | |
520 | - $this->addMetadata( $result ); |
|
520 | + $this->addMetadata($result); |
|
521 | 521 | |
522 | 522 | try { |
523 | 523 | $constraintStatus = $this->constraintParameterParser |
524 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
525 | - } catch ( ConstraintParameterException $e ) { |
|
526 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage() ); |
|
524 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
525 | + } catch (ConstraintParameterException $e) { |
|
526 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getMessage()); |
|
527 | 527 | $constraintStatus = null; |
528 | 528 | } |
529 | - if ( $constraintStatus === null ) { |
|
529 | + if ($constraintStatus === null) { |
|
530 | 530 | // downgrade violation to warning |
531 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
532 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
531 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
532 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
533 | 533 | } |
534 | 534 | } else { |
535 | - if ( $constraintStatus !== 'mandatory' ) { |
|
535 | + if ($constraintStatus !== 'mandatory') { |
|
536 | 536 | // @codeCoverageIgnoreStart |
537 | 537 | throw new LogicException( |
538 | - "Unknown constraint status '$constraintStatus', " . |
|
538 | + "Unknown constraint status '$constraintStatus', ". |
|
539 | 539 | "only known status is 'mandatory'" |
540 | 540 | ); |
541 | 541 | // @codeCoverageIgnoreEnd |
542 | 542 | } |
543 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
543 | + $result->addParameter('constraint_status', $constraintStatus); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | $this->loggingHelper->logConstraintCheck( |
547 | 547 | $context, |
548 | 548 | $constraint, |
549 | 549 | $result, |
550 | - get_class( $checker ), |
|
550 | + get_class($checker), |
|
551 | 551 | $endTime - $startTime, |
552 | 552 | __METHOD__ |
553 | 553 | ); |
554 | 554 | |
555 | 555 | return $result; |
556 | 556 | } else { |
557 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
557 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
561 | - private function addMetadata( CheckResult $result ) { |
|
562 | - $result->withMetadata( Metadata::merge( [ |
|
561 | + private function addMetadata(CheckResult $result) { |
|
562 | + $result->withMetadata(Metadata::merge([ |
|
563 | 563 | $result->getMetadata(), |
564 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
565 | - DependencyMetadata::ofEntityId( $result->getEntityId() ), |
|
566 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
567 | - ] ) ), |
|
568 | - ] ) ); |
|
564 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
565 | + DependencyMetadata::ofEntityId($result->getEntityId()), |
|
566 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
567 | + ])), |
|
568 | + ])); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | /** |
@@ -573,12 +573,12 @@ discard block |
||
573 | 573 | * |
574 | 574 | * @return CheckResult[] |
575 | 575 | */ |
576 | - private function sortResult( array $result ) { |
|
577 | - if ( count( $result ) < 2 ) { |
|
576 | + private function sortResult(array $result) { |
|
577 | + if (count($result) < 2) { |
|
578 | 578 | return $result; |
579 | 579 | } |
580 | 580 | |
581 | - $sortFunction = function ( CheckResult $a, CheckResult $b ) { |
|
581 | + $sortFunction = function(CheckResult $a, CheckResult $b) { |
|
582 | 582 | $orderNum = 0; |
583 | 583 | $order = [ |
584 | 584 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -594,45 +594,45 @@ discard block |
||
594 | 594 | $statusA = $a->getStatus(); |
595 | 595 | $statusB = $b->getStatus(); |
596 | 596 | |
597 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
598 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
597 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
598 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
599 | 599 | |
600 | - if ( $orderA === $orderB ) { |
|
600 | + if ($orderA === $orderB) { |
|
601 | 601 | $pidA = $a->getContext()->getSnak()->getPropertyId()->getSerialization(); |
602 | 602 | $pidB = $b->getContext()->getSnak()->getPropertyId()->getSerialization(); |
603 | 603 | |
604 | - if ( $pidA === $pidB ) { |
|
604 | + if ($pidA === $pidB) { |
|
605 | 605 | $hashA = $a->getContext()->getSnak()->getHash(); |
606 | 606 | $hashB = $b->getContext()->getSnak()->getHash(); |
607 | 607 | |
608 | - if ( $hashA === $hashB ) { |
|
609 | - if ( $a instanceof NullResult ) { |
|
608 | + if ($hashA === $hashB) { |
|
609 | + if ($a instanceof NullResult) { |
|
610 | 610 | return $b instanceof NullResult ? 0 : -1; |
611 | 611 | } |
612 | - if ( $b instanceof NullResult ) { |
|
612 | + if ($b instanceof NullResult) { |
|
613 | 613 | return $a instanceof NullResult ? 0 : 1; |
614 | 614 | } |
615 | 615 | |
616 | 616 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
617 | 617 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
618 | 618 | |
619 | - if ( $typeA == $typeB ) { |
|
619 | + if ($typeA == $typeB) { |
|
620 | 620 | return 0; |
621 | 621 | } else { |
622 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
622 | + return ($typeA > $typeB) ? 1 : -1; |
|
623 | 623 | } |
624 | 624 | } else { |
625 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
625 | + return ($hashA > $hashB) ? 1 : -1; |
|
626 | 626 | } |
627 | 627 | } else { |
628 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
628 | + return ($pidA > $pidB) ? 1 : -1; |
|
629 | 629 | } |
630 | 630 | } else { |
631 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
631 | + return ($orderA > $orderB) ? 1 : -1; |
|
632 | 632 | } |
633 | 633 | }; |
634 | 634 | |
635 | - uasort( $result, $sortFunction ); |
|
635 | + uasort($result, $sortFunction); |
|
636 | 636 | |
637 | 637 | return $result; |
638 | 638 | } |
@@ -60,22 +60,22 @@ discard block |
||
60 | 60 | * @return array first element is the namespace number (default namespace for TitleParser), |
61 | 61 | * second element is a string to prepend to the title before giving it to the TitleParser |
62 | 62 | */ |
63 | - private function getCommonsNamespace( $namespace ) { |
|
63 | + private function getCommonsNamespace($namespace) { |
|
64 | 64 | // for namespace numbers see mediawiki-config repo, wmf-config/InitialiseSettings.php, |
65 | 65 | // 'wgExtraNamespaces' key, 'commonswiki' subkey |
66 | - switch ( $namespace ) { |
|
66 | + switch ($namespace) { |
|
67 | 67 | case '': |
68 | - return [ NS_MAIN, '' ]; |
|
68 | + return [NS_MAIN, '']; |
|
69 | 69 | case 'Creator': |
70 | - return [ 100, '' ]; |
|
70 | + return [100, '']; |
|
71 | 71 | case 'TimedText': |
72 | - return [ 102, '' ]; |
|
72 | + return [102, '']; |
|
73 | 73 | case 'Sequence': |
74 | - return [ 104, '' ]; |
|
74 | + return [104, '']; |
|
75 | 75 | case 'Institution': |
76 | - return [ 106, '' ]; |
|
76 | + return [106, '']; |
|
77 | 77 | default: |
78 | - return [ NS_MAIN, $namespace . ':' ]; |
|
78 | + return [NS_MAIN, $namespace.':']; |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
@@ -87,17 +87,17 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @return CheckResult |
89 | 89 | */ |
90 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
90 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
91 | 91 | $parameters = []; |
92 | 92 | $constraintParameters = $constraint->getConstraintParameters(); |
93 | - $namespace = $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
94 | - $parameters['namespace'] = [ $namespace ]; |
|
93 | + $namespace = $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
94 | + $parameters['namespace'] = [$namespace]; |
|
95 | 95 | |
96 | 96 | $snak = $context->getSnak(); |
97 | 97 | |
98 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
98 | + if (!$snak instanceof PropertyValueSnak) { |
|
99 | 99 | // nothing to check |
100 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
100 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $dataValue = $snak->getDataValue(); |
@@ -107,49 +107,49 @@ discard block |
||
107 | 107 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
108 | 108 | * parameter $namespace can be null, works for commons galleries |
109 | 109 | */ |
110 | - if ( $dataValue->getType() !== 'string' ) { |
|
111 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
110 | + if ($dataValue->getType() !== 'string') { |
|
111 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
112 | 112 | ->rawParams( |
113 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
114 | - wfMessage( 'datatypes-type-string' )->escaped() |
|
113 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
114 | + wfMessage('datatypes-type-string')->escaped() |
|
115 | 115 | ) |
116 | 116 | ->escaped(); |
117 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
117 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | $commonsLink = $dataValue->getValue(); |
121 | 121 | |
122 | 122 | try { |
123 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
124 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
123 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
124 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
125 | 125 | } |
126 | - list ( $defaultNamespace, $prefix ) = $this->getCommonsNamespace( $namespace ); |
|
127 | - $title = $this->titleParser->parseTitle( $prefix . $commonsLink, $defaultNamespace ); |
|
128 | - if ( $this->pageExists( $title ) ) { |
|
126 | + list ($defaultNamespace, $prefix) = $this->getCommonsNamespace($namespace); |
|
127 | + $title = $this->titleParser->parseTitle($prefix.$commonsLink, $defaultNamespace); |
|
128 | + if ($this->pageExists($title)) { |
|
129 | 129 | $message = ''; |
130 | 130 | $status = CheckResult::STATUS_COMPLIANCE; |
131 | 131 | } else { |
132 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
133 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
132 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
133 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
134 | 134 | } else { |
135 | - $message = wfMessage( "wbqc-violation-message-commons-link-no-existent" )->escaped(); |
|
135 | + $message = wfMessage("wbqc-violation-message-commons-link-no-existent")->escaped(); |
|
136 | 136 | $status = CheckResult::STATUS_VIOLATION; |
137 | 137 | } |
138 | 138 | } |
139 | - } catch ( MalformedTitleException $e ) { |
|
140 | - $message = wfMessage( "wbqc-violation-message-commons-link-not-well-formed" )->escaped(); |
|
139 | + } catch (MalformedTitleException $e) { |
|
140 | + $message = wfMessage("wbqc-violation-message-commons-link-not-well-formed")->escaped(); |
|
141 | 141 | $status = CheckResult::STATUS_VIOLATION; |
142 | 142 | } |
143 | 143 | |
144 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
144 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
145 | 145 | } |
146 | 146 | |
147 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
147 | + public function checkConstraintParameters(Constraint $constraint) { |
|
148 | 148 | $constraintParameters = $constraint->getConstraintParameters(); |
149 | 149 | $exceptions = []; |
150 | 150 | try { |
151 | - $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
152 | - } catch ( ConstraintParameterException $e ) { |
|
151 | + $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
152 | + } catch (ConstraintParameterException $e) { |
|
153 | 153 | $exceptions[] = $e; |
154 | 154 | } |
155 | 155 | return $exceptions; |
@@ -160,19 +160,19 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @return bool |
162 | 162 | */ |
163 | - private function pageExists( TitleValue $title ) { |
|
163 | + private function pageExists(TitleValue $title) { |
|
164 | 164 | $commonsWikiId = 'commonswiki'; |
165 | - if ( defined( 'MW_PHPUNIT_TEST' ) ) { |
|
165 | + if (defined('MW_PHPUNIT_TEST')) { |
|
166 | 166 | $commonsWikiId = false; |
167 | 167 | } |
168 | 168 | |
169 | - $dbLoadBalancer = wfGetLB( $commonsWikiId ); |
|
169 | + $dbLoadBalancer = wfGetLB($commonsWikiId); |
|
170 | 170 | $dbConnection = $dbLoadBalancer->getConnection( |
171 | 171 | DB_REPLICA, false, $commonsWikiId ); |
172 | - $row = $dbConnection->selectRow( 'page', '*', [ |
|
172 | + $row = $dbConnection->selectRow('page', '*', [ |
|
173 | 173 | 'page_title' => $title->getDBkey(), |
174 | 174 | 'page_namespace' => $title->getNamespace() |
175 | - ] ); |
|
175 | + ]); |
|
176 | 176 | |
177 | 177 | return $row !== false; |
178 | 178 | } |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return bool |
184 | 184 | */ |
185 | - private function commonsLinkIsWellFormed( $commonsLink ) { |
|
186 | - $toReplace = [ "_", "%20" ]; |
|
187 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
185 | + private function commonsLinkIsWellFormed($commonsLink) { |
|
186 | + $toReplace = ["_", "%20"]; |
|
187 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
188 | 188 | return $commonsLink === $compareString; |
189 | 189 | } |
190 | 190 | |
@@ -197,9 +197,9 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @return bool |
199 | 199 | */ |
200 | - private function valueIncludesNamespace( $value, $namespace ) { |
|
200 | + private function valueIncludesNamespace($value, $namespace) { |
|
201 | 201 | return $namespace !== '' && |
202 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
202 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | } |