@@ -71,40 +71,40 @@ |
||
71 | 71 | * @throws ConstraintParameterException |
72 | 72 | * @return CheckResult |
73 | 73 | */ |
74 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
75 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
76 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
74 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
75 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
76 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | $parameters = []; |
80 | 80 | $constraintParameters = $constraint->getConstraintParameters(); |
81 | 81 | |
82 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
83 | - $parameters['property'] = [ $propertyId ]; |
|
82 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
83 | + $parameters['property'] = [$propertyId]; |
|
84 | 84 | |
85 | - $message = ( new ViolationMessage( 'wbqc-violation-message-mandatory-qualifier' ) ) |
|
86 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
87 | - ->withEntityId( $propertyId, Role::QUALIFIER_PREDICATE ); |
|
85 | + $message = (new ViolationMessage('wbqc-violation-message-mandatory-qualifier')) |
|
86 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
87 | + ->withEntityId($propertyId, Role::QUALIFIER_PREDICATE); |
|
88 | 88 | $status = CheckResult::STATUS_VIOLATION; |
89 | 89 | |
90 | 90 | /** @var Snak $qualifier */ |
91 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
92 | - if ( $propertyId->equals( $qualifier->getPropertyId() ) ) { |
|
91 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
92 | + if ($propertyId->equals($qualifier->getPropertyId())) { |
|
93 | 93 | $message = null; |
94 | 94 | $status = CheckResult::STATUS_COMPLIANCE; |
95 | 95 | break; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
99 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
100 | 100 | } |
101 | 101 | |
102 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
102 | + public function checkConstraintParameters(Constraint $constraint) { |
|
103 | 103 | $constraintParameters = $constraint->getConstraintParameters(); |
104 | 104 | $exceptions = []; |
105 | 105 | try { |
106 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
107 | - } catch ( ConstraintParameterException $e ) { |
|
106 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
107 | + } catch (ConstraintParameterException $e) { |
|
108 | 108 | $exceptions[] = $e; |
109 | 109 | } |
110 | 110 | return $exceptions; |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return CheckResult |
82 | 82 | */ |
83 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
84 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
85 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
83 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
84 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
85 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | $parameters = []; |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | $snak = $context->getSnak(); |
91 | 91 | $propertyId = $context->getSnak()->getPropertyId(); |
92 | 92 | |
93 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
93 | + if (!$snak instanceof PropertyValueSnak) { |
|
94 | 94 | // nothing to check |
95 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
95 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | $dataValue = $snak->getDataValue(); |
@@ -101,22 +101,22 @@ discard block |
||
101 | 101 | * error handling: |
102 | 102 | * type of $dataValue for properties with 'Symmetric' constraint has to be 'wikibase-entityid' |
103 | 103 | */ |
104 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
105 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
104 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
105 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
106 | 106 | ->rawParams( |
107 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
107 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
108 | 108 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
109 | 109 | ) |
110 | 110 | ->escaped(); |
111 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
111 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
112 | 112 | } |
113 | 113 | /** @var EntityIdValue $dataValue */ |
114 | 114 | |
115 | 115 | $targetEntityId = $dataValue->getEntityId(); |
116 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
117 | - if ( $targetEntity === null ) { |
|
118 | - $message = new ViolationMessage( 'wbqc-violation-message-target-entity-must-exist' ); |
|
119 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
116 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
117 | + if ($targetEntity === null) { |
|
118 | + $message = new ViolationMessage('wbqc-violation-message-target-entity-must-exist'); |
|
119 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $symmetricStatement = $this->connectionCheckerHelper->findStatementWithPropertyAndEntityIdValue( |
@@ -124,23 +124,23 @@ discard block |
||
124 | 124 | $propertyId, |
125 | 125 | $context->getEntity()->getId() |
126 | 126 | ); |
127 | - if ( $symmetricStatement !== null ) { |
|
127 | + if ($symmetricStatement !== null) { |
|
128 | 128 | $message = null; |
129 | 129 | $status = CheckResult::STATUS_COMPLIANCE; |
130 | 130 | } else { |
131 | - $message = ( new ViolationMessage( 'wbqc-violation-message-symmetric' ) ) |
|
132 | - ->withEntityId( $targetEntityId, Role::SUBJECT ) |
|
133 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
134 | - ->withEntityId( $context->getEntity()->getId(), Role::OBJECT ); |
|
131 | + $message = (new ViolationMessage('wbqc-violation-message-symmetric')) |
|
132 | + ->withEntityId($targetEntityId, Role::SUBJECT) |
|
133 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
134 | + ->withEntityId($context->getEntity()->getId(), Role::OBJECT); |
|
135 | 135 | $status = CheckResult::STATUS_VIOLATION; |
136 | 136 | } |
137 | 137 | |
138 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
139 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
140 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
138 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
139 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
140 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
141 | 141 | } |
142 | 142 | |
143 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
143 | + public function checkConstraintParameters(Constraint $constraint) { |
|
144 | 144 | // no parameters |
145 | 145 | return []; |
146 | 146 | } |
@@ -95,26 +95,26 @@ discard block |
||
95 | 95 | * @throws ConstraintParameterException |
96 | 96 | * @return CheckResult |
97 | 97 | */ |
98 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
98 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
99 | 99 | $parameters = []; |
100 | 100 | $constraintParameters = $constraint->getConstraintParameters(); |
101 | 101 | |
102 | - $format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
103 | - $parameters['pattern'] = [ $format ]; |
|
102 | + $format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
103 | + $parameters['pattern'] = [$format]; |
|
104 | 104 | |
105 | 105 | $syntaxClarification = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
106 | 106 | $constraintParameters, |
107 | 107 | WikibaseRepo::getDefaultInstance()->getUserLanguage() // TODO make this part of the Context? |
108 | 108 | ); |
109 | - if ( $syntaxClarification !== null ) { |
|
110 | - $parameters['clarification'] = [ $syntaxClarification ]; |
|
109 | + if ($syntaxClarification !== null) { |
|
110 | + $parameters['clarification'] = [$syntaxClarification]; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | $snak = $context->getSnak(); |
114 | 114 | |
115 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
115 | + if (!$snak instanceof PropertyValueSnak) { |
|
116 | 116 | // nothing to check |
117 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
117 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | $dataValue = $snak->getDataValue(); |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * error handling: |
124 | 124 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
125 | 125 | */ |
126 | - switch ( $dataValue->getType() ) { |
|
126 | + switch ($dataValue->getType()) { |
|
127 | 127 | case 'string': |
128 | 128 | $text = $dataValue->getValue(); |
129 | 129 | break; |
@@ -132,59 +132,58 @@ discard block |
||
132 | 132 | $text = $dataValue->getText(); |
133 | 133 | break; |
134 | 134 | default: |
135 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-types-2" ) |
|
135 | + $message = wfMessage("wbqc-violation-message-value-needed-of-types-2") |
|
136 | 136 | ->rawParams( |
137 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
138 | - wfMessage( 'datatypes-type-string' )->escaped(), |
|
139 | - wfMessage( 'datatypes-type-monolingualtext' )->escaped() |
|
137 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
138 | + wfMessage('datatypes-type-string')->escaped(), |
|
139 | + wfMessage('datatypes-type-monolingualtext')->escaped() |
|
140 | 140 | ) |
141 | 141 | ->escaped(); |
142 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
142 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
143 | 143 | } |
144 | 144 | |
145 | - if ( $this->sparqlHelper !== null && $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
146 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
145 | + if ($this->sparqlHelper !== null && $this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
146 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
147 | 147 | $message = null; |
148 | 148 | $status = CheckResult::STATUS_COMPLIANCE; |
149 | 149 | } else { |
150 | 150 | $message = wfMessage( |
151 | 151 | $syntaxClarification !== null ? |
152 | - 'wbqc-violation-message-format-clarification' : |
|
153 | - 'wbqc-violation-message-format' |
|
152 | + 'wbqc-violation-message-format-clarification' : 'wbqc-violation-message-format' |
|
154 | 153 | )->rawParams( |
155 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
156 | - $this->constraintParameterRenderer->formatDataValue( new StringValue( $text ), Role::OBJECT ), |
|
157 | - $this->constraintParameterRenderer->formatByRole( Role::CONSTRAINT_PARAMETER_VALUE, |
|
158 | - '<code><nowiki>' . htmlspecialchars( $format ) . '</nowiki></code>' ) |
|
154 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
155 | + $this->constraintParameterRenderer->formatDataValue(new StringValue($text), Role::OBJECT), |
|
156 | + $this->constraintParameterRenderer->formatByRole(Role::CONSTRAINT_PARAMETER_VALUE, |
|
157 | + '<code><nowiki>'.htmlspecialchars($format).'</nowiki></code>') |
|
159 | 158 | ); |
160 | - if ( $syntaxClarification !== null ) { |
|
161 | - $message->params( $syntaxClarification ); |
|
159 | + if ($syntaxClarification !== null) { |
|
160 | + $message->params($syntaxClarification); |
|
162 | 161 | } |
163 | 162 | $message = $message->escaped(); |
164 | 163 | $status = CheckResult::STATUS_VIOLATION; |
165 | 164 | } |
166 | 165 | } else { |
167 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
168 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
166 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
167 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
169 | 168 | $status = CheckResult::STATUS_TODO; |
170 | 169 | } |
171 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
170 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
172 | 171 | } |
173 | 172 | |
174 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
173 | + public function checkConstraintParameters(Constraint $constraint) { |
|
175 | 174 | $constraintParameters = $constraint->getConstraintParameters(); |
176 | 175 | $exceptions = []; |
177 | 176 | try { |
178 | - $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
179 | - } catch ( ConstraintParameterException $e ) { |
|
177 | + $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
178 | + } catch (ConstraintParameterException $e) { |
|
180 | 179 | $exceptions[] = $e; |
181 | 180 | } |
182 | 181 | try { |
183 | 182 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
184 | 183 | $constraintParameters, |
185 | - Language::factory( 'en' ) // errors are reported independent of language requested |
|
184 | + Language::factory('en') // errors are reported independent of language requested |
|
186 | 185 | ); |
187 | - } catch ( ConstraintParameterException $e ) { |
|
186 | + } catch (ConstraintParameterException $e) { |
|
188 | 187 | $exceptions[] = $e; |
189 | 188 | } |
190 | 189 | return $exceptions; |
@@ -71,53 +71,53 @@ |
||
71 | 71 | * @throws ConstraintParameterException |
72 | 72 | * @return CheckResult |
73 | 73 | */ |
74 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
75 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
76 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
74 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
75 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
76 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | $parameters = []; |
80 | 80 | $constraintParameters = $constraint->getConstraintParameters(); |
81 | 81 | |
82 | - $properties = $this->constraintParameterParser->parsePropertiesParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
82 | + $properties = $this->constraintParameterParser->parsePropertiesParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
83 | 83 | $parameters['property'] = $properties; |
84 | 84 | |
85 | 85 | $message = null; |
86 | 86 | $status = CheckResult::STATUS_COMPLIANCE; |
87 | 87 | |
88 | 88 | /** @var Snak $qualifier */ |
89 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
89 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
90 | 90 | $allowedQualifier = false; |
91 | - foreach ( $properties as $property ) { |
|
92 | - if ( $qualifier->getPropertyId()->equals( $property ) ) { |
|
91 | + foreach ($properties as $property) { |
|
92 | + if ($qualifier->getPropertyId()->equals($property)) { |
|
93 | 93 | $allowedQualifier = true; |
94 | 94 | break; |
95 | 95 | } |
96 | 96 | } |
97 | - if ( !$allowedQualifier ) { |
|
98 | - if ( empty( $properties ) || $properties === [ '' ] ) { |
|
99 | - $message = ( new ViolationMessage( 'wbqc-violation-message-no-qualifiers' ) ) |
|
100 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ); |
|
97 | + if (!$allowedQualifier) { |
|
98 | + if (empty($properties) || $properties === ['']) { |
|
99 | + $message = (new ViolationMessage('wbqc-violation-message-no-qualifiers')) |
|
100 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY); |
|
101 | 101 | } else { |
102 | - $message = ( new ViolationMessage( 'wbqc-violation-message-qualifiers' ) ) |
|
103 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
104 | - ->withEntityId( $qualifier->getPropertyId(), Role::QUALIFIER_PREDICATE ) |
|
105 | - ->withEntityIdList( $properties, Role::QUALIFIER_PREDICATE ); |
|
102 | + $message = (new ViolationMessage('wbqc-violation-message-qualifiers')) |
|
103 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
104 | + ->withEntityId($qualifier->getPropertyId(), Role::QUALIFIER_PREDICATE) |
|
105 | + ->withEntityIdList($properties, Role::QUALIFIER_PREDICATE); |
|
106 | 106 | } |
107 | 107 | $status = CheckResult::STATUS_VIOLATION; |
108 | 108 | break; |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
112 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
113 | 113 | } |
114 | 114 | |
115 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
115 | + public function checkConstraintParameters(Constraint $constraint) { |
|
116 | 116 | $constraintParameters = $constraint->getConstraintParameters(); |
117 | 117 | $exceptions = []; |
118 | 118 | try { |
119 | - $this->constraintParameterParser->parsePropertiesParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
120 | - } catch ( ConstraintParameterException $e ) { |
|
119 | + $this->constraintParameterParser->parsePropertiesParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
120 | + } catch (ConstraintParameterException $e) { |
|
121 | 121 | $exceptions[] = $e; |
122 | 122 | } |
123 | 123 | return $exceptions; |
@@ -74,22 +74,22 @@ discard block |
||
74 | 74 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
75 | 75 | * @return CheckResult |
76 | 76 | */ |
77 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
78 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
79 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
77 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
78 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
79 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $parameters = []; |
83 | 83 | |
84 | - if ( $this->sparqlHelper !== null ) { |
|
85 | - if ( $context->getType() === 'statement' ) { |
|
84 | + if ($this->sparqlHelper !== null) { |
|
85 | + if ($context->getType() === 'statement') { |
|
86 | 86 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
87 | 87 | $context->getSnakStatement(), |
88 | 88 | true // ignore deprecated statements |
89 | 89 | ); |
90 | 90 | } else { |
91 | - if ( $context->getSnak()->getType() !== 'value' ) { |
|
92 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
91 | + if ($context->getSnak()->getType() !== 'value') { |
|
92 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
93 | 93 | } |
94 | 94 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
95 | 95 | $context->getEntity()->getId(), |
@@ -102,27 +102,27 @@ discard block |
||
102 | 102 | $otherEntities = $result->getArray(); |
103 | 103 | $metadata = $result->getMetadata(); |
104 | 104 | |
105 | - if ( $otherEntities === [] ) { |
|
105 | + if ($otherEntities === []) { |
|
106 | 106 | $status = CheckResult::STATUS_COMPLIANCE; |
107 | 107 | $message = null; |
108 | 108 | } else { |
109 | - $otherEntities = array_values( array_filter( $otherEntities ) ); // remove nulls |
|
109 | + $otherEntities = array_values(array_filter($otherEntities)); // remove nulls |
|
110 | 110 | $status = CheckResult::STATUS_VIOLATION; |
111 | - $message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) ) |
|
112 | - ->withEntityIdList( $otherEntities, Role::SUBJECT ); |
|
111 | + $message = (new ViolationMessage('wbqc-violation-message-unique-value')) |
|
112 | + ->withEntityIdList($otherEntities, Role::SUBJECT); |
|
113 | 113 | } |
114 | 114 | } else { |
115 | 115 | $status = CheckResult::STATUS_TODO; |
116 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
117 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
116 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
117 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
118 | 118 | $metadata = Metadata::blank(); |
119 | 119 | } |
120 | 120 | |
121 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
122 | - ->withMetadata( $metadata ); |
|
121 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
122 | + ->withMetadata($metadata); |
|
123 | 123 | } |
124 | 124 | |
125 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
125 | + public function checkConstraintParameters(Constraint $constraint) { |
|
126 | 126 | // no parameters |
127 | 127 | return []; |
128 | 128 | } |
@@ -89,23 +89,23 @@ discard block |
||
89 | 89 | * @return bool |
90 | 90 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
91 | 91 | */ |
92 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
93 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
92 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
93 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
94 | 94 | if ( ++$entitiesChecked > $maxEntities ) { |
95 | - throw new OverflowException( 'Too many entities to check' ); |
|
95 | + throw new OverflowException('Too many entities to check'); |
|
96 | 96 | } |
97 | 97 | |
98 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
99 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
98 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
99 | + if (!($item instanceof StatementListProvider)) { |
|
100 | 100 | return false; // lookup failed, probably because item doesn't exist |
101 | 101 | } |
102 | 102 | |
103 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
103 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
104 | 104 | /** @var Statement $statement */ |
105 | - foreach ( $item->getStatements()->getByPropertyId( new PropertyId( $subclassId ) ) as $statement ) { |
|
105 | + foreach ($item->getStatements()->getByPropertyId(new PropertyId($subclassId)) as $statement) { |
|
106 | 106 | $mainSnak = $statement->getMainSnak(); |
107 | 107 | |
108 | - if ( !( $this->hasCorrectType( $mainSnak ) ) ) { |
|
108 | + if (!($this->hasCorrectType($mainSnak))) { |
|
109 | 109 | continue; |
110 | 110 | } |
111 | 111 | /** @var PropertyValueSnak $mainSnak */ |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | $dataValue = $mainSnak->getDataValue(); |
115 | 115 | $comparativeClass = $dataValue->getEntityId(); |
116 | 116 | |
117 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
117 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
118 | 118 | return true; |
119 | 119 | } |
120 | 120 | |
121 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
121 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
122 | 122 | return true; |
123 | 123 | } |
124 | 124 | } |
@@ -139,14 +139,14 @@ discard block |
||
139 | 139 | * @return CachedBool |
140 | 140 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
141 | 141 | */ |
142 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
142 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
143 | 143 | try { |
144 | 144 | return new CachedBool( |
145 | - $this->isSubclassOf( $comparativeClass, $classesToCheck ), |
|
145 | + $this->isSubclassOf($comparativeClass, $classesToCheck), |
|
146 | 146 | Metadata::blank() |
147 | 147 | ); |
148 | - } catch ( OverflowException $e ) { |
|
149 | - if ( $this->sparqlHelper !== null ) { |
|
148 | + } catch (OverflowException $e) { |
|
149 | + if ($this->sparqlHelper !== null) { |
|
150 | 150 | $this->dataFactory->increment( |
151 | 151 | 'wikibase.quality.constraints.sparql.typeFallback' |
152 | 152 | ); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | /* withInstance = */ false |
157 | 157 | ); |
158 | 158 | } else { |
159 | - return new CachedBool( false, Metadata::blank() ); |
|
159 | + return new CachedBool(false, Metadata::blank()); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | * @return CachedBool |
175 | 175 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
176 | 176 | */ |
177 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
177 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
178 | 178 | $metadatas = []; |
179 | 179 | |
180 | 180 | /** @var Statement $statement */ |
181 | - foreach ( $this->getStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
181 | + foreach ($this->getStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
182 | 182 | $mainSnak = $statement->getMainSnak(); |
183 | 183 | |
184 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
184 | + if (!$this->hasCorrectType($mainSnak)) { |
|
185 | 185 | continue; |
186 | 186 | } |
187 | 187 | /** @var PropertyValueSnak $mainSnak */ |
@@ -190,28 +190,28 @@ discard block |
||
190 | 190 | $dataValue = $mainSnak->getDataValue(); |
191 | 191 | $comparativeClass = $dataValue->getEntityId(); |
192 | 192 | |
193 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
193 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
194 | 194 | // discard $metadatas, we know this is fresh |
195 | - return new CachedBool( true, Metadata::blank() ); |
|
195 | + return new CachedBool(true, Metadata::blank()); |
|
196 | 196 | } |
197 | 197 | |
198 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
198 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
199 | 199 | $metadatas[] = $result->getMetadata(); |
200 | - if ( $result->getBool() ) { |
|
200 | + if ($result->getBool()) { |
|
201 | 201 | return new CachedBool( |
202 | 202 | true, |
203 | - Metadata::merge( $metadatas ) |
|
203 | + Metadata::merge($metadatas) |
|
204 | 204 | ); |
205 | 205 | } |
206 | 206 | } |
207 | 207 | |
208 | 208 | return new CachedBool( |
209 | 209 | false, |
210 | - Metadata::merge( $metadatas ) |
|
210 | + Metadata::merge($metadatas) |
|
211 | 211 | ); |
212 | 212 | } |
213 | 213 | |
214 | - private function hasCorrectType( Snak $mainSnak ) { |
|
214 | + private function hasCorrectType(Snak $mainSnak) { |
|
215 | 215 | return $mainSnak instanceof PropertyValueSnak |
216 | 216 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
217 | 217 | } |
@@ -226,12 +226,12 @@ discard block |
||
226 | 226 | array $propertyIdSerializations |
227 | 227 | ) { |
228 | 228 | $statementArrays = []; |
229 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
230 | - $propertyId = new PropertyId( $propertyIdSerialization ); |
|
231 | - $statementArrays[] = $statements->getByPropertyId( $propertyId )->toArray(); |
|
229 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
230 | + $propertyId = new PropertyId($propertyIdSerialization); |
|
231 | + $statementArrays[] = $statements->getByPropertyId($propertyId)->toArray(); |
|
232 | 232 | } |
233 | 233 | return new StatementList( |
234 | - call_user_func_array( 'array_merge', $statementArrays ) |
|
234 | + call_user_func_array('array_merge', $statementArrays) |
|
235 | 235 | ); |
236 | 236 | } |
237 | 237 | |
@@ -244,10 +244,10 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @return ViolationMessage |
246 | 246 | */ |
247 | - public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) { |
|
247 | + public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) { |
|
248 | 248 | $classes = array_map( |
249 | - function( $itemIdSerialization ) { |
|
250 | - return new ItemId( $itemIdSerialization ); |
|
249 | + function($itemIdSerialization) { |
|
250 | + return new ItemId($itemIdSerialization); |
|
251 | 251 | }, |
252 | 252 | $classes |
253 | 253 | ); |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | // wbqc-violation-message-valueType-instance |
260 | 260 | // wbqc-violation-message-valueType-subclass |
261 | 261 | // wbqc-violation-message-valueType-instanceOrSubclass |
262 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
263 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
264 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
265 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
262 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
263 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
264 | + ->withEntityId($entityId, Role::SUBJECT) |
|
265 | + ->withEntityIdList($classes, Role::OBJECT); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | } |
@@ -87,18 +87,18 @@ discard block |
||
87 | 87 | * @throws ConstraintParameterException |
88 | 88 | * @return CheckResult |
89 | 89 | */ |
90 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
91 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
92 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
90 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
91 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
92 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | $parameters = []; |
96 | 96 | $constraintParameters = $constraint->getConstraintParameters(); |
97 | 97 | |
98 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
99 | - $parameters['property'] = [ $propertyId ]; |
|
98 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
99 | + $parameters['property'] = [$propertyId]; |
|
100 | 100 | |
101 | - $items = $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
101 | + $items = $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
102 | 102 | $parameters['items'] = $items; |
103 | 103 | |
104 | 104 | /* |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | * a) a property only |
107 | 107 | * b) a property and a number of items (each combination of property and item forming an individual claim) |
108 | 108 | */ |
109 | - if ( $items === [] ) { |
|
109 | + if ($items === []) { |
|
110 | 110 | $offendingStatement = $this->connectionCheckerHelper->findStatementWithProperty( |
111 | 111 | $context->getEntity()->getStatements(), |
112 | 112 | $propertyId |
113 | 113 | ); |
114 | - if ( $offendingStatement !== null ) { |
|
115 | - $message = ( new ViolationMessage( 'wbqc-violation-message-conflicts-with-property' ) ) |
|
116 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
117 | - ->withEntityId( $propertyId, Role::PREDICATE ); |
|
114 | + if ($offendingStatement !== null) { |
|
115 | + $message = (new ViolationMessage('wbqc-violation-message-conflicts-with-property')) |
|
116 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
117 | + ->withEntityId($propertyId, Role::PREDICATE); |
|
118 | 118 | $status = CheckResult::STATUS_VIOLATION; |
119 | 119 | } else { |
120 | 120 | $message = null; |
@@ -126,12 +126,12 @@ discard block |
||
126 | 126 | $propertyId, |
127 | 127 | $items |
128 | 128 | ); |
129 | - if ( $offendingStatement !== null ) { |
|
130 | - $offendingValue = ItemIdSnakValue::fromSnak( $offendingStatement->getMainSnak() ); |
|
131 | - $message = ( new ViolationMessage( 'wbqc-violation-message-conflicts-with-claim' ) ) |
|
132 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
133 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
134 | - ->withItemIdSnakValue( $offendingValue, Role::OBJECT ); |
|
129 | + if ($offendingStatement !== null) { |
|
130 | + $offendingValue = ItemIdSnakValue::fromSnak($offendingStatement->getMainSnak()); |
|
131 | + $message = (new ViolationMessage('wbqc-violation-message-conflicts-with-claim')) |
|
132 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
133 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
134 | + ->withItemIdSnakValue($offendingValue, Role::OBJECT); |
|
135 | 135 | $status = CheckResult::STATUS_VIOLATION; |
136 | 136 | } else { |
137 | 137 | $message = null; |
@@ -139,20 +139,20 @@ discard block |
||
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
142 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
142 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
143 | 143 | } |
144 | 144 | |
145 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
145 | + public function checkConstraintParameters(Constraint $constraint) { |
|
146 | 146 | $constraintParameters = $constraint->getConstraintParameters(); |
147 | 147 | $exceptions = []; |
148 | 148 | try { |
149 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
150 | - } catch ( ConstraintParameterException $e ) { |
|
149 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
150 | + } catch (ConstraintParameterException $e) { |
|
151 | 151 | $exceptions[] = $e; |
152 | 152 | } |
153 | 153 | try { |
154 | - $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
155 | - } catch ( ConstraintParameterException $e ) { |
|
154 | + $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
155 | + } catch (ConstraintParameterException $e) { |
|
156 | 156 | $exceptions[] = $e; |
157 | 157 | } |
158 | 158 | return $exceptions; |
@@ -28,35 +28,35 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param DatabaseUpdater $updater |
30 | 30 | */ |
31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
32 | - $updater->addExtensionTable( 'wbqc_constraints', __DIR__ . '/../sql/create_wbqc_constraints.sql' ); |
|
31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
32 | + $updater->addExtensionTable('wbqc_constraints', __DIR__.'/../sql/create_wbqc_constraints.sql'); |
|
33 | 33 | } |
34 | 34 | |
35 | - public static function onWikibaseChange( Change $change ) { |
|
35 | + public static function onWikibaseChange(Change $change) { |
|
36 | 36 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
37 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
38 | - self::isConstraintStatementsChange( $config, $change ) |
|
37 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
38 | + self::isConstraintStatementsChange($config, $change) |
|
39 | 39 | ) { |
40 | 40 | /** @var EntityChange $change */ |
41 | 41 | $title = Title::newMainPage(); |
42 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
42 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
43 | 43 | JobQueueGroup::singleton()->push( |
44 | - new JobSpecification( 'constraintsTableUpdate', $params, [], $title ) |
|
44 | + new JobSpecification('constraintsTableUpdate', $params, [], $title) |
|
45 | 45 | ); |
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
49 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
50 | - if ( !( $change instanceof EntityChange ) || |
|
49 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
50 | + if (!($change instanceof EntityChange) || |
|
51 | 51 | $change->getAction() !== EntityChange::UPDATE || |
52 | - !( $change->getEntityId() instanceof PropertyId ) |
|
52 | + !($change->getEntityId() instanceof PropertyId) |
|
53 | 53 | ) { |
54 | 54 | return false; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $info = $change->getInfo(); |
58 | 58 | |
59 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
59 | + if (!array_key_exists('compactDiff', $info)) { |
|
60 | 60 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
61 | 61 | // so we only know that the change *might* affect the constraint statements |
62 | 62 | return true; |
@@ -65,18 +65,18 @@ discard block |
||
65 | 65 | /** @var EntityDiffChangedAspects $aspects */ |
66 | 66 | $aspects = $info['compactDiff']; |
67 | 67 | |
68 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
69 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
68 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
69 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
70 | 70 | } |
71 | 71 | |
72 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
72 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
73 | 73 | $repo = WikibaseRepo::getDefaultInstance(); |
74 | 74 | |
75 | 75 | $entityContentFactory = $repo->getEntityContentFactory(); |
76 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
77 | - $entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
76 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
77 | + $entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle()); |
|
78 | 78 | $resultsCache = ResultsCache::getDefaultInstance(); |
79 | - $resultsCache->delete( $entityId ); |
|
79 | + $resultsCache->delete($entityId); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
@@ -85,18 +85,18 @@ discard block |
||
85 | 85 | * @param int $timestamp UTC timestamp (seconds since the Epoch) |
86 | 86 | * @return bool |
87 | 87 | */ |
88 | - public static function isGadgetEnabledForUserName( $userName, $timestamp ) { |
|
88 | + public static function isGadgetEnabledForUserName($userName, $timestamp) { |
|
89 | 89 | $initial = $userName[0]; |
90 | 90 | |
91 | - if ( $initial === 'Z' ) { |
|
91 | + if ($initial === 'Z') { |
|
92 | 92 | $firstWeek = 0; |
93 | - } elseif ( $initial >= 'W' && $initial < 'Z' ) { |
|
93 | + } elseif ($initial >= 'W' && $initial < 'Z') { |
|
94 | 94 | $firstWeek = 1; |
95 | - } elseif ( $initial >= 'T' && $initial < 'W' ) { |
|
95 | + } elseif ($initial >= 'T' && $initial < 'W') { |
|
96 | 96 | $firstWeek = 2; |
97 | - } elseif ( $initial >= 'N' && $initial < 'T' ) { |
|
97 | + } elseif ($initial >= 'N' && $initial < 'T') { |
|
98 | 98 | $firstWeek = 3; |
99 | - } elseif ( $initial >= 'E' && $initial < 'N' ) { |
|
99 | + } elseif ($initial >= 'E' && $initial < 'N') { |
|
100 | 100 | $firstWeek = 4; |
101 | 101 | } else { |
102 | 102 | $firstWeek = 5; |
@@ -114,27 +114,27 @@ discard block |
||
114 | 114 | return $timestamp >= $threshold; |
115 | 115 | } |
116 | 116 | |
117 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
117 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
118 | 118 | $repo = WikibaseRepo::getDefaultInstance(); |
119 | 119 | |
120 | 120 | $lookup = $repo->getEntityNamespaceLookup(); |
121 | 121 | $title = $out->getTitle(); |
122 | - if ( $title === null ) { |
|
122 | + if ($title === null) { |
|
123 | 123 | return; |
124 | 124 | } |
125 | 125 | |
126 | - if ( !$lookup->isEntityNamespace( $title->getNamespace() ) ) { |
|
126 | + if (!$lookup->isEntityNamespace($title->getNamespace())) { |
|
127 | 127 | return; |
128 | 128 | } |
129 | - if ( !$out->getUser()->isLoggedIn() ) { |
|
129 | + if (!$out->getUser()->isLoggedIn()) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
132 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | - if ( self::isGadgetEnabledForUserName( $out->getUser()->getName(), time() ) ) { |
|
137 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
136 | + if (self::isGadgetEnabledForUserName($out->getUser()->getName(), time())) { |
|
137 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 |
@@ -68,41 +68,41 @@ |
||
68 | 68 | * @throws ConstraintParameterException |
69 | 69 | * @return CheckResult |
70 | 70 | */ |
71 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
72 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
73 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
71 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
72 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
73 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | $parameters = []; |
77 | 77 | $constraintParameters = $constraint->getConstraintParameters(); |
78 | 78 | |
79 | - $items = $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), true ); |
|
79 | + $items = $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), true); |
|
80 | 80 | $parameters['item'] = $items; |
81 | 81 | |
82 | 82 | $snak = $context->getSnak(); |
83 | 83 | |
84 | - $message = ( new ViolationMessage( 'wbqc-violation-message-one-of' ) ) |
|
85 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
86 | - ->withItemIdSnakValueList( $items, Role::OBJECT ); |
|
84 | + $message = (new ViolationMessage('wbqc-violation-message-one-of')) |
|
85 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
86 | + ->withItemIdSnakValueList($items, Role::OBJECT); |
|
87 | 87 | $status = CheckResult::STATUS_VIOLATION; |
88 | 88 | |
89 | - foreach ( $items as $item ) { |
|
90 | - if ( $item->matchesSnak( $snak ) ) { |
|
89 | + foreach ($items as $item) { |
|
90 | + if ($item->matchesSnak($snak)) { |
|
91 | 91 | $message = null; |
92 | 92 | $status = CheckResult::STATUS_COMPLIANCE; |
93 | 93 | break; |
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
97 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
98 | 98 | } |
99 | 99 | |
100 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
100 | + public function checkConstraintParameters(Constraint $constraint) { |
|
101 | 101 | $constraintParameters = $constraint->getConstraintParameters(); |
102 | 102 | $exceptions = []; |
103 | 103 | try { |
104 | - $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), true ); |
|
105 | - } catch ( ConstraintParameterException $e ) { |
|
104 | + $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), true); |
|
105 | + } catch (ConstraintParameterException $e) { |
|
106 | 106 | $exceptions[] = $e; |
107 | 107 | } |
108 | 108 | return $exceptions; |