@@ -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 | |
@@ -108,12 +108,12 @@ discard block |
||
| 108 | 108 | string $status = self::STATUS_TODO, |
| 109 | 109 | ?ViolationMessage $message = null |
| 110 | 110 | ) { |
| 111 | - if ( $contextCursor instanceof Context ) { |
|
| 111 | + if ($contextCursor instanceof Context) { |
|
| 112 | 112 | $context = $contextCursor; |
| 113 | 113 | $this->contextCursor = $context->getCursor(); |
| 114 | 114 | $this->snakType = $context->getSnak()->getType(); |
| 115 | 115 | $mainSnak = $context->getSnak(); |
| 116 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
| 116 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
| 117 | 117 | $this->dataValue = $mainSnak->getDataValue(); |
| 118 | 118 | } else { |
| 119 | 119 | $this->dataValue = null; |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $this->status = $status; |
| 128 | 128 | $this->message = $message; |
| 129 | 129 | $this->metadata = Metadata::blank(); |
| 130 | - $this->constraintClarification = new MultilingualTextValue( [] ); |
|
| 130 | + $this->constraintClarification = new MultilingualTextValue([]); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | public function getContextCursor(): ContextCursor { |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | return $this->status; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - public function setStatus( string $status ): void { |
|
| 166 | + public function setStatus(string $status): void { |
|
| 167 | 167 | $this->status = $status; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -171,11 +171,11 @@ discard block |
||
| 171 | 171 | return $this->message; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - public function setMessage( ?ViolationMessage $message ) { |
|
| 174 | + public function setMessage(?ViolationMessage $message) { |
|
| 175 | 175 | $this->message = $message; |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - public function withMetadata( Metadata $metadata ): self { |
|
| 178 | + public function withMetadata(Metadata $metadata): self { |
|
| 179 | 179 | $this->metadata = $metadata; |
| 180 | 180 | return $this; |
| 181 | 181 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | return $this->constraintClarification; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - public function setConstraintClarification( MultilingualTextValue $constraintClarification ) { |
|
| 191 | + public function setConstraintClarification(MultilingualTextValue $constraintClarification) { |
|
| 192 | 192 | $this->constraintClarification = $constraintClarification; |
| 193 | 193 | } |
| 194 | 194 | |
@@ -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\Cache; |
| 6 | 6 | |
@@ -31,8 +31,8 @@ discard block |
||
| 31 | 31 | * @param int $maxAge The maximum age of the cached value (in seconds). |
| 32 | 32 | * @return self Indication that a value is possibly outdated by up to this many seconds. |
| 33 | 33 | */ |
| 34 | - public static function ofMaximumAgeInSeconds( int $maxAge ): self { |
|
| 35 | - Assert::parameter( $maxAge > 0, '$maxAge', '$maxage > 0' ); |
|
| 34 | + public static function ofMaximumAgeInSeconds(int $maxAge): self { |
|
| 35 | + Assert::parameter($maxAge > 0, '$maxAge', '$maxage > 0'); |
|
| 36 | 36 | $ret = new self; |
| 37 | 37 | $ret->maxAge = $maxAge; |
| 38 | 38 | return $ret; |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | * @param self[] $metadatas |
| 43 | 43 | * @return self |
| 44 | 44 | */ |
| 45 | - public static function merge( array $metadatas ): self { |
|
| 46 | - Assert::parameterElementType( self::class, $metadatas, '$metadatas' ); |
|
| 45 | + public static function merge(array $metadatas): self { |
|
| 46 | + Assert::parameterElementType(self::class, $metadatas, '$metadatas'); |
|
| 47 | 47 | $ret = new self; |
| 48 | - foreach ( $metadatas as $metadata ) { |
|
| 49 | - $ret->maxAge = max( $ret->maxAge, $metadata->maxAge ); |
|
| 48 | + foreach ($metadatas as $metadata) { |
|
| 49 | + $ret->maxAge = max($ret->maxAge, $metadata->maxAge); |
|
| 50 | 50 | } |
| 51 | 51 | return $ret; |
| 52 | 52 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * For a fresh value, returns 0. |
| 65 | 65 | */ |
| 66 | 66 | public function getMaximumAgeInSeconds(): int { |
| 67 | - if ( is_int( $this->maxAge ) ) { |
|
| 67 | + if (is_int($this->maxAge)) { |
|
| 68 | 68 | return $this->maxAge; |
| 69 | 69 | } else { |
| 70 | 70 | return 0; |
@@ -79,8 +79,7 @@ discard block |
||
| 79 | 79 | return $this->isCached() ? |
| 80 | 80 | [ |
| 81 | 81 | 'maximumAgeInSeconds' => $this->maxAge, |
| 82 | - ] : |
|
| 83 | - null; |
|
| 82 | + ] : null; |
|
| 84 | 83 | } |
| 85 | 84 | |
| 86 | 85 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param EntityId $entityId An entity ID from which the value was derived. |
| 38 | 38 | * @return self Indication that a value was derived from the entity with the given ID. |
| 39 | 39 | */ |
| 40 | - public static function ofEntityId( EntityId $entityId ) { |
|
| 40 | + public static function ofEntityId(EntityId $entityId) { |
|
| 41 | 41 | $ret = new self; |
| 42 | 42 | $ret->entityIds[] = $entityId; |
| 43 | 43 | return $ret; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @return self Indication that a value will only remain valid |
| 50 | 50 | * as long as the given time value is in the future, not in the past. |
| 51 | 51 | */ |
| 52 | - public static function ofFutureTime( TimeValue $timeValue ) { |
|
| 52 | + public static function ofFutureTime(TimeValue $timeValue) { |
|
| 53 | 53 | $ret = new self; |
| 54 | 54 | $ret->timeValue = $timeValue; |
| 55 | 55 | return $ret; |
@@ -59,17 +59,17 @@ discard block |
||
| 59 | 59 | * @param self[] $metadatas |
| 60 | 60 | * @return self |
| 61 | 61 | */ |
| 62 | - public static function merge( array $metadatas ) { |
|
| 63 | - Assert::parameterElementType( self::class, $metadatas, '$metadatas' ); |
|
| 62 | + public static function merge(array $metadatas) { |
|
| 63 | + Assert::parameterElementType(self::class, $metadatas, '$metadatas'); |
|
| 64 | 64 | $ret = new self; |
| 65 | 65 | $entityIds = []; |
| 66 | - foreach ( $metadatas as $metadata ) { |
|
| 67 | - foreach ( $metadata->entityIds as $entityId ) { |
|
| 66 | + foreach ($metadatas as $metadata) { |
|
| 67 | + foreach ($metadata->entityIds as $entityId) { |
|
| 68 | 68 | $entityIds[$entityId->getSerialization()] = $entityId; |
| 69 | 69 | } |
| 70 | - $ret->timeValue = self::minTimeValue( $ret->timeValue, $metadata->timeValue ); |
|
| 70 | + $ret->timeValue = self::minTimeValue($ret->timeValue, $metadata->timeValue); |
|
| 71 | 71 | } |
| 72 | - $ret->entityIds = array_values( $entityIds ); |
|
| 72 | + $ret->entityIds = array_values($entityIds); |
|
| 73 | 73 | return $ret; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -78,14 +78,14 @@ discard block |
||
| 78 | 78 | * @param TimeValue|null $t2 |
| 79 | 79 | * @return TimeValue|null |
| 80 | 80 | */ |
| 81 | - private static function minTimeValue( ?TimeValue $t1, ?TimeValue $t2 ) { |
|
| 82 | - if ( $t1 === null ) { |
|
| 81 | + private static function minTimeValue(?TimeValue $t1, ?TimeValue $t2) { |
|
| 82 | + if ($t1 === null) { |
|
| 83 | 83 | return $t2; |
| 84 | 84 | } |
| 85 | - if ( $t2 === null ) { |
|
| 85 | + if ($t2 === null) { |
|
| 86 | 86 | return $t1; |
| 87 | 87 | } |
| 88 | - return ( new TimeValueComparer() )->getMinimum( $t1, $t2 ); |
|
| 88 | + return (new TimeValueComparer())->getMinimum($t1, $t2); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -21,12 +21,12 @@ |
||
| 21 | 21 | * @return false|int (from the preg_match documentation) returns 1 if the pattern |
| 22 | 22 | * matches given subject, 0 if it does not, or FALSE if an error occurred. |
| 23 | 23 | */ |
| 24 | - public static function runRegexCheck( string $regex, string $text ) { |
|
| 25 | - $pattern = '(^(?:' . $regex . ')$)u'; |
|
| 24 | + public static function runRegexCheck(string $regex, string $text) { |
|
| 25 | + $pattern = '(^(?:'.$regex.')$)u'; |
|
| 26 | 26 | |
| 27 | 27 | // `preg_match` emits an E_WARNING when the pattern is not valid regex. |
| 28 | 28 | // Silence this warning to avoid throwing a ShellboxError. |
| 29 | 29 | // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged |
| 30 | - return @preg_match( $pattern, $text ); |
|
| 30 | + return @preg_match($pattern, $text); |
|
| 31 | 31 | } |
| 32 | 32 | } |
@@ -81,26 +81,26 @@ discard block |
||
| 81 | 81 | * @return bool |
| 82 | 82 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
| 83 | 83 | */ |
| 84 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
| 85 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
| 84 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
| 85 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
| 86 | 86 | if ( ++$entitiesChecked > $maxEntities ) { |
| 87 | - throw new OverflowException( 'Too many entities to check' ); |
|
| 87 | + throw new OverflowException('Too many entities to check'); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
| 91 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
| 90 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
| 91 | + if (!($item instanceof StatementListProvider)) { |
|
| 92 | 92 | return false; // lookup failed, probably because item doesn't exist |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
| 95 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
| 96 | 96 | $statements = $item->getStatements() |
| 97 | - ->getByPropertyId( new NumericPropertyId( $subclassId ) ) |
|
| 97 | + ->getByPropertyId(new NumericPropertyId($subclassId)) |
|
| 98 | 98 | ->getBestStatements(); |
| 99 | 99 | /** @var Statement $statement */ |
| 100 | - foreach ( $statements as $statement ) { |
|
| 100 | + foreach ($statements as $statement) { |
|
| 101 | 101 | $mainSnak = $statement->getMainSnak(); |
| 102 | 102 | |
| 103 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
| 103 | + if (!$this->hasCorrectType($mainSnak)) { |
|
| 104 | 104 | continue; |
| 105 | 105 | } |
| 106 | 106 | /** @var PropertyValueSnak $mainSnak */ |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | '@phan-var EntityIdValue $dataValue'; |
| 111 | 111 | $comparativeClass = $dataValue->getEntityId(); |
| 112 | 112 | |
| 113 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
| 113 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
| 114 | 114 | return true; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
| 117 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
| 118 | 118 | return true; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -135,40 +135,40 @@ discard block |
||
| 135 | 135 | * @return CachedBool |
| 136 | 136 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
| 137 | 137 | */ |
| 138 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
| 139 | - $timing = $this->statsFactory->getTiming( 'isSubclassOf_duration_seconds' ) |
|
| 140 | - ->setLabel( 'result', 'success' ) |
|
| 141 | - ->setLabel( 'TypeCheckerImplementation', 'php' ) |
|
| 142 | - ->copyToStatsdAt( 'wikibase.quality.constraints.type.php.success.timing' ); |
|
| 138 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
| 139 | + $timing = $this->statsFactory->getTiming('isSubclassOf_duration_seconds') |
|
| 140 | + ->setLabel('result', 'success') |
|
| 141 | + ->setLabel('TypeCheckerImplementation', 'php') |
|
| 142 | + ->copyToStatsdAt('wikibase.quality.constraints.type.php.success.timing'); |
|
| 143 | 143 | $timing->start(); |
| 144 | 144 | |
| 145 | 145 | try { |
| 146 | 146 | $entitiesChecked = 0; |
| 147 | - $isSubclass = $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ); |
|
| 147 | + $isSubclass = $this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked); |
|
| 148 | 148 | $timing->stop(); |
| 149 | 149 | |
| 150 | 150 | // not really a timing, but works like one (we want percentiles etc.) |
| 151 | 151 | // TODO: probably a good candidate for T348796 |
| 152 | - $this->statsFactory->getTiming( 'isSubclassOf_entities_total' ) |
|
| 153 | - ->setLabel( 'TypeCheckerImplementation', 'php' ) |
|
| 154 | - ->setLabel( 'result', 'success' ) |
|
| 155 | - ->copyToStatsdAt( 'wikibase.quality.constraints.type.php.success.entities' ) |
|
| 156 | - ->observe( $entitiesChecked ); |
|
| 157 | - |
|
| 158 | - return new CachedBool( $isSubclass, Metadata::blank() ); |
|
| 159 | - } catch ( OverflowException $e ) { |
|
| 160 | - $timing->setLabel( 'result', 'overflow' ) |
|
| 161 | - ->copyToStatsdAt( 'wikibase.quality.constraints.type.php.overflow.timing' ) |
|
| 152 | + $this->statsFactory->getTiming('isSubclassOf_entities_total') |
|
| 153 | + ->setLabel('TypeCheckerImplementation', 'php') |
|
| 154 | + ->setLabel('result', 'success') |
|
| 155 | + ->copyToStatsdAt('wikibase.quality.constraints.type.php.success.entities') |
|
| 156 | + ->observe($entitiesChecked); |
|
| 157 | + |
|
| 158 | + return new CachedBool($isSubclass, Metadata::blank()); |
|
| 159 | + } catch (OverflowException $e) { |
|
| 160 | + $timing->setLabel('result', 'overflow') |
|
| 161 | + ->copyToStatsdAt('wikibase.quality.constraints.type.php.overflow.timing') |
|
| 162 | 162 | ->stop(); |
| 163 | 163 | |
| 164 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
| 165 | - $this->statsFactory->getCounter( 'sparql_typeFallback_total' ) |
|
| 166 | - ->copyToStatsdAt( 'wikibase.quality.constraints.sparql.typeFallback' ) |
|
| 164 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
| 165 | + $this->statsFactory->getCounter('sparql_typeFallback_total') |
|
| 166 | + ->copyToStatsdAt('wikibase.quality.constraints.sparql.typeFallback') |
|
| 167 | 167 | ->increment(); |
| 168 | 168 | |
| 169 | - $timing->setLabel( 'TypeCheckerImplementation', 'sparql' ) |
|
| 170 | - ->setLabel( 'result', 'success' ) |
|
| 171 | - ->copyToStatsdAt( 'wikibase.quality.constraints.type.sparql.success.timing' ) |
|
| 169 | + $timing->setLabel('TypeCheckerImplementation', 'sparql') |
|
| 170 | + ->setLabel('result', 'success') |
|
| 171 | + ->copyToStatsdAt('wikibase.quality.constraints.type.sparql.success.timing') |
|
| 172 | 172 | ->start(); |
| 173 | 173 | |
| 174 | 174 | $hasType = $this->sparqlHelper->hasType( |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | return $hasType; |
| 182 | 182 | } else { |
| 183 | - return new CachedBool( false, Metadata::blank() ); |
|
| 183 | + return new CachedBool(false, Metadata::blank()); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | } |
@@ -198,13 +198,13 @@ discard block |
||
| 198 | 198 | * @return CachedBool |
| 199 | 199 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
| 200 | 200 | */ |
| 201 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
| 201 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
| 202 | 202 | $metadatas = []; |
| 203 | 203 | |
| 204 | - foreach ( $this->getBestStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
| 204 | + foreach ($this->getBestStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
| 205 | 205 | $mainSnak = $statement->getMainSnak(); |
| 206 | 206 | |
| 207 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
| 207 | + if (!$this->hasCorrectType($mainSnak)) { |
|
| 208 | 208 | continue; |
| 209 | 209 | } |
| 210 | 210 | /** @var PropertyValueSnak $mainSnak */ |
@@ -214,24 +214,24 @@ discard block |
||
| 214 | 214 | '@phan-var EntityIdValue $dataValue'; |
| 215 | 215 | $comparativeClass = $dataValue->getEntityId(); |
| 216 | 216 | |
| 217 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
| 217 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
| 218 | 218 | // discard $metadatas, we know this is fresh |
| 219 | - return new CachedBool( true, Metadata::blank() ); |
|
| 219 | + return new CachedBool(true, Metadata::blank()); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
| 222 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
| 223 | 223 | $metadatas[] = $result->getMetadata(); |
| 224 | - if ( $result->getBool() ) { |
|
| 224 | + if ($result->getBool()) { |
|
| 225 | 225 | return new CachedBool( |
| 226 | 226 | true, |
| 227 | - Metadata::merge( $metadatas ) |
|
| 227 | + Metadata::merge($metadatas) |
|
| 228 | 228 | ); |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | return new CachedBool( |
| 233 | 233 | false, |
| 234 | - Metadata::merge( $metadatas ) |
|
| 234 | + Metadata::merge($metadatas) |
|
| 235 | 235 | ); |
| 236 | 236 | } |
| 237 | 237 | |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * @return bool |
| 241 | 241 | * @phan-assert PropertyValueSnak $mainSnak |
| 242 | 242 | */ |
| 243 | - private function hasCorrectType( Snak $mainSnak ) { |
|
| 243 | + private function hasCorrectType(Snak $mainSnak) { |
|
| 244 | 244 | return $mainSnak instanceof PropertyValueSnak |
| 245 | 245 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
| 246 | 246 | } |
@@ -257,15 +257,15 @@ discard block |
||
| 257 | 257 | ) { |
| 258 | 258 | $statementArrays = []; |
| 259 | 259 | |
| 260 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
| 261 | - $propertyId = new NumericPropertyId( $propertyIdSerialization ); |
|
| 260 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
| 261 | + $propertyId = new NumericPropertyId($propertyIdSerialization); |
|
| 262 | 262 | $statementArrays[] = $statements |
| 263 | - ->getByPropertyId( $propertyId ) |
|
| 263 | + ->getByPropertyId($propertyId) |
|
| 264 | 264 | ->getBestStatements() |
| 265 | 265 | ->toArray(); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - return array_merge( ...$statementArrays ); |
|
| 268 | + return array_merge(...$statementArrays); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -285,8 +285,8 @@ discard block |
||
| 285 | 285 | $relation |
| 286 | 286 | ) { |
| 287 | 287 | $classes = array_map( |
| 288 | - static function ( $itemIdSerialization ) { |
|
| 289 | - return new ItemId( $itemIdSerialization ); |
|
| 288 | + static function($itemIdSerialization) { |
|
| 289 | + return new ItemId($itemIdSerialization); |
|
| 290 | 290 | }, |
| 291 | 291 | $classes |
| 292 | 292 | ); |
@@ -298,10 +298,10 @@ discard block |
||
| 298 | 298 | // wbqc-violation-message-valueType-instance |
| 299 | 299 | // wbqc-violation-message-valueType-subclass |
| 300 | 300 | // wbqc-violation-message-valueType-instanceOrSubclass |
| 301 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
| 302 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
| 303 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
| 304 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
| 301 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
| 302 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
| 303 | + ->withEntityId($entityId, Role::SUBJECT) |
|
| 304 | + ->withEntityIdList($classes, Role::OBJECT); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | } |
@@ -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 | |
@@ -28,13 +28,13 @@ discard block |
||
| 28 | 28 | 'wbqc-violation-message-format-clarification' => 'wbqc-violation-message-format', |
| 29 | 29 | ]; |
| 30 | 30 | |
| 31 | - public function render( ViolationMessage $violationMessage ): string { |
|
| 32 | - if ( !array_key_exists( $violationMessage->getMessageKey(), self::ALTERNATIVE_MESSAGE_KEYS ) ) { |
|
| 33 | - return parent::render( $violationMessage ); |
|
| 31 | + public function render(ViolationMessage $violationMessage): string { |
|
| 32 | + if (!array_key_exists($violationMessage->getMessageKey(), self::ALTERNATIVE_MESSAGE_KEYS)) { |
|
| 33 | + return parent::render($violationMessage); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $arguments = $violationMessage->getArguments(); |
| 37 | - $multilingualTextArgument = array_pop( $arguments ); |
|
| 37 | + $multilingualTextArgument = array_pop($arguments); |
|
| 38 | 38 | $multilingualTextParams = $this->renderMultilingualText( |
| 39 | 39 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable TODO Ensure this is not an actual issue |
| 40 | 40 | $multilingualTextArgument['value'], |
@@ -42,22 +42,22 @@ discard block |
||
| 42 | 42 | $multilingualTextArgument['role'] |
| 43 | 43 | ); |
| 44 | 44 | |
| 45 | - $paramsLists = [ [] ]; |
|
| 46 | - foreach ( $arguments as $argument ) { |
|
| 47 | - $paramsLists[] = $this->renderArgument( $argument ); |
|
| 45 | + $paramsLists = [[]]; |
|
| 46 | + foreach ($arguments as $argument) { |
|
| 47 | + $paramsLists[] = $this->renderArgument($argument); |
|
| 48 | 48 | } |
| 49 | - $regularParams = array_merge( ...$paramsLists ); |
|
| 49 | + $regularParams = array_merge(...$paramsLists); |
|
| 50 | 50 | |
| 51 | - if ( $multilingualTextParams === null ) { |
|
| 51 | + if ($multilingualTextParams === null) { |
|
| 52 | 52 | return $this->messageLocalizer |
| 53 | - ->msg( self::ALTERNATIVE_MESSAGE_KEYS[$violationMessage->getMessageKey()] ) |
|
| 54 | - ->params( $regularParams ) |
|
| 53 | + ->msg(self::ALTERNATIVE_MESSAGE_KEYS[$violationMessage->getMessageKey()]) |
|
| 54 | + ->params($regularParams) |
|
| 55 | 55 | ->escaped(); |
| 56 | 56 | } else { |
| 57 | 57 | return $this->messageLocalizer |
| 58 | - ->msg( $violationMessage->getMessageKey() ) |
|
| 59 | - ->params( $regularParams ) |
|
| 60 | - ->params( $multilingualTextParams ) |
|
| 58 | + ->msg($violationMessage->getMessageKey()) |
|
| 59 | + ->params($regularParams) |
|
| 60 | + ->params($multilingualTextParams) |
|
| 61 | 61 | ->escaped(); |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -68,14 +68,14 @@ discard block |
||
| 68 | 68 | * @return MessageParam[]|null list of parameters as accepted by Message::params(), |
| 69 | 69 | * or null if the text is not available in the user’s language |
| 70 | 70 | */ |
| 71 | - protected function renderMultilingualText( MultilingualTextValue $text, ?string $role ): ?array { |
|
| 71 | + protected function renderMultilingualText(MultilingualTextValue $text, ?string $role): ?array { |
|
| 72 | 72 | $texts = $text->getTexts(); |
| 73 | - foreach ( $this->languageFallbackChain->getFetchLanguageCodes() as $languageCode ) { |
|
| 74 | - if ( array_key_exists( $languageCode, $texts ) ) { |
|
| 75 | - return [ Message::rawParam( $this->addRole( |
|
| 76 | - htmlspecialchars( $texts[$languageCode]->getText() ), |
|
| 73 | + foreach ($this->languageFallbackChain->getFetchLanguageCodes() as $languageCode) { |
|
| 74 | + if (array_key_exists($languageCode, $texts)) { |
|
| 75 | + return [Message::rawParam($this->addRole( |
|
| 76 | + htmlspecialchars($texts[$languageCode]->getText()), |
|
| 77 | 77 | $role |
| 78 | - ) ) ]; |
|
| 78 | + ))]; |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -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 | |
@@ -67,17 +67,17 @@ discard block |
||
| 67 | 67 | $this->maxListLength = $maxListLength; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function render( ViolationMessage $violationMessage ): string { |
|
| 70 | + public function render(ViolationMessage $violationMessage): string { |
|
| 71 | 71 | $messageKey = $violationMessage->getMessageKey(); |
| 72 | - $paramsLists = [ [] ]; |
|
| 73 | - foreach ( $violationMessage->getArguments() as $argument ) { |
|
| 74 | - $params = $this->renderArgument( $argument ); |
|
| 72 | + $paramsLists = [[]]; |
|
| 73 | + foreach ($violationMessage->getArguments() as $argument) { |
|
| 74 | + $params = $this->renderArgument($argument); |
|
| 75 | 75 | $paramsLists[] = $params; |
| 76 | 76 | } |
| 77 | - $allParams = array_merge( ...$paramsLists ); |
|
| 77 | + $allParams = array_merge(...$paramsLists); |
|
| 78 | 78 | return $this->messageLocalizer |
| 79 | - ->msg( $messageKey ) |
|
| 80 | - ->params( $allParams ) |
|
| 79 | + ->msg($messageKey) |
|
| 80 | + ->params($allParams) |
|
| 81 | 81 | ->escaped(); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | * @param string|null $role one of the Role::* constants |
| 87 | 87 | * @return string HTML |
| 88 | 88 | */ |
| 89 | - protected function addRole( string $value, ?string $role ): string { |
|
| 90 | - if ( $role === null ) { |
|
| 89 | + protected function addRole(string $value, ?string $role): string { |
|
| 90 | + if ($role === null) { |
|
| 91 | 91 | return $value; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' . |
|
| 95 | - $value . |
|
| 94 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'. |
|
| 95 | + $value. |
|
| 96 | 96 | '</span>'; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -100,15 +100,15 @@ discard block |
||
| 100 | 100 | * @param string $key message key |
| 101 | 101 | * @return string HTML |
| 102 | 102 | */ |
| 103 | - protected function msgEscaped( string $key ): string { |
|
| 104 | - return $this->messageLocalizer->msg( $key )->escaped(); |
|
| 103 | + protected function msgEscaped(string $key): string { |
|
| 104 | + return $this->messageLocalizer->msg($key)->escaped(); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * @param array $argument |
| 109 | 109 | * @return MessageParam[] params (for Message::params) |
| 110 | 110 | */ |
| 111 | - protected function renderArgument( array $argument ): array { |
|
| 111 | + protected function renderArgument(array $argument): array { |
|
| 112 | 112 | $methods = [ |
| 113 | 113 | ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId', |
| 114 | 114 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList', |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | $value = $argument['value']; |
| 130 | 130 | $role = $argument['role']; |
| 131 | 131 | |
| 132 | - if ( array_key_exists( $type, $methods ) ) { |
|
| 132 | + if (array_key_exists($type, $methods)) { |
|
| 133 | 133 | $method = $methods[$type]; |
| 134 | - $params = $this->$method( $value, $role ); |
|
| 134 | + $params = $this->$method($value, $role); |
|
| 135 | 135 | } else { |
| 136 | 136 | throw new InvalidArgumentException( |
| 137 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
| 137 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
| 138 | 138 | ); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -148,36 +148,36 @@ discard block |
||
| 148 | 148 | * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ]) |
| 149 | 149 | * @return MessageParam[] list of parameters as accepted by Message::params() |
| 150 | 150 | */ |
| 151 | - private function renderList( array $list, ?string $role, callable $render ): array { |
|
| 152 | - if ( $list === [] ) { |
|
| 151 | + private function renderList(array $list, ?string $role, callable $render): array { |
|
| 152 | + if ($list === []) { |
|
| 153 | 153 | return [ |
| 154 | - Message::numParam( 0 ), |
|
| 155 | - Message::rawParam( '<ul></ul>' ), |
|
| 154 | + Message::numParam(0), |
|
| 155 | + Message::rawParam('<ul></ul>'), |
|
| 156 | 156 | ]; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if ( count( $list ) > $this->maxListLength ) { |
|
| 160 | - $list = array_slice( $list, 0, $this->maxListLength ); |
|
| 159 | + if (count($list) > $this->maxListLength) { |
|
| 160 | + $list = array_slice($list, 0, $this->maxListLength); |
|
| 161 | 161 | $truncated = true; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | $renderedParamsLists = array_map( |
| 165 | 165 | $render, |
| 166 | 166 | $list, |
| 167 | - array_fill( 0, count( $list ), $role ) |
|
| 167 | + array_fill(0, count($list), $role) |
|
| 168 | 168 | ); |
| 169 | - $renderedParams = array_column( $renderedParamsLists, 0 ); |
|
| 170 | - $renderedElements = array_map( static fn ( MessageParam $msg ) => $msg->getValue(), $renderedParams ); |
|
| 171 | - if ( isset( $truncated ) ) { |
|
| 172 | - $renderedElements[] = $this->msgEscaped( 'ellipsis' ); |
|
| 169 | + $renderedParams = array_column($renderedParamsLists, 0); |
|
| 170 | + $renderedElements = array_map(static fn (MessageParam $msg) => $msg->getValue(), $renderedParams); |
|
| 171 | + if (isset($truncated)) { |
|
| 172 | + $renderedElements[] = $this->msgEscaped('ellipsis'); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | return array_merge( |
| 176 | 176 | [ |
| 177 | - Message::numParam( count( $list ) ), |
|
| 177 | + Message::numParam(count($list)), |
|
| 178 | 178 | Message::rawParam( |
| 179 | - '<ul><li>' . |
|
| 180 | - implode( '</li><li>', $renderedElements ) . |
|
| 179 | + '<ul><li>'. |
|
| 180 | + implode('</li><li>', $renderedElements). |
|
| 181 | 181 | '</li></ul>' |
| 182 | 182 | ), |
| 183 | 183 | ], |
@@ -190,11 +190,11 @@ discard block |
||
| 190 | 190 | * @param string|null $role one of the Role::* constants |
| 191 | 191 | * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
| 192 | 192 | */ |
| 193 | - private function renderEntityId( EntityId $entityId, ?string $role ): array { |
|
| 194 | - return [ Message::rawParam( $this->addRole( |
|
| 195 | - $this->entityIdFormatter->formatEntityId( $entityId ), |
|
| 193 | + private function renderEntityId(EntityId $entityId, ?string $role): array { |
|
| 194 | + return [Message::rawParam($this->addRole( |
|
| 195 | + $this->entityIdFormatter->formatEntityId($entityId), |
|
| 196 | 196 | $role |
| 197 | - ) ) ]; |
|
| 197 | + ))]; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -202,8 +202,8 @@ discard block |
||
| 202 | 202 | * @param string|null $role one of the Role::* constants |
| 203 | 203 | * @return MessageParam[] list of parameters as accepted by Message::params() |
| 204 | 204 | */ |
| 205 | - private function renderEntityIdList( array $entityIdList, ?string $role ): array { |
|
| 206 | - return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] ); |
|
| 205 | + private function renderEntityIdList(array $entityIdList, ?string $role): array { |
|
| 206 | + return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -211,24 +211,24 @@ discard block |
||
| 211 | 211 | * @param string|null $role one of the Role::* constants |
| 212 | 212 | * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
| 213 | 213 | */ |
| 214 | - private function renderItemIdSnakValue( ItemIdSnakValue $value, ?string $role ): array { |
|
| 215 | - switch ( true ) { |
|
| 214 | + private function renderItemIdSnakValue(ItemIdSnakValue $value, ?string $role): array { |
|
| 215 | + switch (true) { |
|
| 216 | 216 | case $value->isValue(): |
| 217 | - return $this->renderEntityId( $value->getItemId(), $role ); |
|
| 217 | + return $this->renderEntityId($value->getItemId(), $role); |
|
| 218 | 218 | case $value->isSomeValue(): |
| 219 | - return [ Message::rawParam( $this->addRole( |
|
| 220 | - '<span class="wikibase-snakview-variation-somevaluesnak">' . |
|
| 221 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-somevalue' ) . |
|
| 219 | + return [Message::rawParam($this->addRole( |
|
| 220 | + '<span class="wikibase-snakview-variation-somevaluesnak">'. |
|
| 221 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-somevalue'). |
|
| 222 | 222 | '</span>', |
| 223 | 223 | $role |
| 224 | - ) ) ]; |
|
| 224 | + ))]; |
|
| 225 | 225 | case $value->isNoValue(): |
| 226 | - return [ Message::rawParam( $this->addRole( |
|
| 227 | - '<span class="wikibase-snakview-variation-novaluesnak">' . |
|
| 228 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-novalue' ) . |
|
| 226 | + return [Message::rawParam($this->addRole( |
|
| 227 | + '<span class="wikibase-snakview-variation-novaluesnak">'. |
|
| 228 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-novalue'). |
|
| 229 | 229 | '</span>', |
| 230 | 230 | $role |
| 231 | - ) ) ]; |
|
| 231 | + ))]; |
|
| 232 | 232 | default: |
| 233 | 233 | // @codeCoverageIgnoreStart |
| 234 | 234 | throw new LogicException( |
@@ -243,8 +243,8 @@ discard block |
||
| 243 | 243 | * @param string|null $role one of the Role::* constants |
| 244 | 244 | * @return MessageParam[] list of parameters as accepted by Message::params() |
| 245 | 245 | */ |
| 246 | - private function renderItemIdSnakValueList( array $valueList, ?string $role ): array { |
|
| 247 | - return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] ); |
|
| 246 | + private function renderItemIdSnakValueList(array $valueList, ?string $role): array { |
|
| 247 | + return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -252,11 +252,11 @@ discard block |
||
| 252 | 252 | * @param string|null $role one of the Role::* constants |
| 253 | 253 | * @return MessageParam[] list of parameters as accepted by Message::params() |
| 254 | 254 | */ |
| 255 | - private function renderDataValue( DataValue $dataValue, ?string $role ): array { |
|
| 256 | - return [ Message::rawParam( $this->addRole( |
|
| 257 | - $this->dataValueFormatter->format( $dataValue ), |
|
| 255 | + private function renderDataValue(DataValue $dataValue, ?string $role): array { |
|
| 256 | + return [Message::rawParam($this->addRole( |
|
| 257 | + $this->dataValueFormatter->format($dataValue), |
|
| 258 | 258 | $role |
| 259 | - ) ) ]; |
|
| 259 | + ))]; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * @param string|null $role one of the Role::* constants |
| 265 | 265 | * @return MessageParam[] list of parameters as accepted by Message::params() |
| 266 | 266 | */ |
| 267 | - private function renderDataValueType( string $dataValueType, ?string $role ): array { |
|
| 267 | + private function renderDataValueType(string $dataValueType, ?string $role): array { |
|
| 268 | 268 | $messageKeys = [ |
| 269 | 269 | 'string' => 'datatypes-type-string', |
| 270 | 270 | 'monolingualtext' => 'datatypes-type-monolingualtext', |
@@ -273,15 +273,15 @@ discard block |
||
| 273 | 273 | 'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid', |
| 274 | 274 | ]; |
| 275 | 275 | |
| 276 | - if ( array_key_exists( $dataValueType, $messageKeys ) ) { |
|
| 277 | - return [ Message::rawParam( $this->addRole( |
|
| 278 | - $this->msgEscaped( $messageKeys[$dataValueType] ), |
|
| 276 | + if (array_key_exists($dataValueType, $messageKeys)) { |
|
| 277 | + return [Message::rawParam($this->addRole( |
|
| 278 | + $this->msgEscaped($messageKeys[$dataValueType]), |
|
| 279 | 279 | $role |
| 280 | - ) ) ]; |
|
| 280 | + ))]; |
|
| 281 | 281 | } else { |
| 282 | 282 | // @codeCoverageIgnoreStart |
| 283 | 283 | throw new LogicException( |
| 284 | - 'Unknown data value type ' . $dataValueType |
|
| 284 | + 'Unknown data value type '.$dataValueType |
|
| 285 | 285 | ); |
| 286 | 286 | // @codeCoverageIgnoreEnd |
| 287 | 287 | } |
@@ -292,11 +292,11 @@ discard block |
||
| 292 | 292 | * @param string|null $role one of the Role::* constants |
| 293 | 293 | * @return MessageParam[] list of parameters as accepted by Message::params() |
| 294 | 294 | */ |
| 295 | - private function renderInlineCode( string $code, ?string $role ): array { |
|
| 296 | - return [ Message::rawParam( $this->addRole( |
|
| 297 | - '<code>' . htmlspecialchars( $code ) . '</code>', |
|
| 295 | + private function renderInlineCode(string $code, ?string $role): array { |
|
| 296 | + return [Message::rawParam($this->addRole( |
|
| 297 | + '<code>'.htmlspecialchars($code).'</code>', |
|
| 298 | 298 | $role |
| 299 | - ) ) ]; |
|
| 299 | + ))]; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -304,8 +304,8 @@ discard block |
||
| 304 | 304 | * @param string|null $role one of the Role::* constants |
| 305 | 305 | * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
| 306 | 306 | */ |
| 307 | - private function renderConstraintScope( string $scope, ?string $role ): array { |
|
| 308 | - switch ( $scope ) { |
|
| 307 | + private function renderConstraintScope(string $scope, ?string $role): array { |
|
| 308 | + switch ($scope) { |
|
| 309 | 309 | case Context::TYPE_STATEMENT: |
| 310 | 310 | $itemId = $this->config->get( |
| 311 | 311 | 'WBQualityConstraintsConstraintCheckedOnMainValueId' |
@@ -325,10 +325,10 @@ discard block |
||
| 325 | 325 | // callers should never let this happen, but if it does happen, |
| 326 | 326 | // showing “unknown value” seems reasonable |
| 327 | 327 | // @codeCoverageIgnoreStart |
| 328 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
| 328 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
| 329 | 329 | // @codeCoverageIgnoreEnd |
| 330 | 330 | } |
| 331 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
| 331 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -336,8 +336,8 @@ discard block |
||
| 336 | 336 | * @param string|null $role one of the Role::* constants |
| 337 | 337 | * @return MessageParam[] list of parameters as accepted by Message::params() |
| 338 | 338 | */ |
| 339 | - private function renderConstraintScopeList( array $scopeList, ?string $role ): array { |
|
| 340 | - return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] ); |
|
| 339 | + private function renderConstraintScopeList(array $scopeList, ?string $role): array { |
|
| 340 | + return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
@@ -345,25 +345,25 @@ discard block |
||
| 345 | 345 | * @param string|null $role one of the Role::* constants |
| 346 | 346 | * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
| 347 | 347 | */ |
| 348 | - private function renderPropertyScope( string $scope, ?string $role ): array { |
|
| 349 | - switch ( $scope ) { |
|
| 348 | + private function renderPropertyScope(string $scope, ?string $role): array { |
|
| 349 | + switch ($scope) { |
|
| 350 | 350 | case Context::TYPE_STATEMENT: |
| 351 | - $itemId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
| 351 | + $itemId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
| 352 | 352 | break; |
| 353 | 353 | case Context::TYPE_QUALIFIER: |
| 354 | - $itemId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
| 354 | + $itemId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
| 355 | 355 | break; |
| 356 | 356 | case Context::TYPE_REFERENCE: |
| 357 | - $itemId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
| 357 | + $itemId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
| 358 | 358 | break; |
| 359 | 359 | default: |
| 360 | 360 | // callers should never let this happen, but if it does happen, |
| 361 | 361 | // showing “unknown value” seems reasonable |
| 362 | 362 | // @codeCoverageIgnoreStart |
| 363 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
| 363 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
| 364 | 364 | // @codeCoverageIgnoreEnd |
| 365 | 365 | } |
| 366 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
| 366 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
@@ -371,8 +371,8 @@ discard block |
||
| 371 | 371 | * @param string|null $role one of the Role::* constants |
| 372 | 372 | * @return MessageParam[] list of parameters as accepted by Message::params() |
| 373 | 373 | */ |
| 374 | - private function renderPropertyScopeList( array $scopeList, ?string $role ): array { |
|
| 375 | - return $this->renderList( $scopeList, $role, [ $this, 'renderPropertyScope' ] ); |
|
| 374 | + private function renderPropertyScopeList(array $scopeList, ?string $role): array { |
|
| 375 | + return $this->renderList($scopeList, $role, [$this, 'renderPropertyScope']); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /** |
@@ -380,14 +380,14 @@ discard block |
||
| 380 | 380 | * @param string|null $role one of the Role::* constants |
| 381 | 381 | * @return MessageParam[] list of parameters as accepted by Message::params() |
| 382 | 382 | */ |
| 383 | - private function renderLanguage( string $languageCode, ?string $role ): array { |
|
| 383 | + private function renderLanguage(string $languageCode, ?string $role): array { |
|
| 384 | 384 | return [ |
| 385 | 385 | // ::renderList (through ::renderLanguageList) requires 'raw' parameter |
| 386 | 386 | // so we effectively build Message::plaintextParam here |
| 387 | - Message::rawParam( htmlspecialchars( |
|
| 388 | - $this->languageNameUtils->getLanguageName( $languageCode, $this->userLanguageCode ) |
|
| 389 | - ) ), |
|
| 390 | - Message::plaintextParam( $languageCode ), |
|
| 387 | + Message::rawParam(htmlspecialchars( |
|
| 388 | + $this->languageNameUtils->getLanguageName($languageCode, $this->userLanguageCode) |
|
| 389 | + )), |
|
| 390 | + Message::plaintextParam($languageCode), |
|
| 391 | 391 | ]; |
| 392 | 392 | } |
| 393 | 393 | |
@@ -396,8 +396,8 @@ discard block |
||
| 396 | 396 | * @param string|null $role one of the Role::* constants |
| 397 | 397 | * @return MessageParam[] list of parameters as accepted by Message::params() |
| 398 | 398 | */ |
| 399 | - private function renderLanguageList( array $languageCodes, ?string $role ): array { |
|
| 400 | - return $this->renderList( $languageCodes, $role, [ $this, 'renderLanguage' ] ); |
|
| 399 | + private function renderLanguageList(array $languageCodes, ?string $role): array { |
|
| 400 | + return $this->renderList($languageCodes, $role, [$this, 'renderLanguage']); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | } |
@@ -10,10 +10,10 @@ discard block |
||
| 10 | 10 | use WikibaseQuality\ConstraintReport\Job\UpdateConstraintsTableJob; |
| 11 | 11 | |
| 12 | 12 | // @codeCoverageIgnoreStart |
| 13 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
| 14 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
| 13 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
| 14 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
| 15 | 15 | |
| 16 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
| 16 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
| 17 | 17 | // @codeCoverageIgnoreEnd |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -42,56 +42,56 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public function __construct() { |
| 44 | 44 | parent::__construct(); |
| 45 | - $this->newUpdateConstraintsTableJob = static function ( $propertyIdSerialization ) { |
|
| 45 | + $this->newUpdateConstraintsTableJob = static function($propertyIdSerialization) { |
|
| 46 | 46 | return UpdateConstraintsTableJob::newFromGlobalState( |
| 47 | 47 | Title::newMainPage(), |
| 48 | - [ 'propertyId' => $propertyIdSerialization ] |
|
| 48 | + ['propertyId' => $propertyIdSerialization] |
|
| 49 | 49 | ); |
| 50 | 50 | }; |
| 51 | 51 | |
| 52 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
| 53 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
| 54 | - $this->setBatchSize( 10 ); |
|
| 52 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
| 53 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
| 54 | + $this->setBatchSize(10); |
|
| 55 | 55 | |
| 56 | 56 | // Wikibase classes are not yet loaded, so setup services in a callback run in execute |
| 57 | 57 | // that can be overridden in tests. |
| 58 | - $this->setupServices = function () { |
|
| 58 | + $this->setupServices = function() { |
|
| 59 | 59 | $services = MediaWikiServices::getInstance(); |
| 60 | - $this->propertyInfoLookup = WikibaseRepo::getStore( $services )->getPropertyInfoLookup(); |
|
| 60 | + $this->propertyInfoLookup = WikibaseRepo::getStore($services)->getPropertyInfoLookup(); |
|
| 61 | 61 | }; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | public function execute() { |
| 65 | - ( $this->setupServices )(); |
|
| 66 | - if ( !$this->getConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
| 67 | - $this->error( 'Constraint statements are not enabled. Aborting.' ); |
|
| 65 | + ($this->setupServices)(); |
|
| 66 | + if (!$this->getConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
| 67 | + $this->error('Constraint statements are not enabled. Aborting.'); |
|
| 68 | 68 | return; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | $propertyInfos = $this->propertyInfoLookup->getAllPropertyInfo(); |
| 72 | - $propertyIds = array_keys( $propertyInfos ); |
|
| 72 | + $propertyIds = array_keys($propertyInfos); |
|
| 73 | 73 | |
| 74 | - foreach ( array_chunk( $propertyIds, $this->getBatchSize() ) as $propertyIdsChunk ) { |
|
| 75 | - foreach ( $propertyIdsChunk as $propertyIdSerialization ) { |
|
| 76 | - $this->output( sprintf( |
|
| 74 | + foreach (array_chunk($propertyIds, $this->getBatchSize()) as $propertyIdsChunk) { |
|
| 75 | + foreach ($propertyIdsChunk as $propertyIdSerialization) { |
|
| 76 | + $this->output(sprintf( |
|
| 77 | 77 | 'Importing constraint statements for % 6s... ', |
| 78 | 78 | $propertyIdSerialization ), |
| 79 | 79 | $propertyIdSerialization |
| 80 | 80 | ); |
| 81 | - $startTime = microtime( true ); |
|
| 82 | - $job = ( $this->newUpdateConstraintsTableJob )( $propertyIdSerialization ); |
|
| 81 | + $startTime = microtime(true); |
|
| 82 | + $job = ($this->newUpdateConstraintsTableJob)($propertyIdSerialization); |
|
| 83 | 83 | $job->run(); |
| 84 | - $endTime = microtime( true ); |
|
| 85 | - $millis = ( $endTime - $startTime ) * 1000; |
|
| 86 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
| 84 | + $endTime = microtime(true); |
|
| 85 | + $millis = ($endTime - $startTime) * 1000; |
|
| 86 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - $this->output( 'Waiting for replication... ', 'waitForReplication' ); |
|
| 90 | - $startTime = microtime( true ); |
|
| 89 | + $this->output('Waiting for replication... ', 'waitForReplication'); |
|
| 90 | + $startTime = microtime(true); |
|
| 91 | 91 | $this->waitForReplication(); |
| 92 | - $endTime = microtime( true ); |
|
| 93 | - $millis = ( $endTime - $startTime ) * 1000; |
|
| 94 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), 'waitForReplication' ); |
|
| 92 | + $endTime = microtime(true); |
|
| 93 | + $millis = ($endTime - $startTime) * 1000; |
|
| 94 | + $this->output(sprintf('done in % 6.2f ms.', $millis), 'waitForReplication'); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | EntityIdLookup $entityIdLookup, |
| 50 | 50 | RdfVocabulary $rdfVocabulary |
| 51 | 51 | ) { |
| 52 | - parent::__construct( $page, $context ); |
|
| 52 | + parent::__construct($page, $context); |
|
| 53 | 53 | $this->resultsSource = $resultsSource; |
| 54 | 54 | $this->entityIdLookup = $entityIdLookup; |
| 55 | 55 | $this->rdfVocabulary = $rdfVocabulary; |
@@ -108,8 +108,8 @@ discard block |
||
| 108 | 108 | * @param string $guid |
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | - private function cleanupGuid( $guid ) { |
|
| 112 | - return preg_replace( '/[^\w-]/', '-', $guid ); |
|
| 111 | + private function cleanupGuid($guid) { |
|
| 112 | + return preg_replace('/[^\w-]/', '-', $guid); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -121,63 +121,63 @@ discard block |
||
| 121 | 121 | $response = $this->getRequest()->response(); |
| 122 | 122 | $this->getOutput()->disable(); |
| 123 | 123 | |
| 124 | - if ( !$this->resultsSource instanceof CachingResultsSource ) { |
|
| 124 | + if (!$this->resultsSource instanceof CachingResultsSource) { |
|
| 125 | 125 | // TODO: make configurable whether only cached results are returned |
| 126 | - $response->statusHeader( 501 ); // Not Implemented |
|
| 126 | + $response->statusHeader(501); // Not Implemented |
|
| 127 | 127 | return null; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - $entityId = $this->entityIdLookup->getEntityIdForTitle( $this->getTitle() ); |
|
| 131 | - if ( $entityId === null ) { |
|
| 132 | - $response->statusHeader( 404 ); // Not Found |
|
| 130 | + $entityId = $this->entityIdLookup->getEntityIdForTitle($this->getTitle()); |
|
| 131 | + if ($entityId === null) { |
|
| 132 | + $response->statusHeader(404); // Not Found |
|
| 133 | 133 | return null; |
| 134 | 134 | } |
| 135 | - $revId = $this->getRequest()->getInt( 'revision' ); |
|
| 135 | + $revId = $this->getRequest()->getInt('revision'); |
|
| 136 | 136 | |
| 137 | - $results = $this->resultsSource->getStoredResults( $entityId, $revId ); |
|
| 138 | - if ( $results === null ) { |
|
| 139 | - $response->statusHeader( 204 ); // No Content |
|
| 137 | + $results = $this->resultsSource->getStoredResults($entityId, $revId); |
|
| 138 | + if ($results === null) { |
|
| 139 | + $response->statusHeader(204); // No Content |
|
| 140 | 140 | return null; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | $format = 'ttl'; // TODO: make format an option |
| 144 | 144 | |
| 145 | 145 | $writerFactory = new RdfWriterFactory(); |
| 146 | - $formatName = $writerFactory->getFormatName( $format ); |
|
| 147 | - $contentType = $writerFactory->getMimeTypes( $formatName )[0]; |
|
| 146 | + $formatName = $writerFactory->getFormatName($format); |
|
| 147 | + $contentType = $writerFactory->getMimeTypes($formatName)[0]; |
|
| 148 | 148 | |
| 149 | - $propertyRepo = $this->rdfVocabulary->getEntityRepositoryName( new NumericPropertyId( 'P1' ) ); |
|
| 149 | + $propertyRepo = $this->rdfVocabulary->getEntityRepositoryName(new NumericPropertyId('P1')); |
|
| 150 | 150 | $wds = $this->rdfVocabulary->statementNamespaceNames[$propertyRepo][RdfVocabulary::NS_STATEMENT]; |
| 151 | 151 | |
| 152 | - $writer = $writerFactory->getWriter( $formatName ); |
|
| 153 | - foreach ( [ $wds, RdfVocabulary::NS_ONTOLOGY ] as $ns ) { |
|
| 154 | - $writer->prefix( $ns, $this->rdfVocabulary->getNamespaceURI( $ns ) ); |
|
| 152 | + $writer = $writerFactory->getWriter($formatName); |
|
| 153 | + foreach ([$wds, RdfVocabulary::NS_ONTOLOGY] as $ns) { |
|
| 154 | + $writer->prefix($ns, $this->rdfVocabulary->getNamespaceURI($ns)); |
|
| 155 | 155 | } |
| 156 | 156 | $writer->start(); |
| 157 | 157 | $writtenAny = false; |
| 158 | 158 | |
| 159 | - foreach ( $results->getArray() as $checkResult ) { |
|
| 160 | - if ( $checkResult instanceof NullResult ) { |
|
| 159 | + foreach ($results->getArray() as $checkResult) { |
|
| 160 | + if ($checkResult instanceof NullResult) { |
|
| 161 | 161 | continue; |
| 162 | 162 | } |
| 163 | - if ( $checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS ) { |
|
| 163 | + if ($checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS) { |
|
| 164 | 164 | continue; |
| 165 | 165 | } |
| 166 | 166 | $writtenAny = true; |
| 167 | - $writer->about( $wds, |
|
| 168 | - $this->cleanupGuid( $checkResult->getContextCursor()->getStatementGuid() ) ) |
|
| 169 | - ->say( RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint' ) |
|
| 170 | - ->is( $wds, |
|
| 171 | - $this->cleanupGuid( $checkResult->getConstraint()->getConstraintId() ) ); |
|
| 167 | + $writer->about($wds, |
|
| 168 | + $this->cleanupGuid($checkResult->getContextCursor()->getStatementGuid())) |
|
| 169 | + ->say(RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint') |
|
| 170 | + ->is($wds, |
|
| 171 | + $this->cleanupGuid($checkResult->getConstraint()->getConstraintId())); |
|
| 172 | 172 | } |
| 173 | 173 | $writer->finish(); |
| 174 | - if ( $writtenAny ) { |
|
| 175 | - $response->header( "Content-Type: $contentType; charset=UTF-8" ); |
|
| 174 | + if ($writtenAny) { |
|
| 175 | + $response->header("Content-Type: $contentType; charset=UTF-8"); |
|
| 176 | 176 | echo $writer->drain(); |
| 177 | 177 | } else { |
| 178 | 178 | // Do not output RDF if we haven't written any actual statements. Output 204 instead |
| 179 | 179 | $writer->drain(); |
| 180 | - $response->statusHeader( 204 ); // No Content |
|
| 180 | + $response->statusHeader(204); // No Content |
|
| 181 | 181 | } |
| 182 | 182 | return null; |
| 183 | 183 | } |