@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | Reference $reference, |
29 | 29 | Snak $snak |
30 | 30 | ) { |
31 | - parent::__construct( $entity, $snak ); |
|
31 | + parent::__construct($entity, $snak); |
|
32 | 32 | $this->statement = $statement; |
33 | 33 | $this->reference = $reference; |
34 | 34 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | return self::TYPE_REFERENCE; |
38 | 38 | } |
39 | 39 | |
40 | - protected function &getMainArray( array &$container ) { |
|
40 | + protected function &getMainArray(array &$container) { |
|
41 | 41 | $statementArray = &$this->getStatementArray( |
42 | 42 | $container, |
43 | 43 | $this->entity->getId()->getSerialization(), |
@@ -45,38 +45,38 @@ discard block |
||
45 | 45 | $this->statement->getGuid() |
46 | 46 | ); |
47 | 47 | |
48 | - if ( !array_key_exists( 'references', $statementArray ) ) { |
|
48 | + if (!array_key_exists('references', $statementArray)) { |
|
49 | 49 | $statementArray['references'] = []; |
50 | 50 | } |
51 | 51 | $referencesArray = &$statementArray['references']; |
52 | 52 | |
53 | - foreach ( $referencesArray as &$potentialReferenceArray ) { |
|
54 | - if ( $potentialReferenceArray['hash'] === $this->reference->getHash() ) { |
|
53 | + foreach ($referencesArray as &$potentialReferenceArray) { |
|
54 | + if ($potentialReferenceArray['hash'] === $this->reference->getHash()) { |
|
55 | 55 | $referenceArray = &$potentialReferenceArray; |
56 | 56 | break; |
57 | 57 | } |
58 | 58 | } |
59 | - if ( !isset( $referenceArray ) ) { |
|
60 | - $referenceArray = [ 'hash' => $this->reference->getHash(), 'snaks' => [] ]; |
|
59 | + if (!isset($referenceArray)) { |
|
60 | + $referenceArray = ['hash' => $this->reference->getHash(), 'snaks' => []]; |
|
61 | 61 | $referencesArray[] = &$referenceArray; |
62 | 62 | } |
63 | 63 | |
64 | 64 | $snaksArray = &$referenceArray['snaks']; |
65 | 65 | |
66 | 66 | $propertyId = $this->getSnak()->getPropertyId()->getSerialization(); |
67 | - if ( !array_key_exists( $propertyId, $snaksArray ) ) { |
|
67 | + if (!array_key_exists($propertyId, $snaksArray)) { |
|
68 | 68 | $snaksArray[$propertyId] = []; |
69 | 69 | } |
70 | 70 | $propertyArray = &$snaksArray[$propertyId]; |
71 | 71 | |
72 | - foreach ( $propertyArray as &$potentialSnakArray ) { |
|
73 | - if ( $potentialSnakArray['hash'] === $this->getSnak()->getHash() ) { |
|
72 | + foreach ($propertyArray as &$potentialSnakArray) { |
|
73 | + if ($potentialSnakArray['hash'] === $this->getSnak()->getHash()) { |
|
74 | 74 | $snakArray = &$potentialSnakArray; |
75 | 75 | break; |
76 | 76 | } |
77 | 77 | } |
78 | - if ( !isset( $snakArray ) ) { |
|
79 | - $snakArray = [ 'hash' => $this->getSnak()->getHash() ]; |
|
78 | + if (!isset($snakArray)) { |
|
79 | + $snakArray = ['hash' => $this->getSnak()->getHash()]; |
|
80 | 80 | $propertyArray[] = &$snakArray; |
81 | 81 | } |
82 | 82 |
@@ -25,22 +25,22 @@ |
||
25 | 25 | */ |
26 | 26 | const NULL_PROPERTY_ID = 'P2147483647'; |
27 | 27 | |
28 | - public function __construct( Context $context ) { |
|
28 | + public function __construct(Context $context) { |
|
29 | 29 | $constraint = new Constraint( |
30 | 30 | 'null', |
31 | - new PropertyId( self::NULL_PROPERTY_ID ), |
|
31 | + new PropertyId(self::NULL_PROPERTY_ID), |
|
32 | 32 | 'none', |
33 | 33 | [] |
34 | 34 | ); |
35 | - parent::__construct( $context, $constraint ); |
|
35 | + parent::__construct($context, $constraint); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function getConstraint() { |
39 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
39 | + throw new DomainException('NullResult holds no constraint'); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function getConstraintId() { |
43 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
43 | + throw new DomainException('NullResult holds no constraint'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @throws ConstraintParameterException if the constraint parameters are invalid |
23 | 23 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
24 | 24 | */ |
25 | - public function checkConstraint( Context $context, Constraint $constraint ); |
|
25 | + public function checkConstraint(Context $context, Constraint $constraint); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Check if the constraint parameters of $constraint are valid. |
@@ -33,6 +33,6 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return ConstraintParameterException[] |
35 | 35 | */ |
36 | - public function checkConstraintParameters( Constraint $constraint ); |
|
36 | + public function checkConstraintParameters(Constraint $constraint); |
|
37 | 37 | |
38 | 38 | } |
@@ -52,46 +52,46 @@ |
||
52 | 52 | * |
53 | 53 | * @return CheckResult |
54 | 54 | */ |
55 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
56 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
57 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
55 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
56 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
57 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
58 | 58 | } |
59 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
60 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
59 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
60 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | $parameters = []; |
64 | 64 | $constraintParameters = $constraint->getConstraintParameters(); |
65 | 65 | |
66 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
67 | - $parameters['property'] = [ $propertyId ]; |
|
66 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
67 | + $parameters['property'] = [$propertyId]; |
|
68 | 68 | |
69 | - $message = wfMessage( "wbqc-violation-message-mandatory-qualifier" ) |
|
69 | + $message = wfMessage("wbqc-violation-message-mandatory-qualifier") |
|
70 | 70 | ->rawParams( |
71 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
72 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::QUALIFIER_PREDICATE ) |
|
71 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
72 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::QUALIFIER_PREDICATE) |
|
73 | 73 | ) |
74 | 74 | ->escaped(); |
75 | 75 | $status = CheckResult::STATUS_VIOLATION; |
76 | 76 | |
77 | 77 | /** @var Snak $qualifier */ |
78 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
79 | - if ( $propertyId->equals( $qualifier->getPropertyId() ) ) { |
|
78 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
79 | + if ($propertyId->equals($qualifier->getPropertyId())) { |
|
80 | 80 | $message = ''; |
81 | 81 | $status = CheckResult::STATUS_COMPLIANCE; |
82 | 82 | break; |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
86 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
87 | 87 | } |
88 | 88 | |
89 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
89 | + public function checkConstraintParameters(Constraint $constraint) { |
|
90 | 90 | $constraintParameters = $constraint->getConstraintParameters(); |
91 | 91 | $exceptions = []; |
92 | 92 | try { |
93 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
94 | - } catch ( ConstraintParameterException $e ) { |
|
93 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
94 | + } catch (ConstraintParameterException $e) { |
|
95 | 95 | $exceptions[] = $e; |
96 | 96 | } |
97 | 97 | return $exceptions; |
@@ -70,22 +70,22 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return CheckResult |
72 | 72 | */ |
73 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
74 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
75 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
73 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
74 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
75 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
76 | 76 | } |
77 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
77 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
78 | 78 | // TODO T175562 |
79 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
79 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $parameters = []; |
83 | 83 | $constraintParameters = $constraint->getConstraintParameters(); |
84 | 84 | |
85 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
86 | - $parameters['property'] = [ $propertyId ]; |
|
85 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
86 | + $parameters['property'] = [$propertyId]; |
|
87 | 87 | |
88 | - $items = $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
88 | + $items = $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
89 | 89 | $parameters['items'] = $items; |
90 | 90 | |
91 | 91 | /* |
@@ -93,16 +93,16 @@ discard block |
||
93 | 93 | * a) a property only |
94 | 94 | * b) a property and a number of items (each combination of property and item forming an individual claim) |
95 | 95 | */ |
96 | - if ( $items === [] ) { |
|
96 | + if ($items === []) { |
|
97 | 97 | $offendingStatement = $this->connectionCheckerHelper->findStatementWithProperty( |
98 | 98 | $context->getEntity()->getStatements(), |
99 | 99 | $propertyId |
100 | 100 | ); |
101 | - if ( $offendingStatement !== null ) { |
|
102 | - $message = wfMessage( "wbqc-violation-message-conflicts-with-property" ) |
|
101 | + if ($offendingStatement !== null) { |
|
102 | + $message = wfMessage("wbqc-violation-message-conflicts-with-property") |
|
103 | 103 | ->rawParams( |
104 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
105 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::PREDICATE ) |
|
104 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
105 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::PREDICATE) |
|
106 | 106 | ) |
107 | 107 | ->escaped(); |
108 | 108 | $status = CheckResult::STATUS_VIOLATION; |
@@ -116,13 +116,13 @@ discard block |
||
116 | 116 | $propertyId, |
117 | 117 | $items |
118 | 118 | ); |
119 | - if ( $offendingStatement !== null ) { |
|
120 | - $offendingValue = ItemIdSnakValue::fromSnak( $offendingStatement->getMainSnak() ); |
|
121 | - $message = wfMessage( "wbqc-violation-message-conflicts-with-claim" ) |
|
119 | + if ($offendingStatement !== null) { |
|
120 | + $offendingValue = ItemIdSnakValue::fromSnak($offendingStatement->getMainSnak()); |
|
121 | + $message = wfMessage("wbqc-violation-message-conflicts-with-claim") |
|
122 | 122 | ->rawParams( |
123 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
124 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::PREDICATE ), |
|
125 | - $this->constraintParameterRenderer->formatItemIdSnakValue( $offendingValue, Role::OBJECT ) |
|
123 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
124 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::PREDICATE), |
|
125 | + $this->constraintParameterRenderer->formatItemIdSnakValue($offendingValue, Role::OBJECT) |
|
126 | 126 | ) |
127 | 127 | ->escaped(); |
128 | 128 | $status = CheckResult::STATUS_VIOLATION; |
@@ -132,20 +132,20 @@ discard block |
||
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
135 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
135 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
136 | 136 | } |
137 | 137 | |
138 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
138 | + public function checkConstraintParameters(Constraint $constraint) { |
|
139 | 139 | $constraintParameters = $constraint->getConstraintParameters(); |
140 | 140 | $exceptions = []; |
141 | 141 | try { |
142 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
143 | - } catch ( ConstraintParameterException $e ) { |
|
142 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
143 | + } catch (ConstraintParameterException $e) { |
|
144 | 144 | $exceptions[] = $e; |
145 | 145 | } |
146 | 146 | try { |
147 | - $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
148 | - } catch ( ConstraintParameterException $e ) { |
|
147 | + $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
148 | + } catch (ConstraintParameterException $e) { |
|
149 | 149 | $exceptions[] = $e; |
150 | 150 | } |
151 | 151 | return $exceptions; |
@@ -35,33 +35,33 @@ |
||
35 | 35 | * |
36 | 36 | * @return CheckResult |
37 | 37 | */ |
38 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
39 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
40 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
38 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
39 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
40 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
41 | 41 | } |
42 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
42 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
43 | 43 | // TODO T175566 |
44 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
44 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | $propertyId = $context->getSnak()->getPropertyId(); |
48 | 48 | |
49 | 49 | $parameters = []; |
50 | 50 | |
51 | - $propertyCountArray = $this->valueCountCheckerHelper->getPropertyCount( $context->getEntity()->getStatements() ); |
|
51 | + $propertyCountArray = $this->valueCountCheckerHelper->getPropertyCount($context->getEntity()->getStatements()); |
|
52 | 52 | |
53 | - if ( $propertyCountArray[$propertyId->getSerialization()] > 1 ) { |
|
54 | - $message = wfMessage( "wbqc-violation-message-single-value" )->escaped(); |
|
53 | + if ($propertyCountArray[$propertyId->getSerialization()] > 1) { |
|
54 | + $message = wfMessage("wbqc-violation-message-single-value")->escaped(); |
|
55 | 55 | $status = CheckResult::STATUS_VIOLATION; |
56 | 56 | } else { |
57 | 57 | $message = ''; |
58 | 58 | $status = CheckResult::STATUS_COMPLIANCE; |
59 | 59 | } |
60 | 60 | |
61 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
61 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
62 | 62 | } |
63 | 63 | |
64 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
64 | + public function checkConstraintParameters(Constraint $constraint) { |
|
65 | 65 | // no parameters |
66 | 66 | return []; |
67 | 67 | } |
@@ -60,22 +60,22 @@ discard block |
||
60 | 60 | * @return array first element is the namespace number (default namespace for TitleParser), |
61 | 61 | * second element is a string to prepend to the title before giving it to the TitleParser |
62 | 62 | */ |
63 | - private function getCommonsNamespace( $namespace ) { |
|
63 | + private function getCommonsNamespace($namespace) { |
|
64 | 64 | // for namespace numbers see mediawiki-config repo, wmf-config/InitialiseSettings.php, |
65 | 65 | // 'wgExtraNamespaces' key, 'commonswiki' subkey |
66 | - switch ( $namespace ) { |
|
66 | + switch ($namespace) { |
|
67 | 67 | case '': |
68 | - return [ NS_MAIN, '' ]; |
|
68 | + return [NS_MAIN, '']; |
|
69 | 69 | case 'Creator': |
70 | - return [ 100, '' ]; |
|
70 | + return [100, '']; |
|
71 | 71 | case 'TimedText': |
72 | - return [ 102, '' ]; |
|
72 | + return [102, '']; |
|
73 | 73 | case 'Sequence': |
74 | - return [ 104, '' ]; |
|
74 | + return [104, '']; |
|
75 | 75 | case 'Institution': |
76 | - return [ 106, '' ]; |
|
76 | + return [106, '']; |
|
77 | 77 | default: |
78 | - return [ NS_MAIN, $namespace . ':' ]; |
|
78 | + return [NS_MAIN, $namespace.':']; |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
@@ -87,17 +87,17 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @return CheckResult |
89 | 89 | */ |
90 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
90 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
91 | 91 | $parameters = []; |
92 | 92 | $constraintParameters = $constraint->getConstraintParameters(); |
93 | - $namespace = $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
94 | - $parameters['namespace'] = [ $namespace ]; |
|
93 | + $namespace = $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
94 | + $parameters['namespace'] = [$namespace]; |
|
95 | 95 | |
96 | 96 | $snak = $context->getSnak(); |
97 | 97 | |
98 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
98 | + if (!$snak instanceof PropertyValueSnak) { |
|
99 | 99 | // nothing to check |
100 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
100 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $dataValue = $snak->getDataValue(); |
@@ -107,49 +107,49 @@ discard block |
||
107 | 107 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
108 | 108 | * parameter $namespace can be null, works for commons galleries |
109 | 109 | */ |
110 | - if ( $dataValue->getType() !== 'string' ) { |
|
111 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
110 | + if ($dataValue->getType() !== 'string') { |
|
111 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
112 | 112 | ->rawParams( |
113 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
114 | - wfMessage( 'datatypes-type-string' )->escaped() |
|
113 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
114 | + wfMessage('datatypes-type-string')->escaped() |
|
115 | 115 | ) |
116 | 116 | ->escaped(); |
117 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
117 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | $commonsLink = $dataValue->getValue(); |
121 | 121 | |
122 | 122 | try { |
123 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
124 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
123 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
124 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
125 | 125 | } |
126 | - list ( $defaultNamespace, $prefix ) = $this->getCommonsNamespace( $namespace ); |
|
127 | - $title = $this->titleParser->parseTitle( $prefix . $commonsLink, $defaultNamespace ); |
|
128 | - if ( $this->pageExists( $title ) ) { |
|
126 | + list ($defaultNamespace, $prefix) = $this->getCommonsNamespace($namespace); |
|
127 | + $title = $this->titleParser->parseTitle($prefix.$commonsLink, $defaultNamespace); |
|
128 | + if ($this->pageExists($title)) { |
|
129 | 129 | $message = ''; |
130 | 130 | $status = CheckResult::STATUS_COMPLIANCE; |
131 | 131 | } else { |
132 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
133 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
132 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
133 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
134 | 134 | } else { |
135 | - $message = wfMessage( "wbqc-violation-message-commons-link-no-existent" )->escaped(); |
|
135 | + $message = wfMessage("wbqc-violation-message-commons-link-no-existent")->escaped(); |
|
136 | 136 | $status = CheckResult::STATUS_VIOLATION; |
137 | 137 | } |
138 | 138 | } |
139 | - } catch ( MalformedTitleException $e ) { |
|
140 | - $message = wfMessage( "wbqc-violation-message-commons-link-not-well-formed" )->escaped(); |
|
139 | + } catch (MalformedTitleException $e) { |
|
140 | + $message = wfMessage("wbqc-violation-message-commons-link-not-well-formed")->escaped(); |
|
141 | 141 | $status = CheckResult::STATUS_VIOLATION; |
142 | 142 | } |
143 | 143 | |
144 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
144 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
145 | 145 | } |
146 | 146 | |
147 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
147 | + public function checkConstraintParameters(Constraint $constraint) { |
|
148 | 148 | $constraintParameters = $constraint->getConstraintParameters(); |
149 | 149 | $exceptions = []; |
150 | 150 | try { |
151 | - $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
152 | - } catch ( ConstraintParameterException $e ) { |
|
151 | + $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
152 | + } catch (ConstraintParameterException $e) { |
|
153 | 153 | $exceptions[] = $e; |
154 | 154 | } |
155 | 155 | return $exceptions; |
@@ -160,19 +160,19 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @return bool |
162 | 162 | */ |
163 | - private function pageExists( TitleValue $title ) { |
|
163 | + private function pageExists(TitleValue $title) { |
|
164 | 164 | $commonsWikiId = 'commonswiki'; |
165 | - if ( defined( 'MW_PHPUNIT_TEST' ) ) { |
|
165 | + if (defined('MW_PHPUNIT_TEST')) { |
|
166 | 166 | $commonsWikiId = false; |
167 | 167 | } |
168 | 168 | |
169 | - $dbLoadBalancer = wfGetLB( $commonsWikiId ); |
|
169 | + $dbLoadBalancer = wfGetLB($commonsWikiId); |
|
170 | 170 | $dbConnection = $dbLoadBalancer->getConnection( |
171 | 171 | DB_REPLICA, false, $commonsWikiId ); |
172 | - $row = $dbConnection->selectRow( 'page', '*', [ |
|
172 | + $row = $dbConnection->selectRow('page', '*', [ |
|
173 | 173 | 'page_title' => $title->getDBKey(), |
174 | 174 | 'page_namespace' => $title->getNamespace() |
175 | - ] ); |
|
175 | + ]); |
|
176 | 176 | |
177 | 177 | return $row !== false; |
178 | 178 | } |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return bool |
184 | 184 | */ |
185 | - private function commonsLinkIsWellFormed( $commonsLink ) { |
|
186 | - $toReplace = [ "_", "%20" ]; |
|
187 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
185 | + private function commonsLinkIsWellFormed($commonsLink) { |
|
186 | + $toReplace = ["_", "%20"]; |
|
187 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
188 | 188 | return $commonsLink === $compareString; |
189 | 189 | } |
190 | 190 | |
@@ -197,9 +197,9 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @return bool |
199 | 199 | */ |
200 | - private function valueIncludesNamespace( $value, $namespace ) { |
|
200 | + private function valueIncludesNamespace($value, $namespace) { |
|
201 | 201 | return $namespace !== '' && |
202 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
202 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | } |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return CheckResult |
72 | 72 | */ |
73 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
74 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
75 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
73 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
74 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
75 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | $parameters = []; |
@@ -80,42 +80,42 @@ discard block |
||
80 | 80 | |
81 | 81 | $snak = $context->getSnak(); |
82 | 82 | |
83 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
83 | + if (!$snak instanceof PropertyValueSnak) { |
|
84 | 84 | // nothing to check |
85 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
85 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | $dataValue = $snak->getDataValue(); |
89 | 89 | |
90 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
90 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
91 | 91 | $constraintParameters, |
92 | 92 | $constraint->getConstraintTypeItemId(), |
93 | 93 | $dataValue->getType() |
94 | 94 | ); |
95 | 95 | $parameterKey = $dataValue->getType() === 'quantity' ? 'quantity' : 'date'; |
96 | - if ( $min !== null ) { |
|
97 | - $parameters['minimum_' . $parameterKey] = [ $min ]; |
|
96 | + if ($min !== null) { |
|
97 | + $parameters['minimum_'.$parameterKey] = [$min]; |
|
98 | 98 | } |
99 | - if ( $max !== null ) { |
|
100 | - $parameters['maximum_' . $parameterKey] = [ $max ]; |
|
99 | + if ($max !== null) { |
|
100 | + $parameters['maximum_'.$parameterKey] = [$max]; |
|
101 | 101 | } |
102 | 102 | |
103 | - if ( $this->rangeCheckerHelper->getComparison( $min, $dataValue ) > 0 || |
|
104 | - $this->rangeCheckerHelper->getComparison( $dataValue, $max ) > 0 |
|
103 | + if ($this->rangeCheckerHelper->getComparison($min, $dataValue) > 0 || |
|
104 | + $this->rangeCheckerHelper->getComparison($dataValue, $max) > 0 |
|
105 | 105 | ) { |
106 | 106 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
107 | 107 | $type = $dataValue->getType(); |
108 | - $openness = $min !== null ? ( $max !== null ? 'closed' : 'rightopen' ) : 'leftopen'; |
|
109 | - $message = wfMessage( "wbqc-violation-message-range-$type-$openness" ); |
|
108 | + $openness = $min !== null ? ($max !== null ? 'closed' : 'rightopen') : 'leftopen'; |
|
109 | + $message = wfMessage("wbqc-violation-message-range-$type-$openness"); |
|
110 | 110 | $message->rawParams( |
111 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ), |
|
112 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::OBJECT ) |
|
111 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE), |
|
112 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::OBJECT) |
|
113 | 113 | ); |
114 | - if ( $min !== null ) { |
|
115 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $min, Role::OBJECT ) ); |
|
114 | + if ($min !== null) { |
|
115 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($min, Role::OBJECT)); |
|
116 | 116 | } |
117 | - if ( $max !== null ) { |
|
118 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $max, Role::OBJECT ) ); |
|
117 | + if ($max !== null) { |
|
118 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($max, Role::OBJECT)); |
|
119 | 119 | } |
120 | 120 | $message = $message->escaped(); |
121 | 121 | $status = CheckResult::STATUS_VIOLATION; |
@@ -124,22 +124,22 @@ discard block |
||
124 | 124 | $status = CheckResult::STATUS_COMPLIANCE; |
125 | 125 | } |
126 | 126 | |
127 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
127 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
128 | 128 | } |
129 | 129 | |
130 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
130 | + public function checkConstraintParameters(Constraint $constraint) { |
|
131 | 131 | $constraintParameters = $constraint->getConstraintParameters(); |
132 | 132 | $exceptions = []; |
133 | 133 | try { |
134 | 134 | // we don’t have a data value here, so get the type from the property instead |
135 | 135 | // (the distinction between data type and data value type is irrelevant for 'quantity' and 'time') |
136 | - $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty( $constraint->getPropertyId() ); |
|
136 | + $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty($constraint->getPropertyId()); |
|
137 | 137 | $this->constraintParameterParser->parseRangeParameter( |
138 | 138 | $constraintParameters, |
139 | 139 | $constraint->getConstraintTypeItemId(), |
140 | 140 | $type |
141 | 141 | ); |
142 | - } catch ( ConstraintParameterException $e ) { |
|
142 | + } catch (ConstraintParameterException $e) { |
|
143 | 143 | $exceptions[] = $e; |
144 | 144 | } |
145 | 145 | return $exceptions; |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | * @throws ConstraintParameterException |
68 | 68 | * @return array [ DataValue|null $min, DataValue|null $max, PropertyId $property, array $parameters ] |
69 | 69 | */ |
70 | - private function parseConstraintParameters( Constraint $constraint ) { |
|
71 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
70 | + private function parseConstraintParameters(Constraint $constraint) { |
|
71 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
72 | 72 | $constraint->getConstraintParameters(), |
73 | 73 | $constraint->getConstraintTypeItemId(), |
74 | 74 | 'quantity' |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | $constraint->getConstraintTypeItemId() |
79 | 79 | ); |
80 | 80 | |
81 | - if ( $min !== null ) { |
|
82 | - $parameters['minimum_quantity'] = [ $min ]; |
|
81 | + if ($min !== null) { |
|
82 | + $parameters['minimum_quantity'] = [$min]; |
|
83 | 83 | } |
84 | - if ( $max !== null ) { |
|
85 | - $parameters['maximum_quantity'] = [ $max ]; |
|
84 | + if ($max !== null) { |
|
85 | + $parameters['maximum_quantity'] = [$max]; |
|
86 | 86 | } |
87 | - $parameters['property'] = [ $property ]; |
|
87 | + $parameters['property'] = [$property]; |
|
88 | 88 | |
89 | - return [ $min, $max, $property, $parameters ]; |
|
89 | + return [$min, $max, $property, $parameters]; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @return bool |
98 | 98 | */ |
99 | - private function rangeInYears( $min, $max ) { |
|
100 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
99 | + private function rangeInYears($min, $max) { |
|
100 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
101 | 101 | |
102 | - if ( $min !== null && $min->getUnit() === $yearUnit ) { |
|
102 | + if ($min !== null && $min->getUnit() === $yearUnit) { |
|
103 | 103 | return true; |
104 | 104 | } |
105 | - if ( $max !== null && $max->getUnit() === $yearUnit ) { |
|
105 | + if ($max !== null && $max->getUnit() === $yearUnit) { |
|
106 | 106 | return true; |
107 | 107 | } |
108 | 108 | |
@@ -117,36 +117,36 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return CheckResult |
119 | 119 | */ |
120 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
121 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
122 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
120 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
121 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
122 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
123 | 123 | } |
124 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
124 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
125 | 125 | // TODO T175565 |
126 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
126 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | $parameters = []; |
130 | 130 | |
131 | 131 | $snak = $context->getSnak(); |
132 | 132 | |
133 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
133 | + if (!$snak instanceof PropertyValueSnak) { |
|
134 | 134 | // nothing to check |
135 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
135 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | $minuend = $snak->getDataValue(); |
139 | 139 | |
140 | 140 | /** @var PropertyId $property */ |
141 | - list ( $min, $max, $property, $parameters ) = $this->parseConstraintParameters( $constraint ); |
|
141 | + list ($min, $max, $property, $parameters) = $this->parseConstraintParameters($constraint); |
|
142 | 142 | |
143 | 143 | // checks only the first occurrence of the referenced property (this constraint implies a single value constraint on that property) |
144 | 144 | /** @var Statement $otherStatement */ |
145 | - foreach ( $context->getEntity()->getStatements() as $otherStatement ) { |
|
145 | + foreach ($context->getEntity()->getStatements() as $otherStatement) { |
|
146 | 146 | $otherMainSnak = $otherStatement->getMainSnak(); |
147 | 147 | |
148 | 148 | if ( |
149 | - !$property->equals( $otherStatement->getPropertyId() ) || |
|
149 | + !$property->equals($otherStatement->getPropertyId()) || |
|
150 | 150 | $otherStatement->getRank() === Statement::RANK_DEPRECATED || |
151 | 151 | !$otherMainSnak instanceof PropertyValueSnak |
152 | 152 | ) { |
@@ -154,28 +154,27 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | $subtrahend = $otherMainSnak->getDataValue(); |
157 | - if ( $subtrahend->getType() === $minuend->getType() ) { |
|
158 | - $diff = $this->rangeInYears( $min, $max ) ? |
|
159 | - $this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) : |
|
160 | - $this->rangeCheckerHelper->getDifference( $minuend, $subtrahend ); |
|
157 | + if ($subtrahend->getType() === $minuend->getType()) { |
|
158 | + $diff = $this->rangeInYears($min, $max) ? |
|
159 | + $this->rangeCheckerHelper->getDifferenceInYears($minuend, $subtrahend) : $this->rangeCheckerHelper->getDifference($minuend, $subtrahend); |
|
161 | 160 | |
162 | - if ( $this->rangeCheckerHelper->getComparison( $min, $diff ) > 0 || |
|
163 | - $this->rangeCheckerHelper->getComparison( $diff, $max ) > 0 |
|
161 | + if ($this->rangeCheckerHelper->getComparison($min, $diff) > 0 || |
|
162 | + $this->rangeCheckerHelper->getComparison($diff, $max) > 0 |
|
164 | 163 | ) { |
165 | 164 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
166 | - $openness = $min !== null ? ( $max !== null ? '' : '-rightopen' ) : '-leftopen'; |
|
167 | - $message = wfMessage( "wbqc-violation-message-diff-within-range$openness" ); |
|
165 | + $openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen'; |
|
166 | + $message = wfMessage("wbqc-violation-message-diff-within-range$openness"); |
|
168 | 167 | $message->rawParams( |
169 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ), |
|
170 | - $this->constraintParameterRenderer->formatDataValue( $minuend, Role::OBJECT ), |
|
171 | - $this->constraintParameterRenderer->formatEntityId( $otherStatement->getPropertyId(), Role::PREDICATE ), |
|
172 | - $this->constraintParameterRenderer->formatDataValue( $subtrahend, Role::OBJECT ) |
|
168 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE), |
|
169 | + $this->constraintParameterRenderer->formatDataValue($minuend, Role::OBJECT), |
|
170 | + $this->constraintParameterRenderer->formatEntityId($otherStatement->getPropertyId(), Role::PREDICATE), |
|
171 | + $this->constraintParameterRenderer->formatDataValue($subtrahend, Role::OBJECT) |
|
173 | 172 | ); |
174 | - if ( $min !== null ) { |
|
175 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $min, Role::OBJECT ) ); |
|
173 | + if ($min !== null) { |
|
174 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($min, Role::OBJECT)); |
|
176 | 175 | } |
177 | - if ( $max !== null ) { |
|
178 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $max, Role::OBJECT ) ); |
|
176 | + if ($max !== null) { |
|
177 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($max, Role::OBJECT)); |
|
179 | 178 | } |
180 | 179 | $message = $message->escaped(); |
181 | 180 | $status = CheckResult::STATUS_VIOLATION; |
@@ -184,19 +183,19 @@ discard block |
||
184 | 183 | $status = CheckResult::STATUS_COMPLIANCE; |
185 | 184 | } |
186 | 185 | } else { |
187 | - $message = wfMessage( "wbqc-violation-message-diff-within-range-must-have-equal-types" )->escaped(); |
|
186 | + $message = wfMessage("wbqc-violation-message-diff-within-range-must-have-equal-types")->escaped(); |
|
188 | 187 | $status = CheckResult::STATUS_VIOLATION; |
189 | 188 | } |
190 | 189 | |
191 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
190 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
192 | 191 | } |
193 | 192 | |
194 | - $message = wfMessage( "wbqc-violation-message-diff-within-range-property-must-exist" )->escaped(); |
|
193 | + $message = wfMessage("wbqc-violation-message-diff-within-range-property-must-exist")->escaped(); |
|
195 | 194 | $status = CheckResult::STATUS_VIOLATION; |
196 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
195 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
197 | 196 | } |
198 | 197 | |
199 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
198 | + public function checkConstraintParameters(Constraint $constraint) { |
|
200 | 199 | $constraintParameters = $constraint->getConstraintParameters(); |
201 | 200 | $exceptions = []; |
202 | 201 | try { |
@@ -205,12 +204,12 @@ discard block |
||
205 | 204 | $constraint->getConstraintTypeItemId(), |
206 | 205 | 'quantity' |
207 | 206 | ); |
208 | - } catch ( ConstraintParameterException $e ) { |
|
207 | + } catch (ConstraintParameterException $e) { |
|
209 | 208 | $exceptions[] = $e; |
210 | 209 | } |
211 | 210 | try { |
212 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
213 | - } catch ( ConstraintParameterException $e ) { |
|
211 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
212 | + } catch (ConstraintParameterException $e) { |
|
214 | 213 | $exceptions[] = $e; |
215 | 214 | } |
216 | 215 | return $exceptions; |