@@ -76,9 +76,9 @@ discard block |
||
| 76 | 76 | * @throws ConstraintParameterException |
| 77 | 77 | * @return CheckResult |
| 78 | 78 | */ |
| 79 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 80 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 81 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
| 79 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 80 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 81 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -97,22 +97,22 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | $statementList = $context->getEntity() |
| 99 | 99 | ->getStatements() |
| 100 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
| 100 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
| 101 | 101 | |
| 102 | 102 | /* |
| 103 | 103 | * 'Conflicts with' can be defined with |
| 104 | 104 | * a) a property only |
| 105 | 105 | * b) a property and a number of items (each combination of property and item forming an individual claim) |
| 106 | 106 | */ |
| 107 | - if ( $items === [] ) { |
|
| 107 | + if ($items === []) { |
|
| 108 | 108 | $offendingStatement = $this->connectionCheckerHelper->findStatementWithProperty( |
| 109 | 109 | $statementList, |
| 110 | 110 | $propertyId |
| 111 | 111 | ); |
| 112 | - if ( $offendingStatement !== null ) { |
|
| 113 | - $message = ( new ViolationMessage( 'wbqc-violation-message-conflicts-with-property' ) ) |
|
| 114 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
| 115 | - ->withEntityId( $propertyId, Role::PREDICATE ); |
|
| 112 | + if ($offendingStatement !== null) { |
|
| 113 | + $message = (new ViolationMessage('wbqc-violation-message-conflicts-with-property')) |
|
| 114 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
| 115 | + ->withEntityId($propertyId, Role::PREDICATE); |
|
| 116 | 116 | $status = CheckResult::STATUS_VIOLATION; |
| 117 | 117 | } else { |
| 118 | 118 | $message = null; |
@@ -124,12 +124,12 @@ discard block |
||
| 124 | 124 | $propertyId, |
| 125 | 125 | $items |
| 126 | 126 | ); |
| 127 | - if ( $offendingStatement !== null ) { |
|
| 128 | - $offendingValue = ItemIdSnakValue::fromSnak( $offendingStatement->getMainSnak() ); |
|
| 129 | - $message = ( new ViolationMessage( 'wbqc-violation-message-conflicts-with-claim' ) ) |
|
| 130 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
| 131 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
| 132 | - ->withItemIdSnakValue( $offendingValue, Role::OBJECT ); |
|
| 127 | + if ($offendingStatement !== null) { |
|
| 128 | + $offendingValue = ItemIdSnakValue::fromSnak($offendingStatement->getMainSnak()); |
|
| 129 | + $message = (new ViolationMessage('wbqc-violation-message-conflicts-with-claim')) |
|
| 130 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
| 131 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
| 132 | + ->withItemIdSnakValue($offendingValue, Role::OBJECT); |
|
| 133 | 133 | $status = CheckResult::STATUS_VIOLATION; |
| 134 | 134 | } else { |
| 135 | 135 | $message = null; |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - return new CheckResult( $context, $constraint, [], $status, $message ); |
|
| 140 | + return new CheckResult($context, $constraint, [], $status, $message); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 143 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 144 | 144 | $constraintParameters = $constraint->getConstraintParameters(); |
| 145 | 145 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 146 | 146 | $exceptions = []; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $constraintParameters, |
| 150 | 150 | $constraintTypeItemId |
| 151 | 151 | ); |
| 152 | - } catch ( ConstraintParameterException $e ) { |
|
| 152 | + } catch (ConstraintParameterException $e) { |
|
| 153 | 153 | $exceptions[] = $e; |
| 154 | 154 | } |
| 155 | 155 | try { |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | $constraintTypeItemId, |
| 159 | 159 | false |
| 160 | 160 | ); |
| 161 | - } catch ( ConstraintParameterException $e ) { |
|
| 161 | + } catch (ConstraintParameterException $e) { |
|
| 162 | 162 | $exceptions[] = $e; |
| 163 | 163 | } |
| 164 | 164 | return $exceptions; |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | private $constraintParameterParser; |
| 24 | 24 | |
| 25 | - public function __construct( ConstraintParameterParser $constraintParameterParser ) { |
|
| 25 | + public function __construct(ConstraintParameterParser $constraintParameterParser) { |
|
| 26 | 26 | $this->constraintParameterParser = $constraintParameterParser; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | * @throws ConstraintParameterException |
| 69 | 69 | * @return CheckResult |
| 70 | 70 | */ |
| 71 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
| 72 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 73 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
| 71 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
| 72 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 73 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -81,26 +81,26 @@ discard block |
||
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | 83 | $status = CheckResult::STATUS_VIOLATION; |
| 84 | - $message = ( new ViolationMessage( 'wbqc-violation-message-label-lacking' ) ) |
|
| 85 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
| 86 | - ->withLanguages( $languages ); |
|
| 84 | + $message = (new ViolationMessage('wbqc-violation-message-label-lacking')) |
|
| 85 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
| 86 | + ->withLanguages($languages); |
|
| 87 | 87 | |
| 88 | 88 | /** @var LabelsProvider $entity */ |
| 89 | 89 | $entity = $context->getEntity(); |
| 90 | 90 | '@phan-var LabelsProvider $entity'; |
| 91 | 91 | |
| 92 | - foreach ( $languages as $language ) { |
|
| 93 | - if ( $entity->getLabels()->hasTermForLanguage( $language ) ) { |
|
| 92 | + foreach ($languages as $language) { |
|
| 93 | + if ($entity->getLabels()->hasTermForLanguage($language)) { |
|
| 94 | 94 | $message = null; |
| 95 | 95 | $status = CheckResult::STATUS_COMPLIANCE; |
| 96 | 96 | break; |
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - return new CheckResult( $context, $constraint, [], $status, $message ); |
|
| 100 | + return new CheckResult($context, $constraint, [], $status, $message); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
| 103 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
| 104 | 104 | $constraintParameters = $constraint->getConstraintParameters(); |
| 105 | 105 | $exceptions = []; |
| 106 | 106 | try { |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $constraintParameters, |
| 109 | 109 | $constraint->getConstraintTypeItemId() |
| 110 | 110 | ); |
| 111 | - } catch ( ConstraintParameterException $e ) { |
|
| 111 | + } catch (ConstraintParameterException $e) { |
|
| 112 | 112 | $exceptions[] = $e; |
| 113 | 113 | } |
| 114 | 114 | return $exceptions; |
@@ -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\Checker; |
| 6 | 6 | |
@@ -74,26 +74,26 @@ discard block |
||
| 74 | 74 | * @return array first element is the namespace number (default namespace for TitleParser), |
| 75 | 75 | * second element is a string to prepend to the title before giving it to the TitleParser |
| 76 | 76 | */ |
| 77 | - private function getCommonsNamespace( string $namespace ): array { |
|
| 78 | - switch ( $namespace ) { |
|
| 77 | + private function getCommonsNamespace(string $namespace): array { |
|
| 78 | + switch ($namespace) { |
|
| 79 | 79 | case '': |
| 80 | - return [ NS_MAIN, '' ]; |
|
| 80 | + return [NS_MAIN, '']; |
|
| 81 | 81 | // extra namespaces, see operations/mediawiki-config.git, |
| 82 | 82 | // wmf-config/InitialiseSettings.php, 'wgExtraNamespaces' key, 'commonswiki' subkey |
| 83 | 83 | case 'Creator': |
| 84 | - return [ 100, '' ]; |
|
| 84 | + return [100, '']; |
|
| 85 | 85 | case 'TimedText': |
| 86 | - return [ 102, '' ]; |
|
| 86 | + return [102, '']; |
|
| 87 | 87 | case 'Sequence': |
| 88 | - return [ 104, '' ]; |
|
| 88 | + return [104, '']; |
|
| 89 | 89 | case 'Institution': |
| 90 | - return [ 106, '' ]; |
|
| 90 | + return [106, '']; |
|
| 91 | 91 | // extension namespace, see mediawiki/extensions/JsonConfig.git, |
| 92 | 92 | // extension.json, 'namespaces' key, third element |
| 93 | 93 | case 'Data': |
| 94 | - return [ 486, '' ]; |
|
| 94 | + return [486, '']; |
|
| 95 | 95 | default: |
| 96 | - return [ NS_MAIN, $namespace . ':' ]; |
|
| 96 | + return [NS_MAIN, $namespace.':']; |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @throws ConstraintParameterException |
| 104 | 104 | */ |
| 105 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
| 105 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
| 106 | 106 | $constraintParameters = $constraint->getConstraintParameters(); |
| 107 | 107 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 108 | 108 | |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | $snak = $context->getSnak(); |
| 115 | 115 | |
| 116 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
| 116 | + if (!$snak instanceof PropertyValueSnak) { |
|
| 117 | 117 | // nothing to check |
| 118 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
| 118 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $dataValue = $snak->getDataValue(); |
@@ -125,52 +125,52 @@ discard block |
||
| 125 | 125 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
| 126 | 126 | * parameter $namespace can be null, works for commons galleries |
| 127 | 127 | */ |
| 128 | - if ( $dataValue->getType() !== 'string' ) { |
|
| 129 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
| 130 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 131 | - ->withDataValueType( 'string' ); |
|
| 132 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
| 128 | + if ($dataValue->getType() !== 'string') { |
|
| 129 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
| 130 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 131 | + ->withDataValueType('string'); |
|
| 132 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | $commonsLink = $dataValue->getValue(); |
| 136 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
| 137 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, |
|
| 138 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
| 136 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
| 137 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, |
|
| 138 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty( $snak->getPropertyId() ); |
|
| 142 | - switch ( $dataType ) { |
|
| 141 | + $dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty($snak->getPropertyId()); |
|
| 142 | + switch ($dataType) { |
|
| 143 | 143 | case 'geo-shape': |
| 144 | 144 | case 'tabular-data': |
| 145 | - if ( strpos( $commonsLink, $namespace . ':' ) !== 0 ) { |
|
| 146 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, |
|
| 147 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
| 145 | + if (strpos($commonsLink, $namespace.':') !== 0) { |
|
| 146 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, |
|
| 147 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
| 148 | 148 | } |
| 149 | 149 | $pageName = $commonsLink; |
| 150 | 150 | break; |
| 151 | 151 | default: |
| 152 | - $pageName = $namespace ? $namespace . ':' . $commonsLink : $commonsLink; |
|
| 152 | + $pageName = $namespace ? $namespace.':'.$commonsLink : $commonsLink; |
|
| 153 | 153 | break; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - $prefix = $this->getCommonsNamespace( $namespace )[1]; |
|
| 156 | + $prefix = $this->getCommonsNamespace($namespace)[1]; |
|
| 157 | 157 | $normalizedTitle = $this->pageNameNormalizer->normalizePageName( |
| 158 | 158 | $pageName, |
| 159 | 159 | 'https://commons.wikimedia.org/w/api.php' |
| 160 | 160 | ); |
| 161 | - if ( $normalizedTitle === false ) { |
|
| 162 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
| 163 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, |
|
| 164 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
| 161 | + if ($normalizedTitle === false) { |
|
| 162 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
| 163 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, |
|
| 164 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
| 165 | 165 | } |
| 166 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, |
|
| 167 | - new ViolationMessage( 'wbqc-violation-message-commons-link-no-existent' ) ); |
|
| 166 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, |
|
| 167 | + new ViolationMessage('wbqc-violation-message-commons-link-no-existent')); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE, null ); |
|
| 170 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE, null); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
| 173 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
| 174 | 174 | $constraintParameters = $constraint->getConstraintParameters(); |
| 175 | 175 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 176 | 176 | $exceptions = []; |
@@ -179,15 +179,15 @@ discard block |
||
| 179 | 179 | $constraintParameters, |
| 180 | 180 | $constraintTypeItemId |
| 181 | 181 | ); |
| 182 | - } catch ( ConstraintParameterException $e ) { |
|
| 182 | + } catch (ConstraintParameterException $e) { |
|
| 183 | 183 | $exceptions[] = $e; |
| 184 | 184 | } |
| 185 | 185 | return $exceptions; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - private function commonsLinkIsWellFormed( string $commonsLink ): bool { |
|
| 189 | - $toReplace = [ "_", "%20" ]; |
|
| 190 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
| 188 | + private function commonsLinkIsWellFormed(string $commonsLink): bool { |
|
| 189 | + $toReplace = ["_", "%20"]; |
|
| 190 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
| 191 | 191 | |
| 192 | 192 | return $commonsLink === $compareString; |
| 193 | 193 | } |
@@ -196,9 +196,9 @@ discard block |
||
| 196 | 196 | * Checks whether the value of the statement already includes the namespace. |
| 197 | 197 | * This special case should be reported as “malformed title” instead of “title does not exist”. |
| 198 | 198 | */ |
| 199 | - private function valueIncludesNamespace( string $value, string $namespace ): bool { |
|
| 199 | + private function valueIncludesNamespace(string $value, string $namespace): bool { |
|
| 200 | 200 | return $namespace !== '' && |
| 201 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
| 201 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | } |