@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Result; |
6 | 6 | |
@@ -27,22 +27,22 @@ discard block |
||
27 | 27 | */ |
28 | 28 | private const NULL_PROPERTY_ID = 'P2147483647'; |
29 | 29 | |
30 | - public function __construct( ContextCursor $contextCursor ) { |
|
30 | + public function __construct(ContextCursor $contextCursor) { |
|
31 | 31 | $constraint = new Constraint( |
32 | 32 | 'null', |
33 | - new NumericPropertyId( self::NULL_PROPERTY_ID ), |
|
33 | + new NumericPropertyId(self::NULL_PROPERTY_ID), |
|
34 | 34 | 'none', |
35 | 35 | [] |
36 | 36 | ); |
37 | - parent::__construct( $contextCursor, $constraint ); |
|
37 | + parent::__construct($contextCursor, $constraint); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public function getConstraint(): Constraint { |
41 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
41 | + throw new DomainException('NullResult holds no constraint'); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function getConstraintId(): string { |
45 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
45 | + throw new DomainException('NullResult holds no constraint'); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Result; |
6 | 6 | |
@@ -59,14 +59,14 @@ discard block |
||
59 | 59 | $this->serializeDependencyMetadata = $serializeDependencyMetadata; |
60 | 60 | } |
61 | 61 | |
62 | - public function serialize( CheckResult $checkResult ): array { |
|
62 | + public function serialize(CheckResult $checkResult): array { |
|
63 | 63 | $contextCursor = $checkResult->getContextCursor(); |
64 | 64 | |
65 | 65 | $serialization = [ |
66 | - self::KEY_CONTEXT_CURSOR => $this->contextCursorSerializer->serialize( $contextCursor ), |
|
66 | + self::KEY_CONTEXT_CURSOR => $this->contextCursorSerializer->serialize($contextCursor), |
|
67 | 67 | ]; |
68 | 68 | |
69 | - if ( $checkResult instanceof NullResult ) { |
|
69 | + if ($checkResult instanceof NullResult) { |
|
70 | 70 | $serialization[self::KEY_NULL_RESULT] = 1; |
71 | 71 | } else { |
72 | 72 | $constraint = $checkResult->getConstraint(); |
@@ -74,53 +74,53 @@ discard block |
||
74 | 74 | $violationMessage = $checkResult->getMessage(); |
75 | 75 | |
76 | 76 | $serialization[self::KEY_CONSTRAINT] = |
77 | - $this->constraintSerializer->serialize( $constraint ); |
|
77 | + $this->constraintSerializer->serialize($constraint); |
|
78 | 78 | $serialization[self::KEY_CHECK_RESULT_STATUS] = |
79 | 79 | $checkResult->getStatus(); |
80 | 80 | $serialization[self::KEY_CACHING_METADATA] = |
81 | - $this->serializeCachingMetadata( $cachingMetadata ); |
|
81 | + $this->serializeCachingMetadata($cachingMetadata); |
|
82 | 82 | |
83 | - if ( $violationMessage !== null ) { |
|
83 | + if ($violationMessage !== null) { |
|
84 | 84 | $serialization[self::KEY_VIOLATION_MESSAGE] = |
85 | - $this->violationMessageSerializer->serialize( $violationMessage ); |
|
85 | + $this->violationMessageSerializer->serialize($violationMessage); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
89 | - if ( $this->serializeDependencyMetadata ) { |
|
89 | + if ($this->serializeDependencyMetadata) { |
|
90 | 90 | $serialization[self::KEY_DEPENDENCY_METADATA] = |
91 | - $this->serializeDependencyMetadata( $checkResult ); |
|
91 | + $this->serializeDependencyMetadata($checkResult); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | return $serialization; |
95 | 95 | } |
96 | 96 | |
97 | - private function serializeCachingMetadata( CachingMetadata $cachingMetadata ): array { |
|
97 | + private function serializeCachingMetadata(CachingMetadata $cachingMetadata): array { |
|
98 | 98 | $maximumAge = $cachingMetadata->getMaximumAgeInSeconds(); |
99 | 99 | |
100 | 100 | $serialization = []; |
101 | 101 | |
102 | - if ( $maximumAge > 0 ) { |
|
102 | + if ($maximumAge > 0) { |
|
103 | 103 | $serialization[self::KEY_CACHING_METADATA_MAX_AGE] = $maximumAge; |
104 | 104 | } |
105 | 105 | |
106 | 106 | return $serialization; |
107 | 107 | } |
108 | 108 | |
109 | - private function serializeDependencyMetadata( CheckResult $checkResult ): array { |
|
109 | + private function serializeDependencyMetadata(CheckResult $checkResult): array { |
|
110 | 110 | $dependencyMetadata = $checkResult->getMetadata()->getDependencyMetadata(); |
111 | 111 | $entityIds = $dependencyMetadata->getEntityIds(); |
112 | 112 | $futureTime = $dependencyMetadata->getFutureTime(); |
113 | 113 | |
114 | 114 | $serialization = [ |
115 | 115 | self::KEY_DEPENDENCY_METADATA_ENTITY_IDS => array_map( |
116 | - static function ( EntityId $entityId ) { |
|
116 | + static function(EntityId $entityId) { |
|
117 | 117 | return $entityId->getSerialization(); |
118 | 118 | }, |
119 | 119 | $entityIds |
120 | 120 | ), |
121 | 121 | ]; |
122 | 122 | |
123 | - if ( $futureTime !== null ) { |
|
123 | + if ($futureTime !== null) { |
|
124 | 124 | $serialization[self::KEY_DEPENDENCY_METADATA_FUTURE_TIME] = |
125 | 125 | $futureTime->getArrayValue(); |
126 | 126 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Helper; |
6 | 6 | |
@@ -68,15 +68,15 @@ discard block |
||
68 | 68 | * Check if any errors are recorded in the constraint parameters. |
69 | 69 | * @throws ConstraintParameterException |
70 | 70 | */ |
71 | - public function checkError( array $parameters ): void { |
|
72 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
71 | + public function checkError(array $parameters): void { |
|
72 | + if (array_key_exists('@error', $parameters)) { |
|
73 | 73 | $error = $parameters['@error']; |
74 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
74 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
75 | 75 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
76 | 76 | } else { |
77 | 77 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
78 | 78 | } |
79 | - throw new ConstraintParameterException( new ViolationMessage( $msg ) ); |
|
79 | + throw new ConstraintParameterException(new ViolationMessage($msg)); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | * Require that $parameters contains exactly one $parameterId parameter. |
85 | 85 | * @throws ConstraintParameterException |
86 | 86 | */ |
87 | - private function requireSingleParameter( array $parameters, string $parameterId ): void { |
|
88 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
87 | + private function requireSingleParameter(array $parameters, string $parameterId): void { |
|
88 | + if (count($parameters[$parameterId]) !== 1) { |
|
89 | 89 | throw new ConstraintParameterException( |
90 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) ) |
|
91 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
90 | + (new ViolationMessage('wbqc-violation-message-parameter-single')) |
|
91 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
92 | 92 | ); |
93 | 93 | } |
94 | 94 | } |
@@ -97,11 +97,11 @@ discard block |
||
97 | 97 | * Require that $snak is a {@link PropertyValueSnak}. |
98 | 98 | * @throws ConstraintParameterException |
99 | 99 | */ |
100 | - private function requireValueParameter( Snak $snak, string $parameterId ): void { |
|
101 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
100 | + private function requireValueParameter(Snak $snak, string $parameterId): void { |
|
101 | + if (!($snak instanceof PropertyValueSnak)) { |
|
102 | 102 | throw new ConstraintParameterException( |
103 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
104 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
103 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
104 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
105 | 105 | ); |
106 | 106 | } |
107 | 107 | } |
@@ -110,17 +110,17 @@ discard block |
||
110 | 110 | * Parse a single entity ID parameter. |
111 | 111 | * @throws ConstraintParameterException |
112 | 112 | */ |
113 | - private function parseEntityIdParameter( array $snakSerialization, string $parameterId ): EntityId { |
|
114 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
115 | - $this->requireValueParameter( $snak, $parameterId ); |
|
113 | + private function parseEntityIdParameter(array $snakSerialization, string $parameterId): EntityId { |
|
114 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
115 | + $this->requireValueParameter($snak, $parameterId); |
|
116 | 116 | $value = $snak->getDataValue(); |
117 | - if ( $value instanceof EntityIdValue ) { |
|
117 | + if ($value instanceof EntityIdValue) { |
|
118 | 118 | return $value->getEntityId(); |
119 | 119 | } else { |
120 | 120 | throw new ConstraintParameterException( |
121 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) ) |
|
122 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
123 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
121 | + (new ViolationMessage('wbqc-violation-message-parameter-entity')) |
|
122 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
123 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
124 | 124 | ); |
125 | 125 | } |
126 | 126 | } |
@@ -131,20 +131,20 @@ discard block |
||
131 | 131 | * @throws ConstraintParameterException if the parameter is invalid or missing |
132 | 132 | * @return string[] class entity ID serializations |
133 | 133 | */ |
134 | - public function parseClassParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
135 | - $this->checkError( $constraintParameters ); |
|
136 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
137 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
134 | + public function parseClassParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
135 | + $this->checkError($constraintParameters); |
|
136 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
137 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
138 | 138 | throw new ConstraintParameterException( |
139 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
140 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
141 | - ->withEntityId( new NumericPropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
139 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
140 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
141 | + ->withEntityId(new NumericPropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
142 | 142 | ); |
143 | 143 | } |
144 | 144 | |
145 | 145 | $classes = []; |
146 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
147 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
146 | + foreach ($constraintParameters[$classId] as $class) { |
|
147 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
148 | 148 | } |
149 | 149 | return $classes; |
150 | 150 | } |
@@ -155,31 +155,31 @@ discard block |
||
155 | 155 | * @throws ConstraintParameterException if the parameter is invalid or missing |
156 | 156 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
157 | 157 | */ |
158 | - public function parseRelationParameter( array $constraintParameters, string $constraintTypeItemId ): string { |
|
159 | - $this->checkError( $constraintParameters ); |
|
160 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
161 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
158 | + public function parseRelationParameter(array $constraintParameters, string $constraintTypeItemId): string { |
|
159 | + $this->checkError($constraintParameters); |
|
160 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
161 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
162 | 162 | throw new ConstraintParameterException( |
163 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
164 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
165 | - ->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
163 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
164 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
165 | + ->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
166 | 166 | ); |
167 | 167 | } |
168 | 168 | |
169 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
170 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
171 | - if ( !( $relationEntityId instanceof ItemId ) ) { |
|
169 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
170 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
171 | + if (!($relationEntityId instanceof ItemId)) { |
|
172 | 172 | throw new ConstraintParameterException( |
173 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
174 | - ->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
175 | - ->withDataValue( new EntityIdValue( $relationEntityId ), Role::CONSTRAINT_PARAMETER_VALUE ) |
|
173 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
174 | + ->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
175 | + ->withDataValue(new EntityIdValue($relationEntityId), Role::CONSTRAINT_PARAMETER_VALUE) |
|
176 | 176 | ); |
177 | 177 | } |
178 | - return $this->mapItemId( $relationEntityId, [ |
|
179 | - $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ) => 'instance', |
|
180 | - $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ) => 'subclass', |
|
181 | - $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ) => 'instanceOrSubclass', |
|
182 | - ], $relationId ); |
|
178 | + return $this->mapItemId($relationEntityId, [ |
|
179 | + $this->config->get('WBQualityConstraintsInstanceOfRelationId') => 'instance', |
|
180 | + $this->config->get('WBQualityConstraintsSubclassOfRelationId') => 'subclass', |
|
181 | + $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId') => 'instanceOrSubclass', |
|
182 | + ], $relationId); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -189,20 +189,20 @@ discard block |
||
189 | 189 | * @throws ConstraintParameterException |
190 | 190 | * @return PropertyId |
191 | 191 | */ |
192 | - private function parsePropertyIdParameter( array $snakSerialization, string $parameterId ): PropertyId { |
|
193 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
194 | - $this->requireValueParameter( $snak, $parameterId ); |
|
192 | + private function parsePropertyIdParameter(array $snakSerialization, string $parameterId): PropertyId { |
|
193 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
194 | + $this->requireValueParameter($snak, $parameterId); |
|
195 | 195 | $value = $snak->getDataValue(); |
196 | - if ( $value instanceof EntityIdValue ) { |
|
196 | + if ($value instanceof EntityIdValue) { |
|
197 | 197 | $id = $value->getEntityId(); |
198 | - if ( $id instanceof PropertyId ) { |
|
198 | + if ($id instanceof PropertyId) { |
|
199 | 199 | return $id; |
200 | 200 | } |
201 | 201 | } |
202 | 202 | throw new ConstraintParameterException( |
203 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) ) |
|
204 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
205 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
203 | + (new ViolationMessage('wbqc-violation-message-parameter-property')) |
|
204 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
205 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
206 | 206 | ); |
207 | 207 | } |
208 | 208 | |
@@ -213,33 +213,33 @@ discard block |
||
213 | 213 | * @throws ConstraintParameterException if the parameter is invalid or missing |
214 | 214 | * @return PropertyId |
215 | 215 | */ |
216 | - public function parsePropertyParameter( array $constraintParameters, string $constraintTypeItemId ): PropertyId { |
|
217 | - $this->checkError( $constraintParameters ); |
|
218 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
219 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
216 | + public function parsePropertyParameter(array $constraintParameters, string $constraintTypeItemId): PropertyId { |
|
217 | + $this->checkError($constraintParameters); |
|
218 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
219 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
220 | 220 | throw new ConstraintParameterException( |
221 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
222 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
223 | - ->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
221 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
222 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
223 | + ->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
224 | 224 | ); |
225 | 225 | } |
226 | 226 | |
227 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
228 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
227 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
228 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
229 | 229 | } |
230 | 230 | |
231 | - private function parseItemIdParameter( PropertyValueSnak $snak, string $parameterId ): ItemIdSnakValue { |
|
231 | + private function parseItemIdParameter(PropertyValueSnak $snak, string $parameterId): ItemIdSnakValue { |
|
232 | 232 | $dataValue = $snak->getDataValue(); |
233 | - if ( $dataValue instanceof EntityIdValue ) { |
|
233 | + if ($dataValue instanceof EntityIdValue) { |
|
234 | 234 | $entityId = $dataValue->getEntityId(); |
235 | - if ( $entityId instanceof ItemId ) { |
|
236 | - return ItemIdSnakValue::fromItemId( $entityId ); |
|
235 | + if ($entityId instanceof ItemId) { |
|
236 | + return ItemIdSnakValue::fromItemId($entityId); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | throw new ConstraintParameterException( |
240 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
241 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
242 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
240 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
241 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
242 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
243 | 243 | ); |
244 | 244 | } |
245 | 245 | |
@@ -257,16 +257,16 @@ discard block |
||
257 | 257 | bool $required, |
258 | 258 | string $parameterId = null |
259 | 259 | ): array { |
260 | - $this->checkError( $constraintParameters ); |
|
261 | - if ( $parameterId === null ) { |
|
262 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
260 | + $this->checkError($constraintParameters); |
|
261 | + if ($parameterId === null) { |
|
262 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
263 | 263 | } |
264 | - if ( !array_key_exists( $parameterId, $constraintParameters ) ) { |
|
265 | - if ( $required ) { |
|
264 | + if (!array_key_exists($parameterId, $constraintParameters)) { |
|
265 | + if ($required) { |
|
266 | 266 | throw new ConstraintParameterException( |
267 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
268 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
269 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
267 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
268 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
269 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
270 | 270 | ); |
271 | 271 | } else { |
272 | 272 | return []; |
@@ -274,11 +274,11 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | $values = []; |
277 | - foreach ( $constraintParameters[$parameterId] as $parameter ) { |
|
278 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
279 | - switch ( true ) { |
|
277 | + foreach ($constraintParameters[$parameterId] as $parameter) { |
|
278 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
279 | + switch (true) { |
|
280 | 280 | case $snak instanceof PropertyValueSnak: |
281 | - $values[] = $this->parseItemIdParameter( $snak, $parameterId ); |
|
281 | + $values[] = $this->parseItemIdParameter($snak, $parameterId); |
|
282 | 282 | break; |
283 | 283 | case $snak instanceof PropertySomeValueSnak: |
284 | 284 | $values[] = ItemIdSnakValue::someValue(); |
@@ -306,13 +306,13 @@ discard block |
||
306 | 306 | bool $required, |
307 | 307 | string $parameterId |
308 | 308 | ): array { |
309 | - return array_map( static function ( ItemIdSnakValue $value ) use ( $parameterId ): ItemId { |
|
310 | - if ( $value->isValue() ) { |
|
309 | + return array_map(static function(ItemIdSnakValue $value) use ($parameterId): ItemId { |
|
310 | + if ($value->isValue()) { |
|
311 | 311 | return $value->getItemId(); |
312 | 312 | } else { |
313 | 313 | throw new ConstraintParameterException( |
314 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
315 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
314 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
315 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
316 | 316 | ); |
317 | 317 | } |
318 | 318 | }, $this->parseItemsParameter( |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | $constraintTypeItemId, |
321 | 321 | $required, |
322 | 322 | $parameterId |
323 | - ) ); |
|
323 | + )); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -328,18 +328,18 @@ discard block |
||
328 | 328 | * @throws ConstraintParameterException |
329 | 329 | * @return mixed elements of $mapping |
330 | 330 | */ |
331 | - private function mapItemId( ItemId $itemId, array $mapping, string $parameterId ) { |
|
331 | + private function mapItemId(ItemId $itemId, array $mapping, string $parameterId) { |
|
332 | 332 | $serialization = $itemId->getSerialization(); |
333 | - if ( array_key_exists( $serialization, $mapping ) ) { |
|
333 | + if (array_key_exists($serialization, $mapping)) { |
|
334 | 334 | return $mapping[$serialization]; |
335 | 335 | } else { |
336 | - $allowed = array_map( static function ( $id ) { |
|
337 | - return new ItemId( $id ); |
|
338 | - }, array_keys( $mapping ) ); |
|
336 | + $allowed = array_map(static function($id) { |
|
337 | + return new ItemId($id); |
|
338 | + }, array_keys($mapping)); |
|
339 | 339 | throw new ConstraintParameterException( |
340 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
341 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
342 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
340 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
341 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
342 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
343 | 343 | ); |
344 | 344 | } |
345 | 345 | } |
@@ -350,27 +350,27 @@ discard block |
||
350 | 350 | * @throws ConstraintParameterException if the parameter is invalid or missing |
351 | 351 | * @return PropertyId[] |
352 | 352 | */ |
353 | - public function parsePropertiesParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
354 | - $this->checkError( $constraintParameters ); |
|
355 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
356 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
353 | + public function parsePropertiesParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
354 | + $this->checkError($constraintParameters); |
|
355 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
356 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
357 | 357 | throw new ConstraintParameterException( |
358 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
359 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
360 | - ->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
358 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
359 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
360 | + ->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
361 | 361 | ); |
362 | 362 | } |
363 | 363 | |
364 | 364 | $parameters = $constraintParameters[$propertyId]; |
365 | - if ( count( $parameters ) === 1 && |
|
366 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
365 | + if (count($parameters) === 1 && |
|
366 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
367 | 367 | ) { |
368 | 368 | return []; |
369 | 369 | } |
370 | 370 | |
371 | 371 | $properties = []; |
372 | - foreach ( $parameters as $parameter ) { |
|
373 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
372 | + foreach ($parameters as $parameter) { |
|
373 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
374 | 374 | } |
375 | 375 | return $properties; |
376 | 376 | } |
@@ -378,24 +378,24 @@ discard block |
||
378 | 378 | /** |
379 | 379 | * @throws ConstraintParameterException |
380 | 380 | */ |
381 | - private function parseValueOrNoValueParameter( array $snakSerialization, string $parameterId ): ?DataValue { |
|
382 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
383 | - if ( $snak instanceof PropertyValueSnak ) { |
|
381 | + private function parseValueOrNoValueParameter(array $snakSerialization, string $parameterId): ?DataValue { |
|
382 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
383 | + if ($snak instanceof PropertyValueSnak) { |
|
384 | 384 | return $snak->getDataValue(); |
385 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
385 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
386 | 386 | return null; |
387 | 387 | } else { |
388 | 388 | throw new ConstraintParameterException( |
389 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
390 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
389 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
390 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
391 | 391 | ); |
392 | 392 | } |
393 | 393 | } |
394 | 394 | |
395 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, string $parameterId ): ?DataValue { |
|
395 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, string $parameterId): ?DataValue { |
|
396 | 396 | try { |
397 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
398 | - } catch ( ConstraintParameterException $e ) { |
|
397 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
398 | + } catch (ConstraintParameterException $e) { |
|
399 | 399 | // unknown value means “now” |
400 | 400 | return new NowValue(); |
401 | 401 | } |
@@ -404,14 +404,14 @@ discard block |
||
404 | 404 | /** |
405 | 405 | * Checks whether there is exactly one non-null quantity with the given unit. |
406 | 406 | */ |
407 | - private function exactlyOneQuantityWithUnit( ?DataValue $min, ?DataValue $max, string $unit ): bool { |
|
408 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
409 | - !( $max instanceof UnboundedQuantityValue ) |
|
407 | + private function exactlyOneQuantityWithUnit(?DataValue $min, ?DataValue $max, string $unit): bool { |
|
408 | + if (!($min instanceof UnboundedQuantityValue) || |
|
409 | + !($max instanceof UnboundedQuantityValue) |
|
410 | 410 | ) { |
411 | 411 | return false; |
412 | 412 | } |
413 | 413 | |
414 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
414 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
@@ -431,41 +431,41 @@ discard block |
||
431 | 431 | string $constraintTypeItemId, |
432 | 432 | string $type |
433 | 433 | ): array { |
434 | - $this->checkError( $constraintParameters ); |
|
435 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
436 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
434 | + $this->checkError($constraintParameters); |
|
435 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
436 | + !array_key_exists($maximumId, $constraintParameters) |
|
437 | 437 | ) { |
438 | 438 | throw new ConstraintParameterException( |
439 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) ) |
|
440 | - ->withDataValueType( $type ) |
|
441 | - ->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
442 | - ->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
443 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
439 | + (new ViolationMessage('wbqc-violation-message-range-parameters-needed')) |
|
440 | + ->withDataValueType($type) |
|
441 | + ->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
442 | + ->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
443 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
444 | 444 | ); |
445 | 445 | } |
446 | 446 | |
447 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
448 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
447 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
448 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
449 | 449 | $parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
450 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
451 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
450 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
451 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
452 | 452 | |
453 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
454 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
453 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
454 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
455 | 455 | throw new ConstraintParameterException( |
456 | - new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
456 | + new ViolationMessage('wbqc-violation-message-range-parameters-one-year') |
|
457 | 457 | ); |
458 | 458 | } |
459 | - if ( $min === null && $max === null || |
|
460 | - $min !== null && $max !== null && $min->equals( $max ) ) { |
|
459 | + if ($min === null && $max === null || |
|
460 | + $min !== null && $max !== null && $min->equals($max)) { |
|
461 | 461 | throw new ConstraintParameterException( |
462 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) ) |
|
463 | - ->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
464 | - ->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
462 | + (new ViolationMessage('wbqc-violation-message-range-parameters-same')) |
|
463 | + ->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
464 | + ->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
465 | 465 | ); |
466 | 466 | } |
467 | 467 | |
468 | - return [ $min, $max ]; |
|
468 | + return [$min, $max]; |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
@@ -475,11 +475,11 @@ discard block |
||
475 | 475 | * @throws ConstraintParameterException if the parameter is invalid or missing |
476 | 476 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
477 | 477 | */ |
478 | - public function parseQuantityRangeParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
478 | + public function parseQuantityRangeParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
479 | 479 | return $this->parseRangeParameter( |
480 | 480 | $constraintParameters, |
481 | - $this->config->get( 'WBQualityConstraintsMinimumQuantityId' ), |
|
482 | - $this->config->get( 'WBQualityConstraintsMaximumQuantityId' ), |
|
481 | + $this->config->get('WBQualityConstraintsMinimumQuantityId'), |
|
482 | + $this->config->get('WBQualityConstraintsMaximumQuantityId'), |
|
483 | 483 | $constraintTypeItemId, |
484 | 484 | 'quantity' |
485 | 485 | ); |
@@ -492,11 +492,11 @@ discard block |
||
492 | 492 | * @throws ConstraintParameterException if the parameter is invalid or missing |
493 | 493 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
494 | 494 | */ |
495 | - public function parseTimeRangeParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
495 | + public function parseTimeRangeParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
496 | 496 | return $this->parseRangeParameter( |
497 | 497 | $constraintParameters, |
498 | - $this->config->get( 'WBQualityConstraintsMinimumDateId' ), |
|
499 | - $this->config->get( 'WBQualityConstraintsMaximumDateId' ), |
|
498 | + $this->config->get('WBQualityConstraintsMinimumDateId'), |
|
499 | + $this->config->get('WBQualityConstraintsMaximumDateId'), |
|
500 | 500 | $constraintTypeItemId, |
501 | 501 | 'time' |
502 | 502 | ); |
@@ -509,20 +509,20 @@ discard block |
||
509 | 509 | * @throws ConstraintParameterException |
510 | 510 | * @return string[] |
511 | 511 | */ |
512 | - public function parseLanguageParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
513 | - $this->checkError( $constraintParameters ); |
|
514 | - $languagePropertyId = $this->config->get( 'WBQualityConstraintsLanguagePropertyId' ); |
|
515 | - if ( !array_key_exists( $languagePropertyId, $constraintParameters ) ) { |
|
512 | + public function parseLanguageParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
513 | + $this->checkError($constraintParameters); |
|
514 | + $languagePropertyId = $this->config->get('WBQualityConstraintsLanguagePropertyId'); |
|
515 | + if (!array_key_exists($languagePropertyId, $constraintParameters)) { |
|
516 | 516 | throw new ConstraintParameterException( |
517 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
518 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
519 | - ->withEntityId( new NumericPropertyId( $languagePropertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
517 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
518 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
519 | + ->withEntityId(new NumericPropertyId($languagePropertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
520 | 520 | ); |
521 | 521 | } |
522 | 522 | |
523 | 523 | $languages = []; |
524 | - foreach ( $constraintParameters[$languagePropertyId] as $snak ) { |
|
525 | - $languages[] = $this->parseStringParameter( $snak, $languagePropertyId ); |
|
524 | + foreach ($constraintParameters[$languagePropertyId] as $snak) { |
|
525 | + $languages[] = $this->parseStringParameter($snak, $languagePropertyId); |
|
526 | 526 | } |
527 | 527 | return $languages; |
528 | 528 | } |
@@ -531,17 +531,17 @@ discard block |
||
531 | 531 | * Parse a single string parameter. |
532 | 532 | * @throws ConstraintParameterException |
533 | 533 | */ |
534 | - private function parseStringParameter( array $snakSerialization, string $parameterId ): string { |
|
535 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
536 | - $this->requireValueParameter( $snak, $parameterId ); |
|
534 | + private function parseStringParameter(array $snakSerialization, string $parameterId): string { |
|
535 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
536 | + $this->requireValueParameter($snak, $parameterId); |
|
537 | 537 | $value = $snak->getDataValue(); |
538 | - if ( $value instanceof StringValue ) { |
|
538 | + if ($value instanceof StringValue) { |
|
539 | 539 | return $value->getValue(); |
540 | 540 | } else { |
541 | 541 | throw new ConstraintParameterException( |
542 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) ) |
|
543 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
544 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
542 | + (new ViolationMessage('wbqc-violation-message-parameter-string')) |
|
543 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
544 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
545 | 545 | ); |
546 | 546 | } |
547 | 547 | } |
@@ -552,15 +552,15 @@ discard block |
||
552 | 552 | * @throws ConstraintParameterException if the parameter is invalid or missing |
553 | 553 | * @return string |
554 | 554 | */ |
555 | - public function parseNamespaceParameter( array $constraintParameters, string $constraintTypeItemId ): string { |
|
556 | - $this->checkError( $constraintParameters ); |
|
557 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
558 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
555 | + public function parseNamespaceParameter(array $constraintParameters, string $constraintTypeItemId): string { |
|
556 | + $this->checkError($constraintParameters); |
|
557 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
558 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
559 | 559 | return ''; |
560 | 560 | } |
561 | 561 | |
562 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
563 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
562 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
563 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -569,19 +569,19 @@ discard block |
||
569 | 569 | * @throws ConstraintParameterException if the parameter is invalid or missing |
570 | 570 | * @return string |
571 | 571 | */ |
572 | - public function parseFormatParameter( array $constraintParameters, string $constraintTypeItemId ): string { |
|
573 | - $this->checkError( $constraintParameters ); |
|
574 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
575 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
572 | + public function parseFormatParameter(array $constraintParameters, string $constraintTypeItemId): string { |
|
573 | + $this->checkError($constraintParameters); |
|
574 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
575 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
576 | 576 | throw new ConstraintParameterException( |
577 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
578 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
579 | - ->withEntityId( new NumericPropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
577 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
578 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
579 | + ->withEntityId(new NumericPropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
580 | 580 | ); |
581 | 581 | } |
582 | 582 | |
583 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
584 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
583 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
584 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
@@ -589,16 +589,16 @@ discard block |
||
589 | 589 | * @throws ConstraintParameterException if the parameter is invalid |
590 | 590 | * @return EntityId[] |
591 | 591 | */ |
592 | - public function parseExceptionParameter( array $constraintParameters ): array { |
|
593 | - $this->checkError( $constraintParameters ); |
|
594 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
595 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
592 | + public function parseExceptionParameter(array $constraintParameters): array { |
|
593 | + $this->checkError($constraintParameters); |
|
594 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
595 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
596 | 596 | return []; |
597 | 597 | } |
598 | 598 | |
599 | 599 | return array_map( |
600 | - function ( $snakSerialization ) use ( $exceptionId ) { |
|
601 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
600 | + function($snakSerialization) use ($exceptionId) { |
|
601 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
602 | 602 | }, |
603 | 603 | $constraintParameters[$exceptionId] |
604 | 604 | ); |
@@ -609,39 +609,39 @@ discard block |
||
609 | 609 | * @throws ConstraintParameterException if the parameter is invalid |
610 | 610 | * @return string|null 'mandatory', 'suggestion' or null |
611 | 611 | */ |
612 | - public function parseConstraintStatusParameter( array $constraintParameters ): ?string { |
|
613 | - $this->checkError( $constraintParameters ); |
|
614 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
615 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
612 | + public function parseConstraintStatusParameter(array $constraintParameters): ?string { |
|
613 | + $this->checkError($constraintParameters); |
|
614 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
615 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
616 | 616 | return null; |
617 | 617 | } |
618 | 618 | |
619 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
620 | - $supportedStatuses = [ new ItemId( $mandatoryId ) ]; |
|
621 | - if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) { |
|
622 | - $suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' ); |
|
623 | - $supportedStatuses[] = new ItemId( $suggestionId ); |
|
619 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
620 | + $supportedStatuses = [new ItemId($mandatoryId)]; |
|
621 | + if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) { |
|
622 | + $suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId'); |
|
623 | + $supportedStatuses[] = new ItemId($suggestionId); |
|
624 | 624 | } else { |
625 | 625 | $suggestionId = null; |
626 | 626 | } |
627 | 627 | |
628 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
629 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
630 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
628 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
629 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
630 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
631 | 631 | '@phan-var \Wikibase\DataModel\Snak\PropertyValueSnak $snak'; |
632 | 632 | $dataValue = $snak->getDataValue(); |
633 | 633 | '@phan-var EntityIdValue $dataValue'; |
634 | 634 | $entityId = $dataValue->getEntityId(); |
635 | 635 | $statusId = $entityId->getSerialization(); |
636 | 636 | |
637 | - if ( $statusId === $mandatoryId ) { |
|
637 | + if ($statusId === $mandatoryId) { |
|
638 | 638 | return 'mandatory'; |
639 | - } elseif ( $statusId === $suggestionId ) { |
|
639 | + } elseif ($statusId === $suggestionId) { |
|
640 | 640 | return 'suggestion'; |
641 | 641 | } else { |
642 | 642 | throw new ConstraintParameterException( |
643 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
644 | - ->withEntityId( new NumericPropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
643 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
644 | + ->withEntityId(new NumericPropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
645 | 645 | ->withEntityIdList( |
646 | 646 | $supportedStatuses, |
647 | 647 | Role::CONSTRAINT_PARAMETER_VALUE |
@@ -654,12 +654,12 @@ discard block |
||
654 | 654 | * Require that $dataValue is a {@link MonolingualTextValue}. |
655 | 655 | * @throws ConstraintParameterException |
656 | 656 | */ |
657 | - private function requireMonolingualTextParameter( DataValue $dataValue, string $parameterId ): void { |
|
658 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
657 | + private function requireMonolingualTextParameter(DataValue $dataValue, string $parameterId): void { |
|
658 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
659 | 659 | throw new ConstraintParameterException( |
660 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) ) |
|
661 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
662 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
660 | + (new ViolationMessage('wbqc-violation-message-parameter-monolingualtext')) |
|
661 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
662 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
663 | 663 | ); |
664 | 664 | } |
665 | 665 | } |
@@ -669,31 +669,31 @@ discard block |
||
669 | 669 | * |
670 | 670 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
671 | 671 | */ |
672 | - private function parseMultilingualTextParameter( array $snakSerializations, string $parameterId ): MultilingualTextValue { |
|
672 | + private function parseMultilingualTextParameter(array $snakSerializations, string $parameterId): MultilingualTextValue { |
|
673 | 673 | $result = []; |
674 | 674 | |
675 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
676 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
677 | - $this->requireValueParameter( $snak, $parameterId ); |
|
675 | + foreach ($snakSerializations as $snakSerialization) { |
|
676 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
677 | + $this->requireValueParameter($snak, $parameterId); |
|
678 | 678 | |
679 | 679 | $value = $snak->getDataValue(); |
680 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
680 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
681 | 681 | /** @var MonolingualTextValue $value */ |
682 | 682 | '@phan-var MonolingualTextValue $value'; |
683 | 683 | |
684 | 684 | $code = $value->getLanguageCode(); |
685 | - if ( array_key_exists( $code, $result ) ) { |
|
685 | + if (array_key_exists($code, $result)) { |
|
686 | 686 | throw new ConstraintParameterException( |
687 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) ) |
|
688 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
689 | - ->withLanguage( $code ) |
|
687 | + (new ViolationMessage('wbqc-violation-message-parameter-single-per-language')) |
|
688 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
689 | + ->withLanguage($code) |
|
690 | 690 | ); |
691 | 691 | } |
692 | 692 | |
693 | 693 | $result[$code] = $value; |
694 | 694 | } |
695 | 695 | |
696 | - return new MultilingualTextValue( $result ); |
|
696 | + return new MultilingualTextValue($result); |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | /** |
@@ -701,11 +701,11 @@ discard block |
||
701 | 701 | * @throws ConstraintParameterException if the parameter is invalid |
702 | 702 | * @return MultilingualTextValue |
703 | 703 | */ |
704 | - public function parseSyntaxClarificationParameter( array $constraintParameters ): MultilingualTextValue { |
|
705 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
704 | + public function parseSyntaxClarificationParameter(array $constraintParameters): MultilingualTextValue { |
|
705 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
706 | 706 | |
707 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
708 | - return new MultilingualTextValue( [] ); |
|
707 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
708 | + return new MultilingualTextValue([]); |
|
709 | 709 | } |
710 | 710 | |
711 | 711 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -738,14 +738,14 @@ discard block |
||
738 | 738 | array $validContextTypes, |
739 | 739 | array $validEntityTypes |
740 | 740 | ): array { |
741 | - $contextTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
741 | + $contextTypeParameterId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
742 | 742 | $contextTypeItemIds = $this->parseItemIdsParameter( |
743 | 743 | $constraintParameters, |
744 | 744 | $constraintTypeItemId, |
745 | 745 | false, |
746 | 746 | $contextTypeParameterId |
747 | 747 | ); |
748 | - $entityTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintEntityTypesId' ); |
|
748 | + $entityTypeParameterId = $this->config->get('WBQualityConstraintsConstraintEntityTypesId'); |
|
749 | 749 | $entityTypeItemIds = $this->parseItemIdsParameter( |
750 | 750 | $constraintParameters, |
751 | 751 | $constraintTypeItemId, |
@@ -761,26 +761,26 @@ discard block |
||
761 | 761 | $contextTypes = null; |
762 | 762 | $entityTypes = null; |
763 | 763 | |
764 | - if ( $contextTypeParameterId === $entityTypeParameterId ) { |
|
764 | + if ($contextTypeParameterId === $entityTypeParameterId) { |
|
765 | 765 | $itemIds = $contextTypeItemIds; |
766 | 766 | $mapping = $contextTypeMapping + $entityTypeMapping; |
767 | - foreach ( $itemIds as $itemId ) { |
|
768 | - $mapped = $this->mapItemId( $itemId, $mapping, $contextTypeParameterId ); |
|
769 | - if ( in_array( $mapped, $contextTypeMapping, true ) ) { |
|
767 | + foreach ($itemIds as $itemId) { |
|
768 | + $mapped = $this->mapItemId($itemId, $mapping, $contextTypeParameterId); |
|
769 | + if (in_array($mapped, $contextTypeMapping, true)) { |
|
770 | 770 | $contextTypes[] = $mapped; |
771 | 771 | } else { |
772 | 772 | $entityTypes[] = $mapped; |
773 | 773 | } |
774 | 774 | } |
775 | 775 | } else { |
776 | - foreach ( $contextTypeItemIds as $contextTypeItemId ) { |
|
776 | + foreach ($contextTypeItemIds as $contextTypeItemId) { |
|
777 | 777 | $contextTypes[] = $this->mapItemId( |
778 | 778 | $contextTypeItemId, |
779 | 779 | $contextTypeMapping, |
780 | 780 | $contextTypeParameterId |
781 | 781 | ); |
782 | 782 | } |
783 | - foreach ( $entityTypeItemIds as $entityTypeItemId ) { |
|
783 | + foreach ($entityTypeItemIds as $entityTypeItemId) { |
|
784 | 784 | $entityTypes[] = $this->mapItemId( |
785 | 785 | $entityTypeItemId, |
786 | 786 | $entityTypeMapping, |
@@ -789,21 +789,21 @@ discard block |
||
789 | 789 | } |
790 | 790 | } |
791 | 791 | |
792 | - $this->checkValidScope( $constraintTypeItemId, $contextTypes, $validContextTypes ); |
|
793 | - $this->checkValidScope( $constraintTypeItemId, $entityTypes, $validEntityTypes ); |
|
792 | + $this->checkValidScope($constraintTypeItemId, $contextTypes, $validContextTypes); |
|
793 | + $this->checkValidScope($constraintTypeItemId, $entityTypes, $validEntityTypes); |
|
794 | 794 | |
795 | - return [ $contextTypes, $entityTypes ]; |
|
795 | + return [$contextTypes, $entityTypes]; |
|
796 | 796 | } |
797 | 797 | |
798 | - private function checkValidScope( string $constraintTypeItemId, ?array $types, array $validTypes ): void { |
|
799 | - $invalidTypes = array_diff( $types ?: [], $validTypes ); |
|
800 | - if ( $invalidTypes !== [] ) { |
|
801 | - $invalidType = array_pop( $invalidTypes ); |
|
798 | + private function checkValidScope(string $constraintTypeItemId, ?array $types, array $validTypes): void { |
|
799 | + $invalidTypes = array_diff($types ?: [], $validTypes); |
|
800 | + if ($invalidTypes !== []) { |
|
801 | + $invalidType = array_pop($invalidTypes); |
|
802 | 802 | throw new ConstraintParameterException( |
803 | - ( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) ) |
|
804 | - ->withConstraintScope( $invalidType, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
805 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
806 | - ->withConstraintScopeList( $validTypes, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
803 | + (new ViolationMessage('wbqc-violation-message-invalid-scope')) |
|
804 | + ->withConstraintScope($invalidType, Role::CONSTRAINT_PARAMETER_VALUE) |
|
805 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
806 | + ->withConstraintScopeList($validTypes, Role::CONSTRAINT_PARAMETER_VALUE) |
|
807 | 807 | ); |
808 | 808 | } |
809 | 809 | } |
@@ -811,8 +811,8 @@ discard block |
||
811 | 811 | /** |
812 | 812 | * Turn an item ID into a full unit string (using the concept URI). |
813 | 813 | */ |
814 | - private function parseUnitParameter( ItemId $unitId ): string { |
|
815 | - return $this->unitItemConceptBaseUri . $unitId->getSerialization(); |
|
814 | + private function parseUnitParameter(ItemId $unitId): string { |
|
815 | + return $this->unitItemConceptBaseUri.$unitId->getSerialization(); |
|
816 | 816 | } |
817 | 817 | |
818 | 818 | /** |
@@ -820,23 +820,23 @@ discard block |
||
820 | 820 | * |
821 | 821 | * @throws ConstraintParameterException |
822 | 822 | */ |
823 | - private function parseUnitItem( ItemIdSnakValue $item ): UnitsParameter { |
|
824 | - switch ( true ) { |
|
823 | + private function parseUnitItem(ItemIdSnakValue $item): UnitsParameter { |
|
824 | + switch (true) { |
|
825 | 825 | case $item->isValue(): |
826 | - $unit = $this->parseUnitParameter( $item->getItemId() ); |
|
826 | + $unit = $this->parseUnitParameter($item->getItemId()); |
|
827 | 827 | return new UnitsParameter( |
828 | - [ $item->getItemId() ], |
|
829 | - [ UnboundedQuantityValue::newFromNumber( 1, $unit ) ], |
|
828 | + [$item->getItemId()], |
|
829 | + [UnboundedQuantityValue::newFromNumber(1, $unit)], |
|
830 | 830 | false |
831 | 831 | ); |
832 | 832 | case $item->isSomeValue(): |
833 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
833 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
834 | 834 | throw new ConstraintParameterException( |
835 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
836 | - ->withEntityId( new NumericPropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
835 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
836 | + ->withEntityId(new NumericPropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
837 | 837 | ); |
838 | 838 | case $item->isNoValue(): |
839 | - return new UnitsParameter( [], [], true ); |
|
839 | + return new UnitsParameter([], [], true); |
|
840 | 840 | } |
841 | 841 | } |
842 | 842 | |
@@ -846,36 +846,36 @@ discard block |
||
846 | 846 | * @throws ConstraintParameterException if the parameter is invalid or missing |
847 | 847 | * @return UnitsParameter |
848 | 848 | */ |
849 | - public function parseUnitsParameter( array $constraintParameters, string $constraintTypeItemId ): UnitsParameter { |
|
850 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
849 | + public function parseUnitsParameter(array $constraintParameters, string $constraintTypeItemId): UnitsParameter { |
|
850 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
851 | 851 | $unitItems = []; |
852 | 852 | $unitQuantities = []; |
853 | 853 | $unitlessAllowed = false; |
854 | 854 | |
855 | - foreach ( $items as $item ) { |
|
856 | - $unit = $this->parseUnitItem( $item ); |
|
857 | - $unitItems = array_merge( $unitItems, $unit->getUnitItemIds() ); |
|
858 | - $unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() ); |
|
855 | + foreach ($items as $item) { |
|
856 | + $unit = $this->parseUnitItem($item); |
|
857 | + $unitItems = array_merge($unitItems, $unit->getUnitItemIds()); |
|
858 | + $unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities()); |
|
859 | 859 | $unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed(); |
860 | 860 | } |
861 | 861 | |
862 | - if ( $unitQuantities === [] && !$unitlessAllowed ) { |
|
862 | + if ($unitQuantities === [] && !$unitlessAllowed) { |
|
863 | 863 | throw new LogicException( |
864 | 864 | 'The "units" parameter is required, and yet we seem to be missing any allowed unit' |
865 | 865 | ); |
866 | 866 | } |
867 | 867 | |
868 | - return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed ); |
|
868 | + return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed); |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | private function getEntityTypeMapping(): array { |
872 | 872 | return [ |
873 | - $this->config->get( 'WBQualityConstraintsWikibaseItemId' ) => 'item', |
|
874 | - $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) => 'property', |
|
875 | - $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) => 'lexeme', |
|
876 | - $this->config->get( 'WBQualityConstraintsWikibaseFormId' ) => 'form', |
|
877 | - $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) => 'sense', |
|
878 | - $this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ) => 'mediainfo', |
|
873 | + $this->config->get('WBQualityConstraintsWikibaseItemId') => 'item', |
|
874 | + $this->config->get('WBQualityConstraintsWikibasePropertyId') => 'property', |
|
875 | + $this->config->get('WBQualityConstraintsWikibaseLexemeId') => 'lexeme', |
|
876 | + $this->config->get('WBQualityConstraintsWikibaseFormId') => 'form', |
|
877 | + $this->config->get('WBQualityConstraintsWikibaseSenseId') => 'sense', |
|
878 | + $this->config->get('WBQualityConstraintsWikibaseMediaInfoId') => 'mediainfo', |
|
879 | 879 | ]; |
880 | 880 | } |
881 | 881 | |
@@ -885,10 +885,10 @@ discard block |
||
885 | 885 | * @throws ConstraintParameterException if the parameter is invalid or missing |
886 | 886 | * @return EntityTypesParameter |
887 | 887 | */ |
888 | - public function parseEntityTypesParameter( array $constraintParameters, string $constraintTypeItemId ): EntityTypesParameter { |
|
888 | + public function parseEntityTypesParameter(array $constraintParameters, string $constraintTypeItemId): EntityTypesParameter { |
|
889 | 889 | $entityTypes = []; |
890 | 890 | $entityTypeItemIds = []; |
891 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
891 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
892 | 892 | $itemIds = $this->parseItemIdsParameter( |
893 | 893 | $constraintParameters, |
894 | 894 | $constraintTypeItemId, |
@@ -897,22 +897,22 @@ discard block |
||
897 | 897 | ); |
898 | 898 | |
899 | 899 | $mapping = $this->getEntityTypeMapping(); |
900 | - foreach ( $itemIds as $itemId ) { |
|
901 | - $entityType = $this->mapItemId( $itemId, $mapping, $parameterId ); |
|
900 | + foreach ($itemIds as $itemId) { |
|
901 | + $entityType = $this->mapItemId($itemId, $mapping, $parameterId); |
|
902 | 902 | $entityTypes[] = $entityType; |
903 | 903 | $entityTypeItemIds[] = $itemId; |
904 | 904 | } |
905 | 905 | |
906 | - if ( empty( $entityTypes ) ) { |
|
906 | + if (empty($entityTypes)) { |
|
907 | 907 | // @codeCoverageIgnoreStart |
908 | 908 | throw new LogicException( |
909 | - 'The "entity types" parameter is required, ' . |
|
909 | + 'The "entity types" parameter is required, '. |
|
910 | 910 | 'and yet we seem to be missing any allowed entity type' |
911 | 911 | ); |
912 | 912 | // @codeCoverageIgnoreEnd |
913 | 913 | } |
914 | 914 | |
915 | - return new EntityTypesParameter( $entityTypes, $entityTypeItemIds ); |
|
915 | + return new EntityTypesParameter($entityTypes, $entityTypeItemIds); |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | /** |
@@ -920,18 +920,18 @@ discard block |
||
920 | 920 | * @throws ConstraintParameterException if the parameter is invalid |
921 | 921 | * @return PropertyId[] |
922 | 922 | */ |
923 | - public function parseSeparatorsParameter( array $constraintParameters ): array { |
|
924 | - $separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' ); |
|
923 | + public function parseSeparatorsParameter(array $constraintParameters): array { |
|
924 | + $separatorId = $this->config->get('WBQualityConstraintsSeparatorId'); |
|
925 | 925 | |
926 | - if ( !array_key_exists( $separatorId, $constraintParameters ) ) { |
|
926 | + if (!array_key_exists($separatorId, $constraintParameters)) { |
|
927 | 927 | return []; |
928 | 928 | } |
929 | 929 | |
930 | 930 | $parameters = $constraintParameters[$separatorId]; |
931 | 931 | $separators = []; |
932 | 932 | |
933 | - foreach ( $parameters as $parameter ) { |
|
934 | - $separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId ); |
|
933 | + foreach ($parameters as $parameter) { |
|
934 | + $separators[] = $this->parsePropertyIdParameter($parameter, $separatorId); |
|
935 | 935 | } |
936 | 936 | |
937 | 937 | return $separators; |
@@ -939,17 +939,17 @@ discard block |
||
939 | 939 | |
940 | 940 | private function getConstraintScopeContextTypeMapping(): array { |
941 | 941 | return [ |
942 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ) => Context::TYPE_STATEMENT, |
|
943 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ) => Context::TYPE_QUALIFIER, |
|
944 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ) => Context::TYPE_REFERENCE, |
|
942 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId') => Context::TYPE_STATEMENT, |
|
943 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId') => Context::TYPE_QUALIFIER, |
|
944 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId') => Context::TYPE_REFERENCE, |
|
945 | 945 | ]; |
946 | 946 | } |
947 | 947 | |
948 | 948 | private function getPropertyScopeContextTypeMapping(): array { |
949 | 949 | return [ |
950 | - $this->config->get( 'WBQualityConstraintsAsMainValueId' ) => Context::TYPE_STATEMENT, |
|
951 | - $this->config->get( 'WBQualityConstraintsAsQualifiersId' ) => Context::TYPE_QUALIFIER, |
|
952 | - $this->config->get( 'WBQualityConstraintsAsReferencesId' ) => Context::TYPE_REFERENCE, |
|
950 | + $this->config->get('WBQualityConstraintsAsMainValueId') => Context::TYPE_STATEMENT, |
|
951 | + $this->config->get('WBQualityConstraintsAsQualifiersId') => Context::TYPE_QUALIFIER, |
|
952 | + $this->config->get('WBQualityConstraintsAsReferencesId') => Context::TYPE_REFERENCE, |
|
953 | 953 | ]; |
954 | 954 | } |
955 | 955 | |
@@ -959,9 +959,9 @@ discard block |
||
959 | 959 | * @throws ConstraintParameterException if the parameter is invalid or missing |
960 | 960 | * @return string[] list of Context::TYPE_* constants |
961 | 961 | */ |
962 | - public function parsePropertyScopeParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
962 | + public function parsePropertyScopeParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
963 | 963 | $contextTypes = []; |
964 | - $parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' ); |
|
964 | + $parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId'); |
|
965 | 965 | $itemIds = $this->parseItemIdsParameter( |
966 | 966 | $constraintParameters, |
967 | 967 | $constraintTypeItemId, |
@@ -970,14 +970,14 @@ discard block |
||
970 | 970 | ); |
971 | 971 | |
972 | 972 | $mapping = $this->getPropertyScopeContextTypeMapping(); |
973 | - foreach ( $itemIds as $itemId ) { |
|
974 | - $contextTypes[] = $this->mapItemId( $itemId, $mapping, $parameterId ); |
|
973 | + foreach ($itemIds as $itemId) { |
|
974 | + $contextTypes[] = $this->mapItemId($itemId, $mapping, $parameterId); |
|
975 | 975 | } |
976 | 976 | |
977 | - if ( empty( $contextTypes ) ) { |
|
977 | + if (empty($contextTypes)) { |
|
978 | 978 | // @codeCoverageIgnoreStart |
979 | 979 | throw new LogicException( |
980 | - 'The "property scope" parameter is required, ' . |
|
980 | + 'The "property scope" parameter is required, '. |
|
981 | 981 | 'and yet we seem to be missing any allowed scope' |
982 | 982 | ); |
983 | 983 | // @codeCoverageIgnoreEnd |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Message; |
6 | 6 | |
@@ -27,13 +27,13 @@ discard block |
||
27 | 27 | 'wbqc-violation-message-format-clarification' => 'wbqc-violation-message-format', |
28 | 28 | ]; |
29 | 29 | |
30 | - public function render( ViolationMessage $violationMessage ): string { |
|
31 | - if ( !array_key_exists( $violationMessage->getMessageKey(), self::ALTERNATIVE_MESSAGE_KEYS ) ) { |
|
32 | - return parent::render( $violationMessage ); |
|
30 | + public function render(ViolationMessage $violationMessage): string { |
|
31 | + if (!array_key_exists($violationMessage->getMessageKey(), self::ALTERNATIVE_MESSAGE_KEYS)) { |
|
32 | + return parent::render($violationMessage); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | $arguments = $violationMessage->getArguments(); |
36 | - $multilingualTextArgument = array_pop( $arguments ); |
|
36 | + $multilingualTextArgument = array_pop($arguments); |
|
37 | 37 | $multilingualTextParams = $this->renderMultilingualText( |
38 | 38 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable TODO Ensure this is not an actual issue |
39 | 39 | $multilingualTextArgument['value'], |
@@ -41,22 +41,22 @@ discard block |
||
41 | 41 | $multilingualTextArgument['role'] |
42 | 42 | ); |
43 | 43 | |
44 | - $paramsLists = [ [] ]; |
|
45 | - foreach ( $arguments as $argument ) { |
|
46 | - $paramsLists[] = $this->renderArgument( $argument ); |
|
44 | + $paramsLists = [[]]; |
|
45 | + foreach ($arguments as $argument) { |
|
46 | + $paramsLists[] = $this->renderArgument($argument); |
|
47 | 47 | } |
48 | - $regularParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
48 | + $regularParams = call_user_func_array('array_merge', $paramsLists); |
|
49 | 49 | |
50 | - if ( $multilingualTextParams === null ) { |
|
50 | + if ($multilingualTextParams === null) { |
|
51 | 51 | return $this->messageLocalizer |
52 | - ->msg( self::ALTERNATIVE_MESSAGE_KEYS[$violationMessage->getMessageKey()] ) |
|
53 | - ->params( $regularParams ) |
|
52 | + ->msg(self::ALTERNATIVE_MESSAGE_KEYS[$violationMessage->getMessageKey()]) |
|
53 | + ->params($regularParams) |
|
54 | 54 | ->escaped(); |
55 | 55 | } else { |
56 | 56 | return $this->messageLocalizer |
57 | - ->msg( $violationMessage->getMessageKey() ) |
|
58 | - ->params( $regularParams ) |
|
59 | - ->params( $multilingualTextParams ) |
|
57 | + ->msg($violationMessage->getMessageKey()) |
|
58 | + ->params($regularParams) |
|
59 | + ->params($multilingualTextParams) |
|
60 | 60 | ->escaped(); |
61 | 61 | } |
62 | 62 | } |
@@ -67,18 +67,18 @@ discard block |
||
67 | 67 | * @return array[]|null list of parameters as accepted by Message::params(), |
68 | 68 | * or null if the text is not available in the user’s language |
69 | 69 | */ |
70 | - protected function renderMultilingualText( MultilingualTextValue $text, ?string $role ): ?array { |
|
70 | + protected function renderMultilingualText(MultilingualTextValue $text, ?string $role): ?array { |
|
71 | 71 | global $wgLang; |
72 | 72 | $languageCodes = $wgLang->getFallbackLanguages(); |
73 | - array_unshift( $languageCodes, $wgLang->getCode() ); |
|
73 | + array_unshift($languageCodes, $wgLang->getCode()); |
|
74 | 74 | |
75 | 75 | $texts = $text->getTexts(); |
76 | - foreach ( $languageCodes as $languageCode ) { |
|
77 | - if ( array_key_exists( $languageCode, $texts ) ) { |
|
78 | - return [ Message::rawParam( $this->addRole( |
|
79 | - htmlspecialchars( $texts[$languageCode]->getText() ), |
|
76 | + foreach ($languageCodes as $languageCode) { |
|
77 | + if (array_key_exists($languageCode, $texts)) { |
|
78 | + return [Message::rawParam($this->addRole( |
|
79 | + htmlspecialchars($texts[$languageCode]->getText()), |
|
80 | 80 | $role |
81 | - ) ) ]; |
|
81 | + ))]; |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\Api; |
6 | 6 | |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | StatementGuidParser $statementGuidParser, |
75 | 75 | IBufferingStatsdDataFactory $dataFactory |
76 | 76 | ) { |
77 | - parent::__construct( $main, $name ); |
|
77 | + parent::__construct($main, $name); |
|
78 | 78 | |
79 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
79 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
80 | 80 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
81 | 81 | $this->violationMessageRendererFactory = $violationMessageRendererFactory; |
82 | 82 | $this->statementGuidParser = $statementGuidParser; |
@@ -91,39 +91,39 @@ discard block |
||
91 | 91 | $params = $this->extractRequestParams(); |
92 | 92 | $result = $this->getResult(); |
93 | 93 | |
94 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
95 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
94 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
95 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
96 | 96 | |
97 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
98 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
97 | + $this->checkPropertyIds($propertyIds, $result); |
|
98 | + $this->checkConstraintIds($constraintIds, $result); |
|
99 | 99 | |
100 | - $result->addValue( null, 'success', 1 ); |
|
100 | + $result->addValue(null, 'success', 1); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | 104 | * @param array|null $propertyIdSerializations |
105 | 105 | * @return NumericPropertyId[] |
106 | 106 | */ |
107 | - private function parsePropertyIds( ?array $propertyIdSerializations ): array { |
|
108 | - if ( $propertyIdSerializations === null ) { |
|
107 | + private function parsePropertyIds(?array $propertyIdSerializations): array { |
|
108 | + if ($propertyIdSerializations === null) { |
|
109 | 109 | return []; |
110 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
110 | + } elseif (empty($propertyIdSerializations)) { |
|
111 | 111 | $this->apiErrorReporter->dieError( |
112 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
112 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
113 | 113 | 'no-data' |
114 | 114 | ); |
115 | 115 | } |
116 | 116 | |
117 | 117 | return array_map( |
118 | - function ( $propertyIdSerialization ) { |
|
118 | + function($propertyIdSerialization) { |
|
119 | 119 | try { |
120 | - return new NumericPropertyId( $propertyIdSerialization ); |
|
121 | - } catch ( InvalidArgumentException $e ) { |
|
120 | + return new NumericPropertyId($propertyIdSerialization); |
|
121 | + } catch (InvalidArgumentException $e) { |
|
122 | 122 | $this->apiErrorReporter->dieError( |
123 | 123 | "Invalid id: $propertyIdSerialization", |
124 | 124 | 'invalid-property-id', |
125 | 125 | 0, // default argument |
126 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
126 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
127 | 127 | ); |
128 | 128 | } |
129 | 129 | }, |
@@ -135,35 +135,35 @@ discard block |
||
135 | 135 | * @param array|null $constraintIds |
136 | 136 | * @return string[] |
137 | 137 | */ |
138 | - private function parseConstraintIds( ?array $constraintIds ): array { |
|
139 | - if ( $constraintIds === null ) { |
|
138 | + private function parseConstraintIds(?array $constraintIds): array { |
|
139 | + if ($constraintIds === null) { |
|
140 | 140 | return []; |
141 | - } elseif ( empty( $constraintIds ) ) { |
|
141 | + } elseif (empty($constraintIds)) { |
|
142 | 142 | $this->apiErrorReporter->dieError( |
143 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
143 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
144 | 144 | 'no-data' |
145 | 145 | ); |
146 | 146 | } |
147 | 147 | |
148 | 148 | return array_map( |
149 | - function ( $constraintId ) { |
|
149 | + function($constraintId) { |
|
150 | 150 | try { |
151 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
152 | - if ( !$propertyId instanceof NumericPropertyId ) { |
|
151 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
152 | + if (!$propertyId instanceof NumericPropertyId) { |
|
153 | 153 | $this->apiErrorReporter->dieError( |
154 | 154 | "Invalid property ID: {$propertyId->getSerialization()}", |
155 | 155 | 'invalid-property-id', |
156 | 156 | 0, // default argument |
157 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
157 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
158 | 158 | ); |
159 | 159 | } |
160 | 160 | return $constraintId; |
161 | - } catch ( StatementGuidParsingException $e ) { |
|
161 | + } catch (StatementGuidParsingException $e) { |
|
162 | 162 | $this->apiErrorReporter->dieError( |
163 | 163 | "Invalid statement GUID: $constraintId", |
164 | 164 | 'invalid-guid', |
165 | 165 | 0, // default argument |
166 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
166 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
167 | 167 | ); |
168 | 168 | } |
169 | 169 | }, |
@@ -175,12 +175,12 @@ discard block |
||
175 | 175 | * @param NumericPropertyId[] $propertyIds |
176 | 176 | * @param ApiResult $result |
177 | 177 | */ |
178 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ): void { |
|
179 | - foreach ( $propertyIds as $propertyId ) { |
|
180 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
178 | + private function checkPropertyIds(array $propertyIds, ApiResult $result): void { |
|
179 | + foreach ($propertyIds as $propertyId) { |
|
180 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
181 | 181 | $allConstraintExceptions = $this->delegatingConstraintChecker |
182 | - ->checkConstraintParametersOnPropertyId( $propertyId ); |
|
183 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
182 | + ->checkConstraintParametersOnPropertyId($propertyId); |
|
183 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
184 | 184 | $this->addConstraintParameterExceptionsToResult( |
185 | 185 | $constraintId, |
186 | 186 | $constraintParameterExceptions, |
@@ -194,15 +194,15 @@ discard block |
||
194 | 194 | * @param string[] $constraintIds |
195 | 195 | * @param ApiResult $result |
196 | 196 | */ |
197 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ): void { |
|
198 | - foreach ( $constraintIds as $constraintId ) { |
|
199 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
197 | + private function checkConstraintIds(array $constraintIds, ApiResult $result): void { |
|
198 | + foreach ($constraintIds as $constraintId) { |
|
199 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
200 | 200 | // already checked as part of checkPropertyIds() |
201 | 201 | continue; |
202 | 202 | } |
203 | 203 | $constraintParameterExceptions = $this->delegatingConstraintChecker |
204 | - ->checkConstraintParametersOnConstraintId( $constraintId ); |
|
205 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
204 | + ->checkConstraintParametersOnConstraintId($constraintId); |
|
205 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
@@ -210,18 +210,18 @@ discard block |
||
210 | 210 | * @param NumericPropertyId $propertyId |
211 | 211 | * @return string[] |
212 | 212 | */ |
213 | - private function getResultPathForPropertyId( NumericPropertyId $propertyId ): array { |
|
214 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
213 | + private function getResultPathForPropertyId(NumericPropertyId $propertyId): array { |
|
214 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
218 | 218 | * @param string $constraintId |
219 | 219 | * @return string[] |
220 | 220 | */ |
221 | - private function getResultPathForConstraintId( string $constraintId ): array { |
|
222 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
221 | + private function getResultPathForConstraintId(string $constraintId): array { |
|
222 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
223 | 223 | '@phan-var NumericPropertyId $propertyId'; |
224 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
224 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | ?array $constraintParameterExceptions, |
237 | 237 | ApiResult $result |
238 | 238 | ): void { |
239 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
240 | - if ( $constraintParameterExceptions === null ) { |
|
239 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
240 | + if ($constraintParameterExceptions === null) { |
|
241 | 241 | $result->addValue( |
242 | 242 | $path, |
243 | 243 | self::KEY_STATUS, |
@@ -247,13 +247,13 @@ discard block |
||
247 | 247 | $result->addValue( |
248 | 248 | $path, |
249 | 249 | self::KEY_STATUS, |
250 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
250 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
251 | 251 | ); |
252 | 252 | |
253 | 253 | $violationMessageRenderer = $this->violationMessageRendererFactory |
254 | - ->getViolationMessageRenderer( $this->getLanguage(), $this ); |
|
254 | + ->getViolationMessageRenderer($this->getLanguage(), $this); |
|
255 | 255 | $problems = []; |
256 | - foreach ( $constraintParameterExceptions as $constraintParameterException ) { |
|
256 | + foreach ($constraintParameterExceptions as $constraintParameterException) { |
|
257 | 257 | $problems[] = [ |
258 | 258 | self::KEY_MESSAGE_HTML => $violationMessageRenderer->render( |
259 | 259 | $constraintParameterException->getViolationMessage() ), |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | return [ |
293 | 293 | 'action=wbcheckconstraintparameters&propertyid=P247' |
294 | 294 | => 'apihelp-wbcheckconstraintparameters-example-propertyid-1', |
295 | - 'action=wbcheckconstraintparameters&' . |
|
296 | - 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' . |
|
295 | + 'action=wbcheckconstraintparameters&'. |
|
296 | + 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'. |
|
297 | 297 | 'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f' |
298 | 298 | => 'apihelp-wbcheckconstraintparameters-example-constraintid-2', |
299 | 299 | ]; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\Api; |
6 | 6 | |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | $this->violationMessageRenderer = $violationMessageRenderer; |
38 | 38 | } |
39 | 39 | |
40 | - public function render( CachedCheckResults $checkResults ): CachedCheckConstraintsResponse { |
|
40 | + public function render(CachedCheckResults $checkResults): CachedCheckConstraintsResponse { |
|
41 | 41 | $response = []; |
42 | - foreach ( $checkResults->getArray() as $checkResult ) { |
|
43 | - $resultArray = $this->checkResultToArray( $checkResult ); |
|
44 | - $checkResult->getContextCursor()->storeCheckResultInArray( $resultArray, $response ); |
|
42 | + foreach ($checkResults->getArray() as $checkResult) { |
|
43 | + $resultArray = $this->checkResultToArray($checkResult); |
|
44 | + $checkResult->getContextCursor()->storeCheckResultInArray($resultArray, $response); |
|
45 | 45 | } |
46 | 46 | return new CachedCheckConstraintsResponse( |
47 | 47 | $response, |
@@ -49,19 +49,19 @@ discard block |
||
49 | 49 | ); |
50 | 50 | } |
51 | 51 | |
52 | - public function checkResultToArray( CheckResult $checkResult ): ?array { |
|
53 | - if ( $checkResult instanceof NullResult ) { |
|
52 | + public function checkResultToArray(CheckResult $checkResult): ?array { |
|
53 | + if ($checkResult instanceof NullResult) { |
|
54 | 54 | return null; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $constraintId = $checkResult->getConstraint()->getConstraintId(); |
58 | 58 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
59 | - $constraintPropertyId = new NumericPropertyId( $checkResult->getContextCursor()->getSnakPropertyId() ); |
|
59 | + $constraintPropertyId = new NumericPropertyId($checkResult->getContextCursor()->getSnakPropertyId()); |
|
60 | 60 | |
61 | - $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
61 | + $title = $this->entityTitleLookup->getTitleForId($constraintPropertyId); |
|
62 | 62 | $talkTitle = $title->getTalkPageIfDefined(); |
63 | - $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
64 | - $link = $title->getFullURL() . '#' . $constraintId; |
|
63 | + $typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId)); |
|
64 | + $link = $title->getFullURL().'#'.$constraintId; |
|
65 | 65 | |
66 | 66 | $constraint = [ |
67 | 67 | 'id' => $constraintId, |
@@ -77,14 +77,14 @@ discard block |
||
77 | 77 | 'constraint' => $constraint |
78 | 78 | ]; |
79 | 79 | $message = $checkResult->getMessage(); |
80 | - if ( $message ) { |
|
81 | - $result['message-html'] = $this->violationMessageRenderer->render( $message ); |
|
80 | + if ($message) { |
|
81 | + $result['message-html'] = $this->violationMessageRenderer->render($message); |
|
82 | 82 | } |
83 | - if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) { |
|
83 | + if ($checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT) { |
|
84 | 84 | $result['claim'] = $checkResult->getContextCursor()->getStatementGuid(); |
85 | 85 | } |
86 | 86 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
87 | - if ( $cachingMetadataArray !== null ) { |
|
87 | + if ($cachingMetadataArray !== null) { |
|
88 | 88 | $result['cached'] = $cachingMetadataArray; |
89 | 89 | } |
90 | 90 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\Api; |
6 | 6 | |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | CheckResultsRendererFactory $checkResultsRendererFactory, |
82 | 82 | IBufferingStatsdDataFactory $dataFactory |
83 | 83 | ) { |
84 | - parent::__construct( $main, $name ); |
|
84 | + parent::__construct($main, $name); |
|
85 | 85 | $this->entityIdParser = $entityIdParser; |
86 | 86 | $this->statementGuidValidator = $statementGuidValidator; |
87 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
88 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
87 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
88 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
89 | 89 | $this->resultsSource = $resultsSource; |
90 | 90 | $this->checkResultsRendererFactory = $checkResultsRendererFactory; |
91 | 91 | $this->dataFactory = $dataFactory; |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | |
102 | 102 | $params = $this->extractRequestParams(); |
103 | 103 | |
104 | - $this->validateParameters( $params ); |
|
105 | - $entityIds = $this->parseEntityIds( $params ); |
|
106 | - $claimIds = $this->parseClaimIds( $params ); |
|
104 | + $this->validateParameters($params); |
|
105 | + $entityIds = $this->parseEntityIds($params); |
|
106 | + $claimIds = $this->parseClaimIds($params); |
|
107 | 107 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
108 | 108 | $statuses = $params[self::PARAM_STATUS]; |
109 | 109 | |
110 | 110 | $checkResultsRenderer = $this->checkResultsRendererFactory |
111 | - ->getCheckResultsRenderer( $this->getLanguage(), $this ); |
|
111 | + ->getCheckResultsRenderer($this->getLanguage(), $this); |
|
112 | 112 | |
113 | 113 | $this->getResult()->addValue( |
114 | 114 | null, |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | ) |
123 | 123 | )->getArray() |
124 | 124 | ); |
125 | - $this->resultBuilder->markSuccess( 1 ); |
|
125 | + $this->resultBuilder->markSuccess(1); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -130,24 +130,24 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @return EntityId[] |
132 | 132 | */ |
133 | - private function parseEntityIds( array $params ): array { |
|
133 | + private function parseEntityIds(array $params): array { |
|
134 | 134 | $ids = $params[self::PARAM_ID]; |
135 | 135 | |
136 | - if ( $ids === null ) { |
|
136 | + if ($ids === null) { |
|
137 | 137 | return []; |
138 | - } elseif ( $ids === [] ) { |
|
138 | + } elseif ($ids === []) { |
|
139 | 139 | $this->errorReporter->dieError( |
140 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
140 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
141 | 141 | } |
142 | 142 | |
143 | - return array_map( function ( $id ) { |
|
143 | + return array_map(function($id) { |
|
144 | 144 | try { |
145 | - return $this->entityIdParser->parse( $id ); |
|
146 | - } catch ( EntityIdParsingException $e ) { |
|
145 | + return $this->entityIdParser->parse($id); |
|
146 | + } catch (EntityIdParsingException $e) { |
|
147 | 147 | $this->errorReporter->dieError( |
148 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
148 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
149 | 149 | } |
150 | - }, $ids ); |
|
150 | + }, $ids); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -155,35 +155,35 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return string[] |
157 | 157 | */ |
158 | - private function parseClaimIds( array $params ): array { |
|
158 | + private function parseClaimIds(array $params): array { |
|
159 | 159 | $ids = $params[self::PARAM_CLAIM_ID]; |
160 | 160 | |
161 | - if ( $ids === null ) { |
|
161 | + if ($ids === null) { |
|
162 | 162 | return []; |
163 | - } elseif ( $ids === [] ) { |
|
163 | + } elseif ($ids === []) { |
|
164 | 164 | $this->errorReporter->dieError( |
165 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
165 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
166 | 166 | } |
167 | 167 | |
168 | - foreach ( $ids as $id ) { |
|
169 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
168 | + foreach ($ids as $id) { |
|
169 | + if (!$this->statementGuidValidator->validate($id)) { |
|
170 | 170 | $this->errorReporter->dieError( |
171 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
171 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | 175 | return $ids; |
176 | 176 | } |
177 | 177 | |
178 | - private function validateParameters( array $params ): void { |
|
179 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
180 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
178 | + private function validateParameters(array $params): void { |
|
179 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
180 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
181 | 181 | ) { |
182 | 182 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
183 | 183 | $this->errorReporter->dieError( |
184 | 184 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
185 | 185 | } |
186 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
186 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
187 | 187 | $paramId = self::PARAM_ID; |
188 | 188 | $paramClaimId = self::PARAM_CLAIM_ID; |
189 | 189 | $this->errorReporter->dieError( |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | ], |
225 | 225 | ParamValidator::PARAM_ISMULTI => true, |
226 | 226 | ParamValidator::PARAM_ALL => true, |
227 | - ParamValidator::PARAM_DEFAULT => implode( '|', CachingResultsSource::CACHED_STATUSES ), |
|
227 | + ParamValidator::PARAM_DEFAULT => implode('|', CachingResultsSource::CACHED_STATUSES), |
|
228 | 228 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
229 | 229 | ], |
230 | 230 | ]; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck; |
6 | 6 | |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | callable $defaultResultsPerEntity = null |
124 | 124 | ): array { |
125 | 125 | $checkResults = []; |
126 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
126 | + $entity = $this->entityLookup->getEntity($entityId); |
|
127 | 127 | |
128 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
129 | - $startTime = microtime( true ); |
|
128 | + if ($entity instanceof StatementListProvidingEntity) { |
|
129 | + $startTime = microtime(true); |
|
130 | 130 | |
131 | 131 | $checkResults = $this->checkEveryStatement( |
132 | 132 | $entity, |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | $defaultResultsPerContext |
135 | 135 | ); |
136 | 136 | |
137 | - $endTime = microtime( true ); |
|
137 | + $endTime = microtime(true); |
|
138 | 138 | |
139 | - if ( $constraintIds === null ) { // only log full constraint checks |
|
139 | + if ($constraintIds === null) { // only log full constraint checks |
|
140 | 140 | $this->loggingHelper->logConstraintCheckOnEntity( |
141 | 141 | $entityId, |
142 | 142 | $checkResults, |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | - if ( $defaultResultsPerEntity !== null ) { |
|
150 | - $checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults ); |
|
149 | + if ($defaultResultsPerEntity !== null) { |
|
150 | + $checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults); |
|
151 | 151 | } |
152 | 152 | |
153 | - return $this->sortResult( $checkResults ); |
|
153 | + return $this->sortResult($checkResults); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | callable $defaultResults = null |
173 | 173 | ): array { |
174 | 174 | |
175 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
175 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
176 | 176 | $entityId = $parsedGuid->getEntityId(); |
177 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
178 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
179 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
180 | - if ( $statement ) { |
|
177 | + $entity = $this->entityLookup->getEntity($entityId); |
|
178 | + if ($entity instanceof StatementListProvidingEntity) { |
|
179 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
180 | + if ($statement) { |
|
181 | 181 | $result = $this->checkStatement( |
182 | 182 | $entity, |
183 | 183 | $statement, |
184 | 184 | $constraintIds, |
185 | 185 | $defaultResults |
186 | 186 | ); |
187 | - $output = $this->sortResult( $result ); |
|
187 | + $output = $this->sortResult($result); |
|
188 | 188 | return $output; |
189 | 189 | } |
190 | 190 | } |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | return []; |
193 | 193 | } |
194 | 194 | |
195 | - private function getValidContextTypes( Constraint $constraint ): array { |
|
196 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
195 | + private function getValidContextTypes(Constraint $constraint): array { |
|
196 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
197 | 197 | return [ |
198 | 198 | Context::TYPE_STATEMENT, |
199 | 199 | Context::TYPE_QUALIFIER, |
@@ -201,25 +201,25 @@ discard block |
||
201 | 201 | ]; |
202 | 202 | } |
203 | 203 | |
204 | - return array_keys( array_filter( |
|
204 | + return array_keys(array_filter( |
|
205 | 205 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
206 | - static function ( $resultStatus ) { |
|
206 | + static function($resultStatus) { |
|
207 | 207 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
208 | 208 | } |
209 | - ) ); |
|
209 | + )); |
|
210 | 210 | } |
211 | 211 | |
212 | - private function getValidEntityTypes( Constraint $constraint ): array { |
|
213 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
214 | - return array_keys( ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED ); |
|
212 | + private function getValidEntityTypes(Constraint $constraint): array { |
|
213 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
214 | + return array_keys(ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED); |
|
215 | 215 | } |
216 | 216 | |
217 | - return array_keys( array_filter( |
|
217 | + return array_keys(array_filter( |
|
218 | 218 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedEntityTypes(), |
219 | - static function ( $resultStatus ) { |
|
219 | + static function($resultStatus) { |
|
220 | 220 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
221 | 221 | } |
222 | - ) ); |
|
222 | + )); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -230,33 +230,33 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @return ConstraintParameterException[] |
232 | 232 | */ |
233 | - private function checkCommonConstraintParameters( Constraint $constraint ): array { |
|
233 | + private function checkCommonConstraintParameters(Constraint $constraint): array { |
|
234 | 234 | $constraintParameters = $constraint->getConstraintParameters(); |
235 | 235 | try { |
236 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
237 | - } catch ( ConstraintParameterException $e ) { |
|
238 | - return [ $e ]; |
|
236 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
237 | + } catch (ConstraintParameterException $e) { |
|
238 | + return [$e]; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | $problems = []; |
242 | 242 | try { |
243 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
244 | - } catch ( ConstraintParameterException $e ) { |
|
243 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
244 | + } catch (ConstraintParameterException $e) { |
|
245 | 245 | $problems[] = $e; |
246 | 246 | } |
247 | 247 | try { |
248 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
249 | - } catch ( ConstraintParameterException $e ) { |
|
248 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
249 | + } catch (ConstraintParameterException $e) { |
|
250 | 250 | $problems[] = $e; |
251 | 251 | } |
252 | 252 | try { |
253 | 253 | $this->constraintParameterParser->parseConstraintScopeParameters( |
254 | 254 | $constraintParameters, |
255 | 255 | $constraint->getConstraintTypeItemId(), |
256 | - $this->getValidContextTypes( $constraint ), |
|
257 | - $this->getValidEntityTypes( $constraint ) |
|
256 | + $this->getValidContextTypes($constraint), |
|
257 | + $this->getValidEntityTypes($constraint) |
|
258 | 258 | ); |
259 | - } catch ( ConstraintParameterException $e ) { |
|
259 | + } catch (ConstraintParameterException $e) { |
|
260 | 260 | $problems[] = $e; |
261 | 261 | } |
262 | 262 | return $problems; |
@@ -269,16 +269,16 @@ discard block |
||
269 | 269 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
270 | 270 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
271 | 271 | */ |
272 | - public function checkConstraintParametersOnPropertyId( NumericPropertyId $propertyId ): array { |
|
273 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
272 | + public function checkConstraintParametersOnPropertyId(NumericPropertyId $propertyId): array { |
|
273 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
274 | 274 | $result = []; |
275 | 275 | |
276 | - foreach ( $constraints as $constraint ) { |
|
277 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
276 | + foreach ($constraints as $constraint) { |
|
277 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
278 | 278 | |
279 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
279 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
280 | 280 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
281 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
281 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | $result[$constraint->getConstraintId()] = $problems; |
@@ -295,18 +295,18 @@ discard block |
||
295 | 295 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
296 | 296 | * (empty means all parameters okay), or null if constraint is not found |
297 | 297 | */ |
298 | - public function checkConstraintParametersOnConstraintId( string $constraintId ): ?array { |
|
299 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
298 | + public function checkConstraintParametersOnConstraintId(string $constraintId): ?array { |
|
299 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
300 | 300 | '@phan-var NumericPropertyId $propertyId'; |
301 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
301 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
302 | 302 | |
303 | - foreach ( $constraints as $constraint ) { |
|
304 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
305 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
303 | + foreach ($constraints as $constraint) { |
|
304 | + if ($constraint->getConstraintId() === $constraintId) { |
|
305 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
306 | 306 | |
307 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
307 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
308 | 308 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
309 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
309 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | return $problems; |
@@ -331,14 +331,14 @@ discard block |
||
331 | 331 | $result = []; |
332 | 332 | |
333 | 333 | /** @var Statement $statement */ |
334 | - foreach ( $entity->getStatements() as $statement ) { |
|
335 | - $result = array_merge( $result, |
|
334 | + foreach ($entity->getStatements() as $statement) { |
|
335 | + $result = array_merge($result, |
|
336 | 336 | $this->checkStatement( |
337 | 337 | $entity, |
338 | 338 | $statement, |
339 | 339 | $constraintIds, |
340 | 340 | $defaultResultsPerContext |
341 | - ) ); |
|
341 | + )); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | return $result; |
@@ -360,32 +360,32 @@ discard block |
||
360 | 360 | ): array { |
361 | 361 | $result = []; |
362 | 362 | |
363 | - $result = array_merge( $result, |
|
363 | + $result = array_merge($result, |
|
364 | 364 | $this->checkConstraintsForMainSnak( |
365 | 365 | $entity, |
366 | 366 | $statement, |
367 | 367 | $constraintIds, |
368 | 368 | $defaultResultsPerContext |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | |
371 | - if ( $this->checkQualifiers ) { |
|
372 | - $result = array_merge( $result, |
|
371 | + if ($this->checkQualifiers) { |
|
372 | + $result = array_merge($result, |
|
373 | 373 | $this->checkConstraintsForQualifiers( |
374 | 374 | $entity, |
375 | 375 | $statement, |
376 | 376 | $constraintIds, |
377 | 377 | $defaultResultsPerContext |
378 | - ) ); |
|
378 | + )); |
|
379 | 379 | } |
380 | 380 | |
381 | - if ( $this->checkReferences ) { |
|
382 | - $result = array_merge( $result, |
|
381 | + if ($this->checkReferences) { |
|
382 | + $result = array_merge($result, |
|
383 | 383 | $this->checkConstraintsForReferences( |
384 | 384 | $entity, |
385 | 385 | $statement, |
386 | 386 | $constraintIds, |
387 | 387 | $defaultResultsPerContext |
388 | - ) ); |
|
388 | + )); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | return $result; |
@@ -400,17 +400,17 @@ discard block |
||
400 | 400 | * @param string[]|null $constraintIds |
401 | 401 | * @return Constraint[] |
402 | 402 | */ |
403 | - private function getConstraintsToUse( PropertyId $propertyId, ?array $constraintIds ): array { |
|
404 | - if ( !( $propertyId instanceof NumericPropertyId ) ) { |
|
403 | + private function getConstraintsToUse(PropertyId $propertyId, ?array $constraintIds): array { |
|
404 | + if (!($propertyId instanceof NumericPropertyId)) { |
|
405 | 405 | throw new InvalidArgumentException( |
406 | - 'Non-numeric property ID not supported:' . $propertyId->getSerialization() |
|
406 | + 'Non-numeric property ID not supported:'.$propertyId->getSerialization() |
|
407 | 407 | ); |
408 | 408 | } |
409 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
410 | - if ( $constraintIds !== null ) { |
|
409 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
410 | + if ($constraintIds !== null) { |
|
411 | 411 | $constraintsToUse = []; |
412 | - foreach ( $constraints as $constraint ) { |
|
413 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
412 | + foreach ($constraints as $constraint) { |
|
413 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
414 | 414 | $constraintsToUse[] = $constraint; |
415 | 415 | } |
416 | 416 | } |
@@ -434,18 +434,18 @@ discard block |
||
434 | 434 | ?array $constraintIds, |
435 | 435 | ?callable $defaultResults |
436 | 436 | ): array { |
437 | - $context = new MainSnakContext( $entity, $statement ); |
|
437 | + $context = new MainSnakContext($entity, $statement); |
|
438 | 438 | $constraints = $this->getConstraintsToUse( |
439 | 439 | $statement->getPropertyId(), |
440 | 440 | $constraintIds |
441 | 441 | ); |
442 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
442 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
443 | 443 | |
444 | - foreach ( $constraints as $constraint ) { |
|
444 | + foreach ($constraints as $constraint) { |
|
445 | 445 | $parameters = $constraint->getConstraintParameters(); |
446 | 446 | try { |
447 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
448 | - } catch ( ConstraintParameterException $e ) { |
|
447 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
448 | + } catch (ConstraintParameterException $e) { |
|
449 | 449 | $result[] = new CheckResult( |
450 | 450 | $context, |
451 | 451 | $constraint, |
@@ -455,13 +455,13 @@ discard block |
||
455 | 455 | continue; |
456 | 456 | } |
457 | 457 | |
458 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
459 | - $message = new ViolationMessage( 'wbqc-violation-message-exception' ); |
|
460 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
458 | + if (in_array($entity->getId(), $exceptions)) { |
|
459 | + $message = new ViolationMessage('wbqc-violation-message-exception'); |
|
460 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
461 | 461 | continue; |
462 | 462 | } |
463 | 463 | |
464 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
464 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | return $result; |
@@ -483,24 +483,24 @@ discard block |
||
483 | 483 | ): array { |
484 | 484 | $result = []; |
485 | 485 | |
486 | - if ( in_array( |
|
486 | + if (in_array( |
|
487 | 487 | $statement->getPropertyId()->getSerialization(), |
488 | 488 | $this->propertiesWithViolatingQualifiers |
489 | - ) ) { |
|
489 | + )) { |
|
490 | 490 | return $result; |
491 | 491 | } |
492 | 492 | |
493 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
494 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
495 | - if ( $defaultResultsPerContext !== null ) { |
|
496 | - $result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) ); |
|
493 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
494 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
495 | + if ($defaultResultsPerContext !== null) { |
|
496 | + $result = array_merge($result, $defaultResultsPerContext($qualifierContext)); |
|
497 | 497 | } |
498 | 498 | $qualifierConstraints = $this->getConstraintsToUse( |
499 | 499 | $qualifierContext->getSnak()->getPropertyId(), |
500 | 500 | $constraintIds |
501 | 501 | ); |
502 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
503 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
502 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
503 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
@@ -524,19 +524,19 @@ discard block |
||
524 | 524 | $result = []; |
525 | 525 | |
526 | 526 | /** @var Reference $reference */ |
527 | - foreach ( $statement->getReferences() as $reference ) { |
|
528 | - foreach ( $reference->getSnaks() as $snak ) { |
|
527 | + foreach ($statement->getReferences() as $reference) { |
|
528 | + foreach ($reference->getSnaks() as $snak) { |
|
529 | 529 | $referenceContext = new ReferenceContext( |
530 | 530 | $entity, $statement, $reference, $snak |
531 | 531 | ); |
532 | - if ( $defaultResultsPerContext !== null ) { |
|
533 | - $result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) ); |
|
532 | + if ($defaultResultsPerContext !== null) { |
|
533 | + $result = array_merge($result, $defaultResultsPerContext($referenceContext)); |
|
534 | 534 | } |
535 | 535 | $referenceConstraints = $this->getConstraintsToUse( |
536 | 536 | $referenceContext->getSnak()->getPropertyId(), |
537 | 537 | $constraintIds |
538 | 538 | ); |
539 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
539 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
540 | 540 | $result[] = $this->getCheckResultFor( |
541 | 541 | $referenceContext, |
542 | 542 | $referenceConstraint |
@@ -548,20 +548,20 @@ discard block |
||
548 | 548 | return $result; |
549 | 549 | } |
550 | 550 | |
551 | - private function getCheckResultFor( Context $context, Constraint $constraint ): CheckResult { |
|
552 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
551 | + private function getCheckResultFor(Context $context, Constraint $constraint): CheckResult { |
|
552 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
553 | 553 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
554 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
554 | + $result = $this->handleScope($checker, $context, $constraint); |
|
555 | 555 | |
556 | - if ( $result !== null ) { |
|
557 | - $this->addMetadata( $context, $result ); |
|
556 | + if ($result !== null) { |
|
557 | + $this->addMetadata($context, $result); |
|
558 | 558 | return $result; |
559 | 559 | } |
560 | 560 | |
561 | - $startTime = microtime( true ); |
|
561 | + $startTime = microtime(true); |
|
562 | 562 | try { |
563 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
564 | - } catch ( ConstraintParameterException $e ) { |
|
563 | + $result = $checker->checkConstraint($context, $constraint); |
|
564 | + } catch (ConstraintParameterException $e) { |
|
565 | 565 | $result = new CheckResult( |
566 | 566 | $context, |
567 | 567 | $constraint, |
@@ -569,28 +569,28 @@ discard block |
||
569 | 569 | CheckResult::STATUS_BAD_PARAMETERS, |
570 | 570 | $e->getViolationMessage() |
571 | 571 | ); |
572 | - } catch ( SparqlHelperException $e ) { |
|
573 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
574 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, $message ); |
|
572 | + } catch (SparqlHelperException $e) { |
|
573 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
574 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, $message); |
|
575 | 575 | } |
576 | - $endTime = microtime( true ); |
|
576 | + $endTime = microtime(true); |
|
577 | 577 | |
578 | - $this->addMetadata( $context, $result ); |
|
578 | + $this->addMetadata($context, $result); |
|
579 | 579 | |
580 | - $this->downgradeResultStatus( $result ); |
|
580 | + $this->downgradeResultStatus($result); |
|
581 | 581 | |
582 | 582 | $this->loggingHelper->logConstraintCheck( |
583 | 583 | $context, |
584 | 584 | $constraint, |
585 | 585 | $result, |
586 | - get_class( $checker ), |
|
586 | + get_class($checker), |
|
587 | 587 | $endTime - $startTime, |
588 | 588 | __METHOD__ |
589 | 589 | ); |
590 | 590 | |
591 | 591 | return $result; |
592 | 592 | } else { |
593 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
593 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
594 | 594 | } |
595 | 595 | } |
596 | 596 | |
@@ -599,85 +599,85 @@ discard block |
||
599 | 599 | Context $context, |
600 | 600 | Constraint $constraint |
601 | 601 | ): ?CheckResult { |
602 | - $validContextTypes = $this->getValidContextTypes( $constraint ); |
|
603 | - $validEntityTypes = $this->getValidEntityTypes( $constraint ); |
|
602 | + $validContextTypes = $this->getValidContextTypes($constraint); |
|
603 | + $validEntityTypes = $this->getValidEntityTypes($constraint); |
|
604 | 604 | try { |
605 | - [ $checkedContextTypes, $checkedEntityTypes ] = $this->constraintParameterParser->parseConstraintScopeParameters( |
|
605 | + [$checkedContextTypes, $checkedEntityTypes] = $this->constraintParameterParser->parseConstraintScopeParameters( |
|
606 | 606 | $constraint->getConstraintParameters(), |
607 | 607 | $constraint->getConstraintTypeItemId(), |
608 | 608 | $validContextTypes, |
609 | 609 | $validEntityTypes |
610 | 610 | ); |
611 | - } catch ( ConstraintParameterException $e ) { |
|
612 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
611 | + } catch (ConstraintParameterException $e) { |
|
612 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
613 | 613 | } |
614 | 614 | |
615 | - if ( $checkedContextTypes === null ) { |
|
615 | + if ($checkedContextTypes === null) { |
|
616 | 616 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
617 | 617 | } |
618 | 618 | $contextType = $context->getType(); |
619 | - if ( !in_array( $contextType, $checkedContextTypes ) ) { |
|
620 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
619 | + if (!in_array($contextType, $checkedContextTypes)) { |
|
620 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
621 | 621 | } |
622 | - if ( $checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO ) { |
|
623 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
622 | + if ($checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO) { |
|
623 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
624 | 624 | } |
625 | 625 | |
626 | - if ( $checkedEntityTypes === null ) { |
|
626 | + if ($checkedEntityTypes === null) { |
|
627 | 627 | $checkedEntityTypes = $validEntityTypes; |
628 | 628 | } |
629 | 629 | $entityType = $context->getEntity()->getType(); |
630 | - if ( !in_array( $entityType, $checkedEntityTypes ) ) { |
|
631 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
630 | + if (!in_array($entityType, $checkedEntityTypes)) { |
|
631 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
632 | 632 | } |
633 | - if ( $checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO ) { |
|
634 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
633 | + if ($checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO) { |
|
634 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | return null; |
638 | 638 | } |
639 | 639 | |
640 | - private function addMetadata( Context $context, CheckResult $result ): void { |
|
641 | - $result->withMetadata( Metadata::merge( [ |
|
640 | + private function addMetadata(Context $context, CheckResult $result): void { |
|
641 | + $result->withMetadata(Metadata::merge([ |
|
642 | 642 | $result->getMetadata(), |
643 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
644 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
645 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
646 | - ] ) ), |
|
647 | - ] ) ); |
|
643 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
644 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
645 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
646 | + ])), |
|
647 | + ])); |
|
648 | 648 | } |
649 | 649 | |
650 | - private function downgradeResultStatus( CheckResult $result ): void { |
|
650 | + private function downgradeResultStatus(CheckResult $result): void { |
|
651 | 651 | $constraint = $result->getConstraint(); |
652 | 652 | try { |
653 | 653 | $constraintStatus = $this->constraintParameterParser |
654 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
655 | - } catch ( ConstraintParameterException $e ) { |
|
656 | - $result->setStatus( CheckResult::STATUS_BAD_PARAMETERS ); |
|
657 | - $result->setMessage( $e->getViolationMessage() ); |
|
654 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
655 | + } catch (ConstraintParameterException $e) { |
|
656 | + $result->setStatus(CheckResult::STATUS_BAD_PARAMETERS); |
|
657 | + $result->setMessage($e->getViolationMessage()); |
|
658 | 658 | return; |
659 | 659 | } |
660 | - if ( $constraintStatus === null ) { |
|
660 | + if ($constraintStatus === null) { |
|
661 | 661 | // downgrade violation to warning |
662 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
663 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
662 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
663 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
664 | 664 | } |
665 | - } elseif ( $constraintStatus === 'suggestion' ) { |
|
665 | + } elseif ($constraintStatus === 'suggestion') { |
|
666 | 666 | // downgrade violation to suggestion |
667 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
668 | - $result->setStatus( CheckResult::STATUS_SUGGESTION ); |
|
667 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
668 | + $result->setStatus(CheckResult::STATUS_SUGGESTION); |
|
669 | 669 | } |
670 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
670 | + $result->addParameter('constraint_status', $constraintStatus); |
|
671 | 671 | } else { |
672 | - if ( $constraintStatus !== 'mandatory' ) { |
|
672 | + if ($constraintStatus !== 'mandatory') { |
|
673 | 673 | // @codeCoverageIgnoreStart |
674 | 674 | throw new LogicException( |
675 | - "Unknown constraint status '$constraintStatus', " . |
|
675 | + "Unknown constraint status '$constraintStatus', ". |
|
676 | 676 | "only known statuses are 'mandatory' and 'suggestion'" |
677 | 677 | ); |
678 | 678 | // @codeCoverageIgnoreEnd |
679 | 679 | } |
680 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
680 | + $result->addParameter('constraint_status', $constraintStatus); |
|
681 | 681 | } |
682 | 682 | } |
683 | 683 | |
@@ -686,12 +686,12 @@ discard block |
||
686 | 686 | * |
687 | 687 | * @return CheckResult[] |
688 | 688 | */ |
689 | - private function sortResult( array $result ): array { |
|
690 | - if ( count( $result ) < 2 ) { |
|
689 | + private function sortResult(array $result): array { |
|
690 | + if (count($result) < 2) { |
|
691 | 691 | return $result; |
692 | 692 | } |
693 | 693 | |
694 | - $sortFunction = static function ( CheckResult $a, CheckResult $b ) { |
|
694 | + $sortFunction = static function(CheckResult $a, CheckResult $b) { |
|
695 | 695 | $orderNum = 0; |
696 | 696 | $order = [ |
697 | 697 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -708,55 +708,55 @@ discard block |
||
708 | 708 | $statusA = $a->getStatus(); |
709 | 709 | $statusB = $b->getStatus(); |
710 | 710 | |
711 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
712 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
711 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
712 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
713 | 713 | |
714 | - if ( $orderA === $orderB ) { |
|
714 | + if ($orderA === $orderB) { |
|
715 | 715 | $cursorA = $a->getContextCursor(); |
716 | 716 | $cursorB = $b->getContextCursor(); |
717 | 717 | |
718 | - if ( $cursorA instanceof EntityContextCursor ) { |
|
718 | + if ($cursorA instanceof EntityContextCursor) { |
|
719 | 719 | return $cursorB instanceof EntityContextCursor ? 0 : -1; |
720 | 720 | } |
721 | - if ( $cursorB instanceof EntityContextCursor ) { |
|
721 | + if ($cursorB instanceof EntityContextCursor) { |
|
722 | 722 | return $cursorA instanceof EntityContextCursor ? 0 : 1; |
723 | 723 | } |
724 | 724 | |
725 | 725 | $pidA = $cursorA->getSnakPropertyId(); |
726 | 726 | $pidB = $cursorB->getSnakPropertyId(); |
727 | 727 | |
728 | - if ( $pidA === $pidB ) { |
|
728 | + if ($pidA === $pidB) { |
|
729 | 729 | $hashA = $cursorA->getSnakHash(); |
730 | 730 | $hashB = $cursorB->getSnakHash(); |
731 | 731 | |
732 | - if ( $hashA === $hashB ) { |
|
733 | - if ( $a instanceof NullResult ) { |
|
732 | + if ($hashA === $hashB) { |
|
733 | + if ($a instanceof NullResult) { |
|
734 | 734 | return $b instanceof NullResult ? 0 : -1; |
735 | 735 | } |
736 | - if ( $b instanceof NullResult ) { |
|
736 | + if ($b instanceof NullResult) { |
|
737 | 737 | return $a instanceof NullResult ? 0 : 1; |
738 | 738 | } |
739 | 739 | |
740 | 740 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
741 | 741 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
742 | 742 | |
743 | - if ( $typeA == $typeB ) { |
|
743 | + if ($typeA == $typeB) { |
|
744 | 744 | return 0; |
745 | 745 | } else { |
746 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
746 | + return ($typeA > $typeB) ? 1 : -1; |
|
747 | 747 | } |
748 | 748 | } else { |
749 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
749 | + return ($hashA > $hashB) ? 1 : -1; |
|
750 | 750 | } |
751 | 751 | } else { |
752 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
752 | + return ($pidA > $pidB) ? 1 : -1; |
|
753 | 753 | } |
754 | 754 | } else { |
755 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
755 | + return ($orderA > $orderB) ? 1 : -1; |
|
756 | 756 | } |
757 | 757 | }; |
758 | 758 | |
759 | - uasort( $result, $sortFunction ); |
|
759 | + uasort($result, $sortFunction); |
|
760 | 760 | |
761 | 761 | return $result; |
762 | 762 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Result; |
6 | 6 | |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | string $status = self::STATUS_TODO, |
115 | 115 | ViolationMessage $message = null |
116 | 116 | ) { |
117 | - if ( $contextCursor instanceof Context ) { |
|
117 | + if ($contextCursor instanceof Context) { |
|
118 | 118 | $context = $contextCursor; |
119 | 119 | $this->contextCursor = $context->getCursor(); |
120 | 120 | $this->snakType = $context->getSnak()->getType(); |
121 | 121 | $mainSnak = $context->getSnak(); |
122 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
122 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
123 | 123 | $this->dataValue = $mainSnak->getDataValue(); |
124 | 124 | } else { |
125 | 125 | $this->dataValue = null; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | return $this->parameters; |
170 | 170 | } |
171 | 171 | |
172 | - public function addParameter( string $key, string $value ): void { |
|
172 | + public function addParameter(string $key, string $value): void { |
|
173 | 173 | $this->parameters[$key][] = $value; |
174 | 174 | } |
175 | 175 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | return $this->status; |
181 | 181 | } |
182 | 182 | |
183 | - public function setStatus( string $status ): void { |
|
183 | + public function setStatus(string $status): void { |
|
184 | 184 | $this->status = $status; |
185 | 185 | } |
186 | 186 | |
@@ -188,11 +188,11 @@ discard block |
||
188 | 188 | return $this->message; |
189 | 189 | } |
190 | 190 | |
191 | - public function setMessage( ?ViolationMessage $message ) { |
|
191 | + public function setMessage(?ViolationMessage $message) { |
|
192 | 192 | $this->message = $message; |
193 | 193 | } |
194 | 194 | |
195 | - public function withMetadata( Metadata $metadata ): self { |
|
195 | + public function withMetadata(Metadata $metadata): self { |
|
196 | 196 | $this->metadata = $metadata; |
197 | 197 | return $this; |
198 | 198 | } |