@@ -20,47 +20,47 @@ |
||
| 20 | 20 | { |
| 21 | 21 | |
| 22 | 22 | /** @inheritDoc */ |
| 23 | - public function onArticlePurge( $wikiPage ) { |
|
| 23 | + public function onArticlePurge($wikiPage) { |
|
| 24 | 24 | $entityContentFactory = WikibaseRepo::getEntityContentFactory(); |
| 25 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
| 25 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
| 26 | 26 | $entityIdLookup = WikibaseRepo::getEntityIdLookup(); |
| 27 | - $entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
| 28 | - if ( $entityId !== null ) { |
|
| 27 | + $entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle()); |
|
| 28 | + if ($entityId !== null) { |
|
| 29 | 29 | $resultsCache = ResultsCache::getDefaultInstance(); |
| 30 | - $resultsCache->delete( $entityId ); |
|
| 30 | + $resultsCache->delete($entityId); |
|
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** @inheritDoc */ |
| 36 | - public function onBeforePageDisplay( $out, $skin ): void { |
|
| 36 | + public function onBeforePageDisplay($out, $skin): void { |
|
| 37 | 37 | $lookup = WikibaseRepo::getEntityNamespaceLookup(); |
| 38 | 38 | $title = $out->getTitle(); |
| 39 | - if ( $title === null ) { |
|
| 39 | + if ($title === null) { |
|
| 40 | 40 | return; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) { |
|
| 43 | + if (!$lookup->isNamespaceWithEntities($title->getNamespace())) { |
|
| 44 | 44 | return; |
| 45 | 45 | } |
| 46 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
| 46 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
| 47 | 47 | return; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | $services = MediaWikiServices::getInstance(); |
| 51 | 51 | $config = $services->getMainConfig(); |
| 52 | 52 | |
| 53 | - $isMobileView = ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) && |
|
| 54 | - $services->getService( 'MobileFrontend.Context' )->shouldDisplayMobileView(); |
|
| 55 | - if ( $isMobileView ) { |
|
| 53 | + $isMobileView = ExtensionRegistry::getInstance()->isLoaded('MobileFrontend') && |
|
| 54 | + $services->getService('MobileFrontend.Context')->shouldDisplayMobileView(); |
|
| 55 | + if ($isMobileView) { |
|
| 56 | 56 | return; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
| 59 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
| 60 | 60 | |
| 61 | - if ( $config->get( 'WBQualityConstraintsShowConstraintViolationToNonLoggedInUsers' ) |
|
| 62 | - || $out->getUser()->isRegistered() ) { |
|
| 63 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
| 61 | + if ($config->get('WBQualityConstraintsShowConstraintViolationToNonLoggedInUsers') |
|
| 62 | + || $out->getUser()->isRegistered()) { |
|
| 63 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
@@ -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; |
| 6 | 6 | |
@@ -33,55 +33,55 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** @inheritDoc */ |
| 36 | - public function onWikibaseChangeNotification( Change $change ): void { |
|
| 37 | - if ( !( $change instanceof EntityChange ) ) { |
|
| 36 | + public function onWikibaseChangeNotification(Change $change): void { |
|
| 37 | + if (!($change instanceof EntityChange)) { |
|
| 38 | 38 | return; |
| 39 | 39 | } |
| 40 | 40 | /** @var EntityChange $change */ |
| 41 | 41 | |
| 42 | 42 | // If jobs are enabled and the results would be stored in some way run a job. |
| 43 | 43 | if ( |
| 44 | - $this->config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
| 45 | - $this->config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
| 44 | + $this->config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
| 45 | + $this->config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
| 46 | 46 | $this->isSelectedForJobRunBasedOnPercentage() |
| 47 | 47 | ) { |
| 48 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
| 48 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
| 49 | 49 | $this->jobQueueGroup->lazyPush( |
| 50 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
| 50 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
| 51 | 51 | ); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if ( $this->config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
| 55 | - $this->isConstraintStatementsChange( $change ) |
|
| 54 | + if ($this->config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
| 55 | + $this->isConstraintStatementsChange($change) |
|
| 56 | 56 | ) { |
| 57 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
| 57 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
| 58 | 58 | $metadata = $change->getMetadata(); |
| 59 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
| 59 | + if (array_key_exists('rev_id', $metadata)) { |
|
| 60 | 60 | $params['revisionId'] = $metadata['rev_id']; |
| 61 | 61 | } |
| 62 | 62 | $this->jobQueueGroup->push( |
| 63 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
| 63 | + new JobSpecification('constraintsTableUpdate', $params) |
|
| 64 | 64 | ); |
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | private function isSelectedForJobRunBasedOnPercentage(): bool { |
| 69 | - $percentage = $this->config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
| 69 | + $percentage = $this->config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
| 70 | 70 | |
| 71 | - return mt_rand( 1, 100 ) <= $percentage; |
|
| 71 | + return mt_rand(1, 100) <= $percentage; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - private function isConstraintStatementsChange( Change $change ): bool { |
|
| 75 | - if ( !( $change instanceof EntityChange ) || |
|
| 74 | + private function isConstraintStatementsChange(Change $change): bool { |
|
| 75 | + if (!($change instanceof EntityChange) || |
|
| 76 | 76 | $change->getAction() !== EntityChange::UPDATE || |
| 77 | - !( $change->getEntityId() instanceof NumericPropertyId ) |
|
| 77 | + !($change->getEntityId() instanceof NumericPropertyId) |
|
| 78 | 78 | ) { |
| 79 | 79 | return false; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $info = $change->getInfo(); |
| 83 | 83 | |
| 84 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
| 84 | + if (!array_key_exists('compactDiff', $info)) { |
|
| 85 | 85 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
| 86 | 86 | // so we only know that the change *might* affect the constraint statements |
| 87 | 87 | return true; |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | /** @var EntityDiffChangedAspects $aspects */ |
| 91 | 91 | $aspects = $info['compactDiff']; |
| 92 | 92 | |
| 93 | - $propertyConstraintId = $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
| 94 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
| 93 | + $propertyConstraintId = $this->config->get('WBQualityConstraintsPropertyConstraintId'); |
|
| 94 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | } |
@@ -29,9 +29,9 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | private $isSortable; |
| 31 | 31 | |
| 32 | - public function __construct( array $headers ) { |
|
| 33 | - foreach ( $headers as $header ) { |
|
| 34 | - $this->addHeader( $header ); |
|
| 32 | + public function __construct(array $headers) { |
|
| 33 | + foreach ($headers as $header) { |
|
| 34 | + $this->addHeader($header); |
|
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | |
@@ -40,16 +40,16 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @throws InvalidArgumentException |
| 42 | 42 | */ |
| 43 | - private function addHeader( $header ) { |
|
| 44 | - Assert::parameterType( [ 'string', HtmlTableHeaderBuilder::class ], $header, '$header' ); |
|
| 43 | + private function addHeader($header) { |
|
| 44 | + Assert::parameterType(['string', HtmlTableHeaderBuilder::class], $header, '$header'); |
|
| 45 | 45 | |
| 46 | - if ( is_string( $header ) ) { |
|
| 47 | - $header = new HtmlTableHeaderBuilder( $header ); |
|
| 46 | + if (is_string($header)) { |
|
| 47 | + $header = new HtmlTableHeaderBuilder($header); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | $this->headers[] = $header; |
| 51 | 51 | |
| 52 | - if ( $header->getIsSortable() ) { |
|
| 52 | + if ($header->getIsSortable()) { |
|
| 53 | 53 | $this->isSortable = true; |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -82,12 +82,12 @@ discard block |
||
| 82 | 82 | * |
| 83 | 83 | * @throws InvalidArgumentException |
| 84 | 84 | */ |
| 85 | - public function appendRow( array $cells ) { |
|
| 86 | - foreach ( $cells as $key => $cell ) { |
|
| 87 | - if ( is_string( $cell ) ) { |
|
| 88 | - $cells[$key] = new HtmlTableCellBuilder( $cell ); |
|
| 89 | - } elseif ( !( $cell instanceof HtmlTableCellBuilder ) ) { |
|
| 90 | - throw new InvalidArgumentException( '$cells must be array of HtmlTableCell objects.' ); |
|
| 85 | + public function appendRow(array $cells) { |
|
| 86 | + foreach ($cells as $key => $cell) { |
|
| 87 | + if (is_string($cell)) { |
|
| 88 | + $cells[$key] = new HtmlTableCellBuilder($cell); |
|
| 89 | + } elseif (!($cell instanceof HtmlTableCellBuilder)) { |
|
| 90 | + throw new InvalidArgumentException('$cells must be array of HtmlTableCell objects.'); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | * @throws InvalidArgumentException |
| 103 | 103 | */ |
| 104 | - public function appendRows( array $rows ) { |
|
| 105 | - foreach ( $rows as $cells ) { |
|
| 106 | - if ( !is_array( $cells ) ) { |
|
| 107 | - throw new InvalidArgumentException( '$rows must be array of arrays of HtmlTableCell objects.' ); |
|
| 104 | + public function appendRows(array $rows) { |
|
| 105 | + foreach ($rows as $cells) { |
|
| 106 | + if (!is_array($cells)) { |
|
| 107 | + throw new InvalidArgumentException('$rows must be array of arrays of HtmlTableCell objects.'); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - $this->appendRow( $cells ); |
|
| 110 | + $this->appendRow($cells); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
@@ -119,38 +119,38 @@ discard block |
||
| 119 | 119 | public function toHtml() { |
| 120 | 120 | // Open table |
| 121 | 121 | $tableClasses = 'wikitable'; |
| 122 | - if ( $this->isSortable ) { |
|
| 122 | + if ($this->isSortable) { |
|
| 123 | 123 | $tableClasses .= ' sortable'; |
| 124 | 124 | } |
| 125 | - $html = Html::openElement( 'table', [ 'class' => $tableClasses ] ); |
|
| 125 | + $html = Html::openElement('table', ['class' => $tableClasses]); |
|
| 126 | 126 | |
| 127 | 127 | // Write headers |
| 128 | - $html .= Html::openElement( 'thead' ); |
|
| 129 | - $html .= Html::openElement( 'tr' ); |
|
| 130 | - foreach ( $this->headers as $header ) { |
|
| 128 | + $html .= Html::openElement('thead'); |
|
| 129 | + $html .= Html::openElement('tr'); |
|
| 130 | + foreach ($this->headers as $header) { |
|
| 131 | 131 | $html .= $header->toHtml(); |
| 132 | 132 | } |
| 133 | - $html .= Html::closeElement( 'tr' ); |
|
| 134 | - $html .= Html::closeElement( 'thead' ); |
|
| 135 | - $html .= Html::openElement( 'tbody' ); |
|
| 133 | + $html .= Html::closeElement('tr'); |
|
| 134 | + $html .= Html::closeElement('thead'); |
|
| 135 | + $html .= Html::openElement('tbody'); |
|
| 136 | 136 | |
| 137 | 137 | // Write rows |
| 138 | - foreach ( $this->rows as $row ) { |
|
| 139 | - $html .= Html::openElement( 'tr' ); |
|
| 138 | + foreach ($this->rows as $row) { |
|
| 139 | + $html .= Html::openElement('tr'); |
|
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * @var HtmlTableCellBuilder $cell |
| 143 | 143 | */ |
| 144 | - foreach ( $row as $cell ) { |
|
| 144 | + foreach ($row as $cell) { |
|
| 145 | 145 | $html .= $cell->toHtml(); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $html .= Html::closeElement( 'tr' ); |
|
| 148 | + $html .= Html::closeElement('tr'); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Close table |
| 152 | - $html .= Html::closeElement( 'tbody' ); |
|
| 153 | - $html .= Html::closeElement( 'table' ); |
|
| 152 | + $html .= Html::closeElement('tbody'); |
|
| 153 | + $html .= Html::closeElement('table'); |
|
| 154 | 154 | |
| 155 | 155 | return $html; |
| 156 | 156 | } |
@@ -128,17 +128,17 @@ discard block |
||
| 128 | 128 | public function __construct( |
| 129 | 129 | $messageKey |
| 130 | 130 | ) { |
| 131 | - if ( strpos( $messageKey, self::MESSAGE_KEY_PREFIX ) !== 0 ) { |
|
| 131 | + if (strpos($messageKey, self::MESSAGE_KEY_PREFIX) !== 0) { |
|
| 132 | 132 | throw new InvalidArgumentException( |
| 133 | - 'ViolationMessage key ⧼' . |
|
| 134 | - $messageKey . |
|
| 135 | - '⧽ should start with "' . |
|
| 136 | - self::MESSAGE_KEY_PREFIX . |
|
| 133 | + 'ViolationMessage key ⧼'. |
|
| 134 | + $messageKey. |
|
| 135 | + '⧽ should start with "'. |
|
| 136 | + self::MESSAGE_KEY_PREFIX. |
|
| 137 | 137 | '".' |
| 138 | 138 | ); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $this->messageKeySuffix = substr( $messageKey, strlen( self::MESSAGE_KEY_PREFIX ) ); |
|
| 141 | + $this->messageKeySuffix = substr($messageKey, strlen(self::MESSAGE_KEY_PREFIX)); |
|
| 142 | 142 | $this->arguments = []; |
| 143 | 143 | } |
| 144 | 144 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * @return string |
| 148 | 148 | */ |
| 149 | 149 | public function getMessageKey() { |
| 150 | - return self::MESSAGE_KEY_PREFIX . $this->messageKeySuffix; |
|
| 150 | + return self::MESSAGE_KEY_PREFIX.$this->messageKeySuffix; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | * @param mixed $value the value, which should match the $type |
| 168 | 168 | * @return self |
| 169 | 169 | */ |
| 170 | - public function withArgument( $type, $role, $value ) { |
|
| 170 | + public function withArgument($type, $role, $value) { |
|
| 171 | 171 | $ret = clone $this; |
| 172 | - $ret->arguments[] = [ 'type' => $type, 'role' => $role, 'value' => $value ]; |
|
| 172 | + $ret->arguments[] = ['type' => $type, 'role' => $role, 'value' => $value]; |
|
| 173 | 173 | return $ret; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | * @param string|null $role one of the Role::* constants |
| 182 | 182 | * @return self |
| 183 | 183 | */ |
| 184 | - public function withEntityId( EntityId $entityId, $role = null ) { |
|
| 185 | - return $this->withArgument( self::TYPE_ENTITY_ID, $role, $entityId ); |
|
| 184 | + public function withEntityId(EntityId $entityId, $role = null) { |
|
| 185 | + return $this->withArgument(self::TYPE_ENTITY_ID, $role, $entityId); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -199,8 +199,8 @@ discard block |
||
| 199 | 199 | * @param string|null $role one of the Role::* constants |
| 200 | 200 | * @return self |
| 201 | 201 | */ |
| 202 | - public function withEntityIdList( array $entityIdList, $role = null ) { |
|
| 203 | - return $this->withArgument( self::TYPE_ENTITY_ID_LIST, $role, $entityIdList ); |
|
| 202 | + public function withEntityIdList(array $entityIdList, $role = null) { |
|
| 203 | + return $this->withArgument(self::TYPE_ENTITY_ID_LIST, $role, $entityIdList); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | * @param string|null $role one of the Role::* constants |
| 212 | 212 | * @return self |
| 213 | 213 | */ |
| 214 | - public function withItemIdSnakValue( ItemIdSnakValue $value, $role = null ) { |
|
| 215 | - return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value ); |
|
| 214 | + public function withItemIdSnakValue(ItemIdSnakValue $value, $role = null) { |
|
| 215 | + return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -229,8 +229,8 @@ discard block |
||
| 229 | 229 | * @param string|null $role one of the Role::* constants |
| 230 | 230 | * @return self |
| 231 | 231 | */ |
| 232 | - public function withItemIdSnakValueList( array $valueList, $role = null ) { |
|
| 233 | - return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList ); |
|
| 232 | + public function withItemIdSnakValueList(array $valueList, $role = null) { |
|
| 233 | + return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -241,8 +241,8 @@ discard block |
||
| 241 | 241 | * @param string|null $role one of the Role::* constants |
| 242 | 242 | * @return self |
| 243 | 243 | */ |
| 244 | - public function withDataValue( DataValue $dataValue, $role = null ) { |
|
| 245 | - return $this->withArgument( self::TYPE_DATA_VALUE, $role, $dataValue ); |
|
| 244 | + public function withDataValue(DataValue $dataValue, $role = null) { |
|
| 245 | + return $this->withArgument(self::TYPE_DATA_VALUE, $role, $dataValue); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | * @param string|null $role one of the Role::* constants |
| 258 | 258 | * @return self |
| 259 | 259 | */ |
| 260 | - public function withDataValueType( $dataValueType, $role = null ) { |
|
| 261 | - return $this->withArgument( self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType ); |
|
| 260 | + public function withDataValueType($dataValueType, $role = null) { |
|
| 261 | + return $this->withArgument(self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -269,8 +269,8 @@ discard block |
||
| 269 | 269 | * @param string|null $role one of the Role::* constants |
| 270 | 270 | * @return self |
| 271 | 271 | */ |
| 272 | - public function withInlineCode( $code, $role = null ) { |
|
| 273 | - return $this->withArgument( self::TYPE_INLINE_CODE, $role, $code ); |
|
| 272 | + public function withInlineCode($code, $role = null) { |
|
| 273 | + return $this->withArgument(self::TYPE_INLINE_CODE, $role, $code); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -281,8 +281,8 @@ discard block |
||
| 281 | 281 | * @param string|null $role one of the Role::* constants |
| 282 | 282 | * @return self |
| 283 | 283 | */ |
| 284 | - public function withConstraintScope( $scope, $role = null ) { |
|
| 285 | - return $this->withArgument( self::TYPE_CONSTRAINT_SCOPE, $role, $scope ); |
|
| 284 | + public function withConstraintScope($scope, $role = null) { |
|
| 285 | + return $this->withArgument(self::TYPE_CONSTRAINT_SCOPE, $role, $scope); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -293,8 +293,8 @@ discard block |
||
| 293 | 293 | * @param string|null $role one of the Role::* constants |
| 294 | 294 | * @return self |
| 295 | 295 | */ |
| 296 | - public function withConstraintScopeList( array $scopeList, $role = null ) { |
|
| 297 | - return $this->withArgument( self::TYPE_CONSTRAINT_SCOPE_LIST, $role, $scopeList ); |
|
| 296 | + public function withConstraintScopeList(array $scopeList, $role = null) { |
|
| 297 | + return $this->withArgument(self::TYPE_CONSTRAINT_SCOPE_LIST, $role, $scopeList); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -305,8 +305,8 @@ discard block |
||
| 305 | 305 | * @param string|null $role one of the Role::* constants |
| 306 | 306 | * @return self |
| 307 | 307 | */ |
| 308 | - public function withPropertyScope( $scope, $role = null ) { |
|
| 309 | - return $this->withArgument( self::TYPE_PROPERTY_SCOPE, $role, $scope ); |
|
| 308 | + public function withPropertyScope($scope, $role = null) { |
|
| 309 | + return $this->withArgument(self::TYPE_PROPERTY_SCOPE, $role, $scope); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -317,8 +317,8 @@ discard block |
||
| 317 | 317 | * @param string|null $role one of the Role::* constants |
| 318 | 318 | * @return self |
| 319 | 319 | */ |
| 320 | - public function withPropertyScopeList( array $scopeList, $role = null ) { |
|
| 321 | - return $this->withArgument( self::TYPE_PROPERTY_SCOPE_LIST, $role, $scopeList ); |
|
| 320 | + public function withPropertyScopeList(array $scopeList, $role = null) { |
|
| 321 | + return $this->withArgument(self::TYPE_PROPERTY_SCOPE_LIST, $role, $scopeList); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -333,8 +333,8 @@ discard block |
||
| 333 | 333 | * @param string $languageCode |
| 334 | 334 | * @return self |
| 335 | 335 | */ |
| 336 | - public function withLanguage( $languageCode ) { |
|
| 337 | - return $this->withArgument( self::TYPE_LANGUAGE, null, $languageCode ); |
|
| 336 | + public function withLanguage($languageCode) { |
|
| 337 | + return $this->withArgument(self::TYPE_LANGUAGE, null, $languageCode); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
@@ -349,8 +349,8 @@ discard block |
||
| 349 | 349 | * @param string[] $languageCodes |
| 350 | 350 | * @return self |
| 351 | 351 | */ |
| 352 | - public function withLanguages( $languageCodes ) { |
|
| 353 | - return $this->withArgument( self::TYPE_LANGUAGE_LIST, null, $languageCodes ); |
|
| 352 | + public function withLanguages($languageCodes) { |
|
| 353 | + return $this->withArgument(self::TYPE_LANGUAGE_LIST, null, $languageCodes); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -365,8 +365,8 @@ discard block |
||
| 365 | 365 | * @param string|null $role one of the Role::* constants |
| 366 | 366 | * @return self |
| 367 | 367 | */ |
| 368 | - public function withMultilingualText( MultilingualTextValue $text, $role = null ) { |
|
| 369 | - return $this->withArgument( self::TYPE_MULTILINGUAL_TEXT, $role, $text ); |
|
| 368 | + public function withMultilingualText(MultilingualTextValue $text, $role = null) { |
|
| 369 | + return $this->withArgument(self::TYPE_MULTILINGUAL_TEXT, $role, $text); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | } |
@@ -18,9 +18,9 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | private $violationMessage; |
| 20 | 20 | |
| 21 | - public function __construct( ViolationMessage $violationMessage ) { |
|
| 22 | - $message = '⧼' . $violationMessage->getMessageKey() . '⧽'; |
|
| 23 | - parent::__construct( $message ); |
|
| 21 | + public function __construct(ViolationMessage $violationMessage) { |
|
| 22 | + $message = '⧼'.$violationMessage->getMessageKey().'⧽'; |
|
| 23 | + parent::__construct($message); |
|
| 24 | 24 | |
| 25 | 25 | $this->violationMessage = $violationMessage; |
| 26 | 26 | } |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | $this->statsFactory = $statsFactory; |
| 54 | 54 | $this->logger = $logger; |
| 55 | 55 | $this->constraintCheckDurationLimits = [ |
| 56 | - 'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ), |
|
| 57 | - 'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ), |
|
| 56 | + 'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'), |
|
| 57 | + 'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'), |
|
| 58 | 58 | ]; |
| 59 | 59 | $this->constraintCheckOnEntityDurationLimits = [ |
| 60 | - 'info' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationInfoSeconds' ), |
|
| 61 | - 'warning' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationWarningSeconds' ), |
|
| 60 | + 'info' => $config->get('WBQualityConstraintsCheckOnEntityDurationInfoSeconds'), |
|
| 61 | + 'warning' => $config->get('WBQualityConstraintsCheckOnEntityDurationWarningSeconds'), |
|
| 62 | 62 | ]; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -70,23 +70,23 @@ discard block |
||
| 70 | 70 | * @param float $durationSeconds |
| 71 | 71 | * @return array [ $limitSeconds, $logLevel ] |
| 72 | 72 | */ |
| 73 | - private function findLimit( $limits, $durationSeconds ) { |
|
| 73 | + private function findLimit($limits, $durationSeconds) { |
|
| 74 | 74 | $limitSeconds = null; |
| 75 | 75 | $logLevel = null; |
| 76 | 76 | |
| 77 | - foreach ( $limits as $level => $limit ) { |
|
| 77 | + foreach ($limits as $level => $limit) { |
|
| 78 | 78 | if ( |
| 79 | 79 | // duration exceeds this limit |
| 80 | 80 | $limit !== null && $durationSeconds > $limit && |
| 81 | 81 | // this limit is longer than previous longest limit |
| 82 | - ( $limitSeconds === null || $limit > $limitSeconds ) |
|
| 82 | + ($limitSeconds === null || $limit > $limitSeconds) |
|
| 83 | 83 | ) { |
| 84 | 84 | $limitSeconds = $limit; |
| 85 | 85 | $logLevel = $level; |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - return [ $limitSeconds, $logLevel ]; |
|
| 89 | + return [$limitSeconds, $logLevel]; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -111,30 +111,30 @@ discard block |
||
| 111 | 111 | $durationSeconds, |
| 112 | 112 | $method |
| 113 | 113 | ) { |
| 114 | - $constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 ); |
|
| 114 | + $constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1); |
|
| 115 | 115 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 116 | 116 | |
| 117 | 117 | $baseCheckTimingKey = 'wikibase.quality.constraints.check.timing'; |
| 118 | 118 | $this->statsFactory |
| 119 | - ->getTiming( 'check_constraint_duration_seconds' ) |
|
| 120 | - ->copyToStatsdAt( "$baseCheckTimingKey.$constraintTypeItemId-$constraintCheckerClassShortName" ) |
|
| 121 | - ->observe( $durationSeconds * 1000 ); |
|
| 119 | + ->getTiming('check_constraint_duration_seconds') |
|
| 120 | + ->copyToStatsdAt("$baseCheckTimingKey.$constraintTypeItemId-$constraintCheckerClassShortName") |
|
| 121 | + ->observe($durationSeconds * 1000); |
|
| 122 | 122 | |
| 123 | 123 | // find the longest limit (and associated log level) that the duration exceeds |
| 124 | - [ $limitSeconds, $logLevel ] = $this->findLimit( |
|
| 124 | + [$limitSeconds, $logLevel] = $this->findLimit( |
|
| 125 | 125 | $this->constraintCheckDurationLimits, |
| 126 | 126 | $durationSeconds |
| 127 | 127 | ); |
| 128 | - if ( $limitSeconds === null ) { |
|
| 128 | + if ($limitSeconds === null) { |
|
| 129 | 129 | return; |
| 130 | 130 | } |
| 131 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
| 131 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
| 132 | 132 | // TODO log less details but still log something |
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | $resultMessage = $result->getMessage(); |
| 137 | - if ( $resultMessage !== null ) { |
|
| 137 | + if ($resultMessage !== null) { |
|
| 138 | 138 | $resultMessageKey = $resultMessage->getMessageKey(); |
| 139 | 139 | } else { |
| 140 | 140 | $resultMessageKey = null; |
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | $this->logger->log( |
| 144 | 144 | $logLevel, |
| 145 | - 'Constraint check with {constraintCheckerClassShortName} ' . |
|
| 146 | - 'took longer than {limitSeconds} second(s) ' . |
|
| 145 | + 'Constraint check with {constraintCheckerClassShortName} '. |
|
| 146 | + 'took longer than {limitSeconds} second(s) '. |
|
| 147 | 147 | '(duration: {durationSeconds} seconds).', |
| 148 | 148 | [ |
| 149 | 149 | 'method' => $method, |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | 'constraintId' => $constraint->getConstraintId(), |
| 154 | 154 | 'constraintPropertyId' => $constraint->getPropertyId()->getSerialization(), |
| 155 | 155 | 'constraintTypeItemId' => $constraintTypeItemId, |
| 156 | - 'constraintParameters' => json_encode( $constraint->getConstraintParameters() ), |
|
| 156 | + 'constraintParameters' => json_encode($constraint->getConstraintParameters()), |
|
| 157 | 157 | 'constraintCheckerClass' => $constraintCheckerClass, |
| 158 | 158 | 'constraintCheckerClassShortName' => $constraintCheckerClassShortName, |
| 159 | 159 | 'entityId' => $context->getEntity()->getId()->getSerialization(), |
@@ -185,23 +185,23 @@ discard block |
||
| 185 | 185 | ) { |
| 186 | 186 | $checkEntityTimingKey = 'wikibase.quality.constraints.check.entity.timing'; |
| 187 | 187 | $this->statsFactory |
| 188 | - ->getTiming( 'check_entity_constraint_duration_seconds' ) |
|
| 189 | - ->copyToStatsdAt( $checkEntityTimingKey ) |
|
| 190 | - ->observe( $durationSeconds * 1000 ); |
|
| 188 | + ->getTiming('check_entity_constraint_duration_seconds') |
|
| 189 | + ->copyToStatsdAt($checkEntityTimingKey) |
|
| 190 | + ->observe($durationSeconds * 1000); |
|
| 191 | 191 | |
| 192 | 192 | // find the longest limit (and associated log level) that the duration exceeds |
| 193 | - [ $limitSeconds, $logLevel ] = $this->findLimit( |
|
| 193 | + [$limitSeconds, $logLevel] = $this->findLimit( |
|
| 194 | 194 | $this->constraintCheckOnEntityDurationLimits, |
| 195 | 195 | $durationSeconds |
| 196 | 196 | ); |
| 197 | - if ( $limitSeconds === null ) { |
|
| 197 | + if ($limitSeconds === null) { |
|
| 198 | 198 | return; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | $this->logger->log( |
| 202 | 202 | $logLevel, |
| 203 | - 'Full constraint check on {entityId} ' . |
|
| 204 | - 'took longer than {limitSeconds} second(s) ' . |
|
| 203 | + 'Full constraint check on {entityId} '. |
|
| 204 | + 'took longer than {limitSeconds} second(s) '. |
|
| 205 | 205 | '(duration: {durationSeconds} seconds).', |
| 206 | 206 | [ |
| 207 | 207 | 'method' => $method, |
@@ -217,9 +217,9 @@ discard block |
||
| 217 | 217 | /** |
| 218 | 218 | * Log a cache hit for a complete constraint check result for the given entity ID. |
| 219 | 219 | */ |
| 220 | - public function logCheckConstraintsCacheHit( EntityId $entityId ) { |
|
| 220 | + public function logCheckConstraintsCacheHit(EntityId $entityId) { |
|
| 221 | 221 | $cacheEntityHitKey = 'wikibase.quality.constraints.cache.entity.hit'; |
| 222 | - $metric = $this->statsFactory->getCounter( 'cache_entity_hit_total' ); |
|
| 222 | + $metric = $this->statsFactory->getCounter('cache_entity_hit_total'); |
|
| 223 | 223 | $metric->copyToStatsdAt( |
| 224 | 224 | $cacheEntityHitKey, |
| 225 | 225 | )->increment(); |
@@ -230,12 +230,12 @@ discard block |
||
| 230 | 230 | * |
| 231 | 231 | * @param EntityId[] $entityIds |
| 232 | 232 | */ |
| 233 | - public function logCheckConstraintsCacheMisses( array $entityIds ) { |
|
| 233 | + public function logCheckConstraintsCacheMisses(array $entityIds) { |
|
| 234 | 234 | $cacheEntityMissKey = 'wikibase.quality.constraints.cache.entity.miss'; |
| 235 | - $metric = $this->statsFactory->getCounter( 'cache_entity_miss_total' ); |
|
| 235 | + $metric = $this->statsFactory->getCounter('cache_entity_miss_total'); |
|
| 236 | 236 | $metric->copyToStatsdAt( |
| 237 | 237 | $cacheEntityMissKey, |
| 238 | - )->incrementBy( count( $entityIds ) ); |
|
| 238 | + )->incrementBy(count($entityIds)); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -261,17 +261,17 @@ discard block |
||
| 261 | 261 | * @param EntityId[] $entityIds |
| 262 | 262 | * @param int $maxRevisionIds |
| 263 | 263 | */ |
| 264 | - public function logHugeDependencyMetadata( array $entityIds, $maxRevisionIds ) { |
|
| 264 | + public function logHugeDependencyMetadata(array $entityIds, $maxRevisionIds) { |
|
| 265 | 265 | $this->logger->log( |
| 266 | 266 | 'warning', |
| 267 | - 'Dependency metadata for constraint check result has huge set of entity IDs ' . |
|
| 268 | - '(count ' . count( $entityIds ) . ', limit ' . $maxRevisionIds . '); ' . |
|
| 267 | + 'Dependency metadata for constraint check result has huge set of entity IDs '. |
|
| 268 | + '(count '.count($entityIds).', limit '.$maxRevisionIds.'); '. |
|
| 269 | 269 | 'caching disabled for this check result.', |
| 270 | 270 | [ |
| 271 | 271 | 'loggingMethod' => __METHOD__, |
| 272 | 272 | 'entityIds' => json_encode( |
| 273 | 273 | array_map( |
| 274 | - static function ( EntityId $entityId ) { |
|
| 274 | + static function(EntityId $entityId) { |
|
| 275 | 275 | return $entityId->getSerialization(); |
| 276 | 276 | }, |
| 277 | 277 | $entityIds |
@@ -290,17 +290,17 @@ discard block |
||
| 290 | 290 | 'Sparql API replied with status 429 and a retry-after header. Requesting to retry after {retryAfterTime}', |
| 291 | 291 | [ |
| 292 | 292 | 'retryAfterTime' => $retryAfterTime, |
| 293 | - 'responseHeaders' => json_encode( $request->getResponseHeaders() ), |
|
| 293 | + 'responseHeaders' => json_encode($request->getResponseHeaders()), |
|
| 294 | 294 | 'responseContent' => $request->getContent(), |
| 295 | 295 | ] |
| 296 | 296 | ); |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - public function logSparqlHelperTooManyRequestsRetryAfterInvalid( MWHttpRequest $request ) { |
|
| 299 | + public function logSparqlHelperTooManyRequestsRetryAfterInvalid(MWHttpRequest $request) { |
|
| 300 | 300 | $this->logger->warning( |
| 301 | 301 | 'Sparql API replied with status 429 and no valid retry-after header.', |
| 302 | 302 | [ |
| 303 | - 'responseHeaders' => json_encode( $request->getResponseHeaders() ), |
|
| 303 | + 'responseHeaders' => json_encode($request->getResponseHeaders()), |
|
| 304 | 304 | 'responseContent' => $request->getContent(), |
| 305 | 305 | ] |
| 306 | 306 | ); |
@@ -37,25 +37,25 @@ discard block |
||
| 37 | 37 | * @param Title $title |
| 38 | 38 | * @param string[] $params should contain 'entityId' => 'Q1234' |
| 39 | 39 | */ |
| 40 | - public function __construct( Title $title, array $params ) { |
|
| 41 | - parent::__construct( self::COMMAND, $title, $params ); |
|
| 40 | + public function __construct(Title $title, array $params) { |
|
| 41 | + parent::__construct(self::COMMAND, $title, $params); |
|
| 42 | 42 | $this->removeDuplicates = true; |
| 43 | 43 | |
| 44 | - Assert::parameterType( 'string', $params['entityId'], '$params[\'entityId\']' ); |
|
| 44 | + Assert::parameterType('string', $params['entityId'], '$params[\'entityId\']'); |
|
| 45 | 45 | |
| 46 | - $resultSource = ConstraintsServices::getResultsSource( MediaWikiServices::getInstance() ); |
|
| 46 | + $resultSource = ConstraintsServices::getResultsSource(MediaWikiServices::getInstance()); |
|
| 47 | 47 | '@phan-var CachingResultsSource $resultSource'; |
| 48 | 48 | // This job should only ever be used when caching result sources are used. |
| 49 | - $this->setResultsSource( $resultSource ); |
|
| 49 | + $this->setResultsSource($resultSource); |
|
| 50 | 50 | |
| 51 | - $this->setEntityIdParser( WikibaseRepo::getEntityIdParser() ); |
|
| 51 | + $this->setEntityIdParser(WikibaseRepo::getEntityIdParser()); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public function setResultsSource( CachingResultsSource $resultsSource ) { |
|
| 54 | + public function setResultsSource(CachingResultsSource $resultsSource) { |
|
| 55 | 55 | $this->resultsSource = $resultsSource; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - public function setEntityIdParser( EntityIdParser $parser ) { |
|
| 58 | + public function setEntityIdParser(EntityIdParser $parser) { |
|
| 59 | 59 | $this->entityIdParser = $parser; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -66,19 +66,19 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function run() { |
| 68 | 68 | try { |
| 69 | - $entityId = $this->entityIdParser->parse( $this->params['entityId'] ); |
|
| 70 | - } catch ( EntityIdParsingException ) { |
|
| 69 | + $entityId = $this->entityIdParser->parse($this->params['entityId']); |
|
| 70 | + } catch (EntityIdParsingException) { |
|
| 71 | 71 | return false; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $this->checkConstraints( $entityId ); |
|
| 74 | + $this->checkConstraints($entityId); |
|
| 75 | 75 | |
| 76 | 76 | return true; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - private function checkConstraints( EntityId $entityId ) { |
|
| 79 | + private function checkConstraints(EntityId $entityId) { |
|
| 80 | 80 | $this->resultsSource->getResults( |
| 81 | - [ $entityId ], |
|
| 81 | + [$entityId], |
|
| 82 | 82 | [], |
| 83 | 83 | null, |
| 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\Specials; |
| 6 | 6 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | Config $config, |
| 92 | 92 | StatsFactory $statsFactory |
| 93 | 93 | ) { |
| 94 | - parent::__construct( 'ConstraintReport' ); |
|
| 94 | + parent::__construct('ConstraintReport'); |
|
| 95 | 95 | |
| 96 | 96 | $this->entityLookup = $entityLookup; |
| 97 | 97 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | $this->violationMessageRenderer = $violationMessageRendererFactory->getViolationMessageRenderer( |
| 113 | 113 | $language, |
| 114 | - $languageFallbackChainFactory->newFromLanguage( $language ), |
|
| 114 | + $languageFallbackChainFactory->newFromLanguage($language), |
|
| 115 | 115 | $this->getContext() |
| 116 | 116 | ); |
| 117 | 117 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @inheritDoc |
| 146 | 146 | */ |
| 147 | 147 | public function getDescription() { |
| 148 | - return $this->msg( 'wbqc-constraintreport' ); |
|
| 148 | + return $this->msg('wbqc-constraintreport'); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -157,75 +157,75 @@ discard block |
||
| 157 | 157 | * @throws EntityIdParsingException |
| 158 | 158 | * @throws UnexpectedValueException |
| 159 | 159 | */ |
| 160 | - public function execute( $subPage ) { |
|
| 160 | + public function execute($subPage) { |
|
| 161 | 161 | $out = $this->getOutput(); |
| 162 | 162 | |
| 163 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
| 164 | - if ( $postRequest ) { |
|
| 163 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
| 164 | + if ($postRequest) { |
|
| 165 | 165 | try { |
| 166 | - $entityId = $this->entityIdParser->parse( $postRequest ); |
|
| 167 | - $out->redirect( $this->getPageTitle( $entityId->getSerialization() )->getLocalURL() ); |
|
| 166 | + $entityId = $this->entityIdParser->parse($postRequest); |
|
| 167 | + $out->redirect($this->getPageTitle($entityId->getSerialization())->getLocalURL()); |
|
| 168 | 168 | return; |
| 169 | - } catch ( EntityIdParsingException ) { |
|
| 169 | + } catch (EntityIdParsingException) { |
|
| 170 | 170 | // fall through, error is shown later |
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | $out->enableOOUI(); |
| 175 | - $out->addModules( $this->getModules() ); |
|
| 175 | + $out->addModules($this->getModules()); |
|
| 176 | 176 | |
| 177 | 177 | $this->setHeaders(); |
| 178 | 178 | |
| 179 | - $out->addHTML( $this->getExplanationText() ); |
|
| 179 | + $out->addHTML($this->getExplanationText()); |
|
| 180 | 180 | $this->buildEntityIdForm(); |
| 181 | 181 | |
| 182 | - if ( $postRequest ) { |
|
| 182 | + if ($postRequest) { |
|
| 183 | 183 | // must be an invalid entity ID (otherwise we would have redirected and returned above) |
| 184 | 184 | $out->addHTML( |
| 185 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
| 185 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
| 186 | 186 | ); |
| 187 | 187 | return; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - if ( !$subPage ) { |
|
| 190 | + if (!$subPage) { |
|
| 191 | 191 | return; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - if ( !is_string( $subPage ) ) { |
|
| 195 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
| 194 | + if (!is_string($subPage)) { |
|
| 195 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | try { |
| 199 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
| 200 | - } catch ( EntityIdParsingException ) { |
|
| 199 | + $entityId = $this->entityIdParser->parse($subPage); |
|
| 200 | + } catch (EntityIdParsingException) { |
|
| 201 | 201 | $out->addHTML( |
| 202 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
| 202 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
| 203 | 203 | ); |
| 204 | 204 | return; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
| 207 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
| 208 | 208 | $out->addHTML( |
| 209 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
| 209 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
| 210 | 210 | ); |
| 211 | 211 | return; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | $baseKey = 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck'; |
| 215 | - $metric = $this->statsFactory->getCounter( 'special_constraint_report_execute_check_total' ); |
|
| 216 | - $metric->copyToStatsdAt( $baseKey )->increment(); |
|
| 217 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
| 215 | + $metric = $this->statsFactory->getCounter('special_constraint_report_execute_check_total'); |
|
| 216 | + $metric->copyToStatsdAt($baseKey)->increment(); |
|
| 217 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
| 218 | 218 | |
| 219 | - if ( $results !== [] ) { |
|
| 219 | + if ($results !== []) { |
|
| 220 | 220 | $out->addHTML( |
| 221 | - $this->buildResultHeader( $entityId ) |
|
| 222 | - . $this->buildSummary( $results ) |
|
| 223 | - . $this->buildResultTable( $entityId, $results ) |
|
| 221 | + $this->buildResultHeader($entityId) |
|
| 222 | + . $this->buildSummary($results) |
|
| 223 | + . $this->buildResultTable($entityId, $results) |
|
| 224 | 224 | ); |
| 225 | 225 | } else { |
| 226 | 226 | $out->addHTML( |
| 227 | - $this->buildResultHeader( $entityId ) |
|
| 228 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
| 227 | + $this->buildResultHeader($entityId) |
|
| 228 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
| 229 | 229 | ); |
| 230 | 230 | } |
| 231 | 231 | } |
@@ -241,16 +241,16 @@ discard block |
||
| 241 | 241 | 'name' => 'entityid', |
| 242 | 242 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
| 243 | 243 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
| 244 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped(), |
|
| 244 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped(), |
|
| 245 | 245 | 'required' => true, |
| 246 | 246 | ], |
| 247 | 247 | ]; |
| 248 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
| 249 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
| 250 | - $htmlForm->setSubmitCallback( static function () { |
|
| 248 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
| 249 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
| 250 | + $htmlForm->setSubmitCallback(static function() { |
|
| 251 | 251 | return false; |
| 252 | 252 | } ); |
| 253 | - $htmlForm->setMethod( 'post' ); |
|
| 253 | + $htmlForm->setMethod('post'); |
|
| 254 | 254 | $htmlForm->show(); |
| 255 | 255 | } |
| 256 | 256 | |
@@ -264,9 +264,9 @@ discard block |
||
| 264 | 264 | * |
| 265 | 265 | * @return string HTML |
| 266 | 266 | */ |
| 267 | - private function buildNotice( string $messageKey, bool $error = false ): string { |
|
| 267 | + private function buildNotice(string $messageKey, bool $error = false): string { |
|
| 268 | 268 | $cssClasses = 'wbqc-constraintreport-notice'; |
| 269 | - if ( $error ) { |
|
| 269 | + if ($error) { |
|
| 270 | 270 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
| 271 | 271 | } |
| 272 | 272 | |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | [ |
| 276 | 276 | 'class' => $cssClasses, |
| 277 | 277 | ], |
| 278 | - $this->msg( $messageKey )->escaped() |
|
| 278 | + $this->msg($messageKey)->escaped() |
|
| 279 | 279 | ); |
| 280 | 280 | } |
| 281 | 281 | |
@@ -285,16 +285,16 @@ discard block |
||
| 285 | 285 | private function getExplanationText(): string { |
| 286 | 286 | return Html::rawElement( |
| 287 | 287 | 'div', |
| 288 | - [ 'class' => 'wbqc-explanation' ], |
|
| 288 | + ['class' => 'wbqc-explanation'], |
|
| 289 | 289 | Html::rawElement( |
| 290 | 290 | 'p', |
| 291 | 291 | [], |
| 292 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
| 292 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
| 293 | 293 | ) |
| 294 | 294 | . Html::rawElement( |
| 295 | 295 | 'p', |
| 296 | 296 | [], |
| 297 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
| 297 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
| 298 | 298 | ) |
| 299 | 299 | ); |
| 300 | 300 | } |
@@ -305,31 +305,31 @@ discard block |
||
| 305 | 305 | * |
| 306 | 306 | * @return string HTML |
| 307 | 307 | */ |
| 308 | - private function buildResultTable( EntityId $entityId, array $results ): string { |
|
| 308 | + private function buildResultTable(EntityId $entityId, array $results): string { |
|
| 309 | 309 | // Set table headers |
| 310 | 310 | $table = new HtmlTableBuilder( |
| 311 | 311 | [ |
| 312 | 312 | new HtmlTableHeaderBuilder( |
| 313 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->text(), |
|
| 313 | + $this->msg('wbqc-constraintreport-result-table-header-status')->text(), |
|
| 314 | 314 | true |
| 315 | 315 | ), |
| 316 | 316 | new HtmlTableHeaderBuilder( |
| 317 | - $this->msg( 'wbqc-constraintreport-result-table-header-property' )->text(), |
|
| 317 | + $this->msg('wbqc-constraintreport-result-table-header-property')->text(), |
|
| 318 | 318 | true |
| 319 | 319 | ), |
| 320 | 320 | new HtmlTableHeaderBuilder( |
| 321 | - $this->msg( 'wbqc-constraintreport-result-table-header-message' )->text(), |
|
| 321 | + $this->msg('wbqc-constraintreport-result-table-header-message')->text(), |
|
| 322 | 322 | true |
| 323 | 323 | ), |
| 324 | 324 | new HtmlTableHeaderBuilder( |
| 325 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->text(), |
|
| 325 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->text(), |
|
| 326 | 326 | true |
| 327 | 327 | ), |
| 328 | 328 | ] |
| 329 | 329 | ); |
| 330 | 330 | |
| 331 | - foreach ( $results as $result ) { |
|
| 332 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
| 331 | + foreach ($results as $result) { |
|
| 332 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | return $table->toHtml(); |
@@ -341,35 +341,35 @@ discard block |
||
| 341 | 341 | CheckResult $result |
| 342 | 342 | ): HtmlTableBuilder { |
| 343 | 343 | $message = $result->getMessage(); |
| 344 | - if ( $message === null ) { |
|
| 344 | + if ($message === null) { |
|
| 345 | 345 | // no row for this result |
| 346 | 346 | return $table; |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | // Status column |
| 350 | - $statusColumn = $this->formatStatus( $result->getStatus() ); |
|
| 350 | + $statusColumn = $this->formatStatus($result->getStatus()); |
|
| 351 | 351 | |
| 352 | 352 | // Property column |
| 353 | - $propertyId = new NumericPropertyId( $result->getContextCursor()->getSnakPropertyId() ); |
|
| 353 | + $propertyId = new NumericPropertyId($result->getContextCursor()->getSnakPropertyId()); |
|
| 354 | 354 | $propertyColumn = $this->getClaimLink( |
| 355 | 355 | $entityId, |
| 356 | 356 | $propertyId, |
| 357 | - $this->entityIdLabelFormatter->formatEntityId( $propertyId ) |
|
| 357 | + $this->entityIdLabelFormatter->formatEntityId($propertyId) |
|
| 358 | 358 | ); |
| 359 | 359 | |
| 360 | 360 | // Message column |
| 361 | - $messageColumn = $this->violationMessageRenderer->render( $message ); |
|
| 361 | + $messageColumn = $this->violationMessageRenderer->render($message); |
|
| 362 | 362 | |
| 363 | 363 | // Constraint column |
| 364 | 364 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
| 365 | 365 | try { |
| 366 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
| 367 | - } catch ( InvalidArgumentException ) { |
|
| 368 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
| 366 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
| 367 | + } catch (InvalidArgumentException) { |
|
| 368 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
| 369 | 369 | } |
| 370 | 370 | $constraintColumn = $this->getClaimLink( |
| 371 | 371 | $propertyId, |
| 372 | - new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
| 372 | + new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
| 373 | 373 | $constraintTypeLabel |
| 374 | 374 | ); |
| 375 | 375 | |
@@ -377,16 +377,16 @@ discard block |
||
| 377 | 377 | $table->appendRow( |
| 378 | 378 | [ |
| 379 | 379 | new HtmlTableCellBuilder( |
| 380 | - new HtmlArmor( $statusColumn ) |
|
| 380 | + new HtmlArmor($statusColumn) |
|
| 381 | 381 | ), |
| 382 | 382 | new HtmlTableCellBuilder( |
| 383 | - new HtmlArmor( $propertyColumn ) |
|
| 383 | + new HtmlArmor($propertyColumn) |
|
| 384 | 384 | ), |
| 385 | 385 | new HtmlTableCellBuilder( |
| 386 | - new HtmlArmor( $messageColumn ) |
|
| 386 | + new HtmlArmor($messageColumn) |
|
| 387 | 387 | ), |
| 388 | 388 | new HtmlTableCellBuilder( |
| 389 | - new HtmlArmor( $constraintColumn ) |
|
| 389 | + new HtmlArmor($constraintColumn) |
|
| 390 | 390 | ), |
| 391 | 391 | ] |
| 392 | 392 | ); |
@@ -401,15 +401,15 @@ discard block |
||
| 401 | 401 | * |
| 402 | 402 | * @return string HTML |
| 403 | 403 | */ |
| 404 | - protected function buildResultHeader( EntityId $entityId ): string { |
|
| 405 | - $entityLink = sprintf( '%s (%s)', |
|
| 406 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
| 407 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
| 404 | + protected function buildResultHeader(EntityId $entityId): string { |
|
| 405 | + $entityLink = sprintf('%s (%s)', |
|
| 406 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
| 407 | + htmlspecialchars($entityId->getSerialization())); |
|
| 408 | 408 | |
| 409 | 409 | return Html::rawElement( |
| 410 | 410 | 'h3', |
| 411 | 411 | [], |
| 412 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
| 412 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
| 413 | 413 | ); |
| 414 | 414 | } |
| 415 | 415 | |
@@ -420,24 +420,24 @@ discard block |
||
| 420 | 420 | * |
| 421 | 421 | * @return string HTML |
| 422 | 422 | */ |
| 423 | - protected function buildSummary( array $results ): string { |
|
| 423 | + protected function buildSummary(array $results): string { |
|
| 424 | 424 | $statuses = []; |
| 425 | - foreach ( $results as $result ) { |
|
| 426 | - $status = strtolower( $result->getStatus() ); |
|
| 427 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
| 425 | + foreach ($results as $result) { |
|
| 426 | + $status = strtolower($result->getStatus()); |
|
| 427 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | $statusElements = []; |
| 431 | - foreach ( $statuses as $status => $count ) { |
|
| 432 | - if ( $count > 0 ) { |
|
| 431 | + foreach ($statuses as $status => $count) { |
|
| 432 | + if ($count > 0) { |
|
| 433 | 433 | $statusElements[] = |
| 434 | - $this->formatStatus( $status ) |
|
| 434 | + $this->formatStatus($status) |
|
| 435 | 435 | . ': ' |
| 436 | 436 | . $count; |
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
| 440 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | /** |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | * |
| 450 | 450 | * @return string HTML |
| 451 | 451 | */ |
| 452 | - private function formatStatus( string $status ): string { |
|
| 453 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
| 452 | + private function formatStatus(string $status): string { |
|
| 453 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
| 454 | 454 | $statusIcons = [ |
| 455 | 455 | CheckResult::STATUS_SUGGESTION => [ |
| 456 | 456 | 'icon' => 'suggestion-constraint-violation', |
@@ -467,25 +467,25 @@ discard block |
||
| 467 | 467 | ], |
| 468 | 468 | ]; |
| 469 | 469 | |
| 470 | - if ( array_key_exists( $status, $statusIcons ) ) { |
|
| 471 | - $iconWidget = new IconWidget( $statusIcons[$status] ); |
|
| 472 | - $iconHtml = $iconWidget->toString() . ' '; |
|
| 470 | + if (array_key_exists($status, $statusIcons)) { |
|
| 471 | + $iconWidget = new IconWidget($statusIcons[$status]); |
|
| 472 | + $iconHtml = $iconWidget->toString().' '; |
|
| 473 | 473 | } else { |
| 474 | 474 | $iconHtml = ''; |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | - $labelWidget = new LabelWidget( [ |
|
| 478 | - 'label' => $this->msg( $messageName )->text(), |
|
| 479 | - ] ); |
|
| 477 | + $labelWidget = new LabelWidget([ |
|
| 478 | + 'label' => $this->msg($messageName)->text(), |
|
| 479 | + ]); |
|
| 480 | 480 | $labelHtml = $labelWidget->toString(); |
| 481 | 481 | |
| 482 | 482 | $formattedStatus = |
| 483 | 483 | Html::rawElement( |
| 484 | 484 | 'span', |
| 485 | 485 | [ |
| 486 | - 'class' => 'wbqc-status wbqc-status-' . $status, |
|
| 486 | + 'class' => 'wbqc-status wbqc-status-'.$status, |
|
| 487 | 487 | ], |
| 488 | - $iconHtml . $labelHtml |
|
| 488 | + $iconHtml.$labelHtml |
|
| 489 | 489 | ); |
| 490 | 490 | |
| 491 | 491 | return $formattedStatus; |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | return Html::rawElement( |
| 509 | 509 | 'a', |
| 510 | 510 | [ |
| 511 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
| 511 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
| 512 | 512 | 'target' => '_blank', |
| 513 | 513 | ], |
| 514 | 514 | $text |
@@ -522,8 +522,8 @@ discard block |
||
| 522 | 522 | EntityId $entityId, |
| 523 | 523 | NumericPropertyId $propertyId |
| 524 | 524 | ): string { |
| 525 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
| 526 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
| 525 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
| 526 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
| 527 | 527 | |
| 528 | 528 | return $entityUrl; |
| 529 | 529 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $this->sparqlHelper = $sparqlHelper; |
| 75 | 75 | $this->shellboxClientFactory = $shellboxClientFactory; |
| 76 | 76 | $this->knownGoodPatternsAsKeys = array_fill_keys( |
| 77 | - $this->config->get( 'WBQualityConstraintsFormatCheckerKnownGoodRegexPatterns' ), |
|
| 77 | + $this->config->get('WBQualityConstraintsFormatCheckerKnownGoodRegexPatterns'), |
|
| 78 | 78 | null |
| 79 | 79 | ); |
| 80 | 80 | $this->logger = $logger ?? new NullLogger(); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * @throws ConstraintParameterException |
| 109 | 109 | * @return CheckResult |
| 110 | 110 | */ |
| 111 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
| 111 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
| 112 | 112 | $constraintParameters = $constraint->getConstraintParameters(); |
| 113 | 113 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 114 | 114 | |
@@ -123,9 +123,9 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | $snak = $context->getSnak(); |
| 125 | 125 | |
| 126 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
| 126 | + if (!$snak instanceof PropertyValueSnak) { |
|
| 127 | 127 | // nothing to check |
| 128 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
| 128 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | $dataValue = $snak->getDataValue(); |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * error handling: |
| 135 | 135 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
| 136 | 136 | */ |
| 137 | - switch ( $dataValue->getType() ) { |
|
| 137 | + switch ($dataValue->getType()) { |
|
| 138 | 138 | case 'string': |
| 139 | 139 | $text = $dataValue->getValue(); |
| 140 | 140 | break; |
@@ -144,13 +144,13 @@ discard block |
||
| 144 | 144 | $text = $dataValue->getText(); |
| 145 | 145 | break; |
| 146 | 146 | default: |
| 147 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) ) |
|
| 148 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 149 | - ->withDataValueType( 'string' ) |
|
| 150 | - ->withDataValueType( 'monolingualtext' ); |
|
| 151 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
| 147 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2')) |
|
| 148 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 149 | + ->withDataValueType('string') |
|
| 150 | + ->withDataValueType('monolingualtext'); |
|
| 151 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
| 152 | 152 | } |
| 153 | - $status = $this->runRegexCheck( $text, $format ); |
|
| 153 | + $status = $this->runRegexCheck($text, $format); |
|
| 154 | 154 | $message = $this->formatMessage( |
| 155 | 155 | $status, |
| 156 | 156 | $text, |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $syntaxClarifications, |
| 160 | 160 | $constraintTypeItemId |
| 161 | 161 | ); |
| 162 | - return new CheckResult( $context, $constraint, $status, $message ); |
|
| 162 | + return new CheckResult($context, $constraint, $status, $message); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | private function formatMessage( |
@@ -171,43 +171,43 @@ discard block |
||
| 171 | 171 | string $constraintTypeItemId |
| 172 | 172 | ): ?ViolationMessage { |
| 173 | 173 | $message = null; |
| 174 | - if ( $status === CheckResult::STATUS_VIOLATION ) { |
|
| 175 | - $message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) ) |
|
| 176 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
| 177 | - ->withDataValue( new StringValue( $text ), Role::OBJECT ) |
|
| 178 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 179 | - ->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE ); |
|
| 180 | - } elseif ( $status === CheckResult::STATUS_TODO ) { |
|
| 181 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
| 182 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ); |
|
| 174 | + if ($status === CheckResult::STATUS_VIOLATION) { |
|
| 175 | + $message = (new ViolationMessage('wbqc-violation-message-format-clarification')) |
|
| 176 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
| 177 | + ->withDataValue(new StringValue($text), Role::OBJECT) |
|
| 178 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 179 | + ->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE); |
|
| 180 | + } elseif ($status === CheckResult::STATUS_TODO) { |
|
| 181 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
| 182 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | return $message; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** @throws ConstraintParameterException */ |
| 189 | - private function runRegexCheck( string $text, string $format ): string { |
|
| 190 | - if ( !$this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
| 189 | + private function runRegexCheck(string $text, string $format): string { |
|
| 190 | + if (!$this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
| 191 | 191 | return CheckResult::STATUS_TODO; |
| 192 | 192 | } |
| 193 | - if ( \array_key_exists( $format, $this->knownGoodPatternsAsKeys ) ) { |
|
| 194 | - $checkResult = FormatCheckerHelper::runRegexCheck( $format, $text ); |
|
| 193 | + if (\array_key_exists($format, $this->knownGoodPatternsAsKeys)) { |
|
| 194 | + $checkResult = FormatCheckerHelper::runRegexCheck($format, $text); |
|
| 195 | 195 | } elseif ( |
| 196 | - $this->config->get( 'WBQualityConstraintsFormatCheckerShellboxRatio' ) > (float)wfRandom() |
|
| 196 | + $this->config->get('WBQualityConstraintsFormatCheckerShellboxRatio') > (float) wfRandom() |
|
| 197 | 197 | ) { |
| 198 | - $checkResult = $this->runRegexCheckUsingShellbox( $text, $format ); |
|
| 198 | + $checkResult = $this->runRegexCheckUsingShellbox($text, $format); |
|
| 199 | 199 | } else { |
| 200 | - return $this->runRegexCheckUsingSparql( $text, $format ); |
|
| 200 | + return $this->runRegexCheckUsingSparql($text, $format); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if ( $checkResult === 1 ) { |
|
| 203 | + if ($checkResult === 1) { |
|
| 204 | 204 | return CheckResult::STATUS_COMPLIANCE; |
| 205 | - } elseif ( $checkResult === 0 ) { |
|
| 205 | + } elseif ($checkResult === 0) { |
|
| 206 | 206 | return CheckResult::STATUS_VIOLATION; |
| 207 | - } elseif ( $checkResult === false ) { |
|
| 207 | + } elseif ($checkResult === false) { |
|
| 208 | 208 | throw new ConstraintParameterException( |
| 209 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
| 210 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 209 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
| 210 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 211 | 211 | ); |
| 212 | 212 | } else { |
| 213 | 213 | return $checkResult; |
@@ -221,51 +221,51 @@ discard block |
||
| 221 | 221 | * - FALSE if $format is invalid regex |
| 222 | 222 | * - CheckResult::STATUS_TODO if Shellbox is not enabled |
| 223 | 223 | */ |
| 224 | - private function runRegexCheckUsingShellbox( string $text, string $format ) { |
|
| 225 | - if ( !$this->shellboxClientFactory->isEnabled( 'constraint-regex-checker' ) ) { |
|
| 224 | + private function runRegexCheckUsingShellbox(string $text, string $format) { |
|
| 225 | + if (!$this->shellboxClientFactory->isEnabled('constraint-regex-checker')) { |
|
| 226 | 226 | return CheckResult::STATUS_TODO; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | try { |
| 230 | - return $this->shellboxClientFactory->getClient( [ |
|
| 231 | - 'timeout' => $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ) / 1000, |
|
| 230 | + return $this->shellboxClientFactory->getClient([ |
|
| 231 | + 'timeout' => $this->config->get('WBQualityConstraintsSparqlMaxMillis') / 1000, |
|
| 232 | 232 | 'service' => 'constraint-regex-checker', |
| 233 | - ] )->call( |
|
| 233 | + ])->call( |
|
| 234 | 234 | 'constraint-regex-checker', |
| 235 | - [ FormatCheckerHelper::class, 'runRegexCheck' ], |
|
| 236 | - [ $format, $text ], |
|
| 237 | - [ 'classes' => [ FormatCheckerHelper::class ] ], |
|
| 235 | + [FormatCheckerHelper::class, 'runRegexCheck'], |
|
| 236 | + [$format, $text], |
|
| 237 | + ['classes' => [FormatCheckerHelper::class]], |
|
| 238 | 238 | ); |
| 239 | - } catch ( ClientExceptionInterface $ce ) { |
|
| 240 | - $this->logger->notice( __METHOD__ . ': Network error, skipping check: {exception}', [ |
|
| 239 | + } catch (ClientExceptionInterface $ce) { |
|
| 240 | + $this->logger->notice(__METHOD__.': Network error, skipping check: {exception}', [ |
|
| 241 | 241 | 'exception' => $ce, |
| 242 | 242 | 'text' => $text, |
| 243 | 243 | 'format' => $format, |
| 244 | - ] ); |
|
| 244 | + ]); |
|
| 245 | 245 | return CheckResult::STATUS_TODO; |
| 246 | - } catch ( ShellboxError $e ) { |
|
| 247 | - $this->logger->error( __METHOD__ . ': Shellbox error, skipping check: {exception}', [ |
|
| 246 | + } catch (ShellboxError $e) { |
|
| 247 | + $this->logger->error(__METHOD__.': Shellbox error, skipping check: {exception}', [ |
|
| 248 | 248 | 'exception' => $e, |
| 249 | 249 | 'text' => $text, |
| 250 | 250 | 'format' => $format, |
| 251 | - ] ); |
|
| 251 | + ]); |
|
| 252 | 252 | return CheckResult::STATUS_TODO; |
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - private function runRegexCheckUsingSparql( string $text, string $format ): string { |
|
| 257 | - if ( $this->sparqlHelper instanceof DummySparqlHelper ) { |
|
| 256 | + private function runRegexCheckUsingSparql(string $text, string $format): string { |
|
| 257 | + if ($this->sparqlHelper instanceof DummySparqlHelper) { |
|
| 258 | 258 | return CheckResult::STATUS_TODO; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
| 261 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
| 262 | 262 | return CheckResult::STATUS_COMPLIANCE; |
| 263 | 263 | } else { |
| 264 | 264 | return CheckResult::STATUS_VIOLATION; |
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
| 268 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
| 269 | 269 | $constraintParameters = $constraint->getConstraintParameters(); |
| 270 | 270 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 271 | 271 | $exceptions = []; |
@@ -274,14 +274,14 @@ discard block |
||
| 274 | 274 | $constraintParameters, |
| 275 | 275 | $constraintTypeItemId |
| 276 | 276 | ); |
| 277 | - } catch ( ConstraintParameterException $e ) { |
|
| 277 | + } catch (ConstraintParameterException $e) { |
|
| 278 | 278 | $exceptions[] = $e; |
| 279 | 279 | } |
| 280 | 280 | try { |
| 281 | 281 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
| 282 | 282 | $constraintParameters |
| 283 | 283 | ); |
| 284 | - } catch ( ConstraintParameterException $e ) { |
|
| 284 | + } catch (ConstraintParameterException $e) { |
|
| 285 | 285 | $exceptions[] = $e; |
| 286 | 286 | } |
| 287 | 287 | return $exceptions; |