@@ -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,28 +102,28 @@ 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 | 109 | $status = CheckResult::STATUS_VIOLATION; |
110 | - $message = wfMessage( 'wbqc-violation-message-unique-value' ) |
|
111 | - ->numParams( count( $otherEntities ) ) |
|
112 | - ->rawParams( $this->constraintParameterRenderer->formatEntityIdList( $otherEntities, Role::SUBJECT ) ) |
|
110 | + $message = wfMessage('wbqc-violation-message-unique-value') |
|
111 | + ->numParams(count($otherEntities)) |
|
112 | + ->rawParams($this->constraintParameterRenderer->formatEntityIdList($otherEntities, Role::SUBJECT)) |
|
113 | 113 | ->escaped(); |
114 | 114 | } |
115 | 115 | } else { |
116 | 116 | $status = CheckResult::STATUS_TODO; |
117 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
118 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
117 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
118 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
119 | 119 | $metadata = Metadata::blank(); |
120 | 120 | } |
121 | 121 | |
122 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
123 | - ->withMetadata( $metadata ); |
|
122 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
123 | + ->withMetadata($metadata); |
|
124 | 124 | } |
125 | 125 | |
126 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
126 | + public function checkConstraintParameters(Constraint $constraint) { |
|
127 | 127 | // no parameters |
128 | 128 | return []; |
129 | 129 | } |
@@ -90,22 +90,22 @@ discard block |
||
90 | 90 | * @throws ConstraintParameterException |
91 | 91 | * @return CheckResult |
92 | 92 | */ |
93 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
94 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
95 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
93 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
94 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
95 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | $parameters = []; |
99 | 99 | $constraintParameters = $constraint->getConstraintParameters(); |
100 | 100 | |
101 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
102 | - $parameters['property'] = [ $propertyId ]; |
|
101 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
102 | + $parameters['property'] = [$propertyId]; |
|
103 | 103 | |
104 | 104 | $snak = $context->getSnak(); |
105 | 105 | |
106 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
106 | + if (!$snak instanceof PropertyValueSnak) { |
|
107 | 107 | // nothing to check |
108 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
108 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | $dataValue = $snak->getDataValue(); |
@@ -114,22 +114,22 @@ discard block |
||
114 | 114 | * error handling: |
115 | 115 | * type of $dataValue for properties with 'Inverse' constraint has to be 'wikibase-entityid' |
116 | 116 | */ |
117 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
118 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
117 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
118 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
119 | 119 | ->rawParams( |
120 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
120 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
121 | 121 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
122 | 122 | ) |
123 | 123 | ->escaped(); |
124 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
124 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
125 | 125 | } |
126 | 126 | /** @var EntityIdValue $dataValue */ |
127 | 127 | |
128 | 128 | $targetEntityId = $dataValue->getEntityId(); |
129 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
130 | - if ( $targetEntity === null ) { |
|
131 | - $message = new ViolationMessage( 'wbqc-violation-message-target-entity-must-exist' ); |
|
132 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
129 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
130 | + if ($targetEntity === null) { |
|
131 | + $message = new ViolationMessage('wbqc-violation-message-target-entity-must-exist'); |
|
132 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | $inverseStatement = $this->connectionCheckerHelper->findStatementWithPropertyAndEntityIdValue( |
@@ -137,28 +137,28 @@ discard block |
||
137 | 137 | $propertyId, |
138 | 138 | $context->getEntity()->getId() |
139 | 139 | ); |
140 | - if ( $inverseStatement !== null ) { |
|
140 | + if ($inverseStatement !== null) { |
|
141 | 141 | $message = null; |
142 | 142 | $status = CheckResult::STATUS_COMPLIANCE; |
143 | 143 | } else { |
144 | - $message = ( new ViolationMessage( 'wbqc-violation-message-inverse' ) ) |
|
145 | - ->withEntityId( $targetEntityId, Role::SUBJECT ) |
|
146 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
147 | - ->withEntityId( $context->getEntity()->getId(), Role::OBJECT ); |
|
144 | + $message = (new ViolationMessage('wbqc-violation-message-inverse')) |
|
145 | + ->withEntityId($targetEntityId, Role::SUBJECT) |
|
146 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
147 | + ->withEntityId($context->getEntity()->getId(), Role::OBJECT); |
|
148 | 148 | $status = CheckResult::STATUS_VIOLATION; |
149 | 149 | } |
150 | 150 | |
151 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
152 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
153 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
151 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
152 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
153 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
154 | 154 | } |
155 | 155 | |
156 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
156 | + public function checkConstraintParameters(Constraint $constraint) { |
|
157 | 157 | $constraintParameters = $constraint->getConstraintParameters(); |
158 | 158 | $exceptions = []; |
159 | 159 | try { |
160 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
161 | - } catch ( ConstraintParameterException $e ) { |
|
160 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
161 | + } catch (ConstraintParameterException $e) { |
|
162 | 162 | $exceptions[] = $e; |
163 | 163 | } |
164 | 164 | return $exceptions; |
@@ -71,41 +71,41 @@ discard block |
||
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 = wfMessage( "wbqc-violation-message-qualifiers" ); |
|
102 | + $message = wfMessage("wbqc-violation-message-qualifiers"); |
|
103 | 103 | $message->rawParams( |
104 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
105 | - $this->constraintParameterRenderer->formatEntityId( $qualifier->getPropertyId(), Role::QUALIFIER_PREDICATE ) |
|
104 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
105 | + $this->constraintParameterRenderer->formatEntityId($qualifier->getPropertyId(), Role::QUALIFIER_PREDICATE) |
|
106 | 106 | ); |
107 | - $message->numParams( count( $properties ) ); |
|
108 | - $message->rawParams( $this->constraintParameterRenderer->formatPropertyIdList( $properties, Role::QUALIFIER_PREDICATE ) ); |
|
107 | + $message->numParams(count($properties)); |
|
108 | + $message->rawParams($this->constraintParameterRenderer->formatPropertyIdList($properties, Role::QUALIFIER_PREDICATE)); |
|
109 | 109 | $message = $message->escaped(); |
110 | 110 | } |
111 | 111 | $status = CheckResult::STATUS_VIOLATION; |
@@ -113,15 +113,15 @@ discard block |
||
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
116 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
117 | 117 | } |
118 | 118 | |
119 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
119 | + public function checkConstraintParameters(Constraint $constraint) { |
|
120 | 120 | $constraintParameters = $constraint->getConstraintParameters(); |
121 | 121 | $exceptions = []; |
122 | 122 | try { |
123 | - $this->constraintParameterParser->parsePropertiesParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
124 | - } catch ( ConstraintParameterException $e ) { |
|
123 | + $this->constraintParameterParser->parsePropertiesParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
124 | + } catch (ConstraintParameterException $e) { |
|
125 | 125 | $exceptions[] = $e; |
126 | 126 | } |
127 | 127 | return $exceptions; |
@@ -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,13 +126,13 @@ discard block |
||
126 | 126 | $propertyId, |
127 | 127 | $items |
128 | 128 | ); |
129 | - if ( $offendingStatement !== null ) { |
|
130 | - $offendingValue = ItemIdSnakValue::fromSnak( $offendingStatement->getMainSnak() ); |
|
131 | - $message = wfMessage( "wbqc-violation-message-conflicts-with-claim" ) |
|
129 | + if ($offendingStatement !== null) { |
|
130 | + $offendingValue = ItemIdSnakValue::fromSnak($offendingStatement->getMainSnak()); |
|
131 | + $message = wfMessage("wbqc-violation-message-conflicts-with-claim") |
|
132 | 132 | ->rawParams( |
133 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
134 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::PREDICATE ), |
|
135 | - $this->constraintParameterRenderer->formatItemIdSnakValue( $offendingValue, Role::OBJECT ) |
|
133 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
134 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::PREDICATE), |
|
135 | + $this->constraintParameterRenderer->formatItemIdSnakValue($offendingValue, Role::OBJECT) |
|
136 | 136 | ) |
137 | 137 | ->escaped(); |
138 | 138 | $status = CheckResult::STATUS_VIOLATION; |
@@ -142,20 +142,20 @@ discard block |
||
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
145 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
146 | 146 | } |
147 | 147 | |
148 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
148 | + public function checkConstraintParameters(Constraint $constraint) { |
|
149 | 149 | $constraintParameters = $constraint->getConstraintParameters(); |
150 | 150 | $exceptions = []; |
151 | 151 | try { |
152 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
153 | - } catch ( ConstraintParameterException $e ) { |
|
152 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
153 | + } catch (ConstraintParameterException $e) { |
|
154 | 154 | $exceptions[] = $e; |
155 | 155 | } |
156 | 156 | try { |
157 | - $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
158 | - } catch ( ConstraintParameterException $e ) { |
|
157 | + $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
158 | + } catch (ConstraintParameterException $e) { |
|
159 | 159 | $exceptions[] = $e; |
160 | 160 | } |
161 | 161 | return $exceptions; |
@@ -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; |