@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * @param int $maxAge The maximum age of the cached value (in seconds). |
30 | 30 | * @return self Indication that a value is possibly outdated by up to this many seconds. |
31 | 31 | */ |
32 | - public static function ofMaximumAgeInSeconds( $maxAge ) { |
|
33 | - Assert::parameterType( 'integer', $maxAge, '$maxAge' ); |
|
34 | - Assert::parameter( $maxAge > 0, '$maxAge', '$maxage > 0' ); |
|
32 | + public static function ofMaximumAgeInSeconds($maxAge) { |
|
33 | + Assert::parameterType('integer', $maxAge, '$maxAge'); |
|
34 | + Assert::parameter($maxAge > 0, '$maxAge', '$maxage > 0'); |
|
35 | 35 | $ret = new self; |
36 | 36 | $ret->maxAge = $maxAge; |
37 | 37 | return $ret; |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * @param array|null $array As returned by toArray. |
43 | 43 | * @return self |
44 | 44 | */ |
45 | - public static function ofArray( array $array = null ) { |
|
45 | + public static function ofArray(array $array = null) { |
|
46 | 46 | $ret = new self; |
47 | - if ( $array !== null ) { |
|
47 | + if ($array !== null) { |
|
48 | 48 | $ret->maxAge = $array['maximumAgeInSeconds']; |
49 | 49 | } |
50 | 50 | return $ret; |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | * @param self[] $metadatas |
55 | 55 | * @return self |
56 | 56 | */ |
57 | - public static function merge( array $metadatas ) { |
|
58 | - Assert::parameterElementType( self::class, $metadatas, '$metadatas' ); |
|
57 | + public static function merge(array $metadatas) { |
|
58 | + Assert::parameterElementType(self::class, $metadatas, '$metadatas'); |
|
59 | 59 | $ret = new self; |
60 | - foreach ( $metadatas as $metadata ) { |
|
61 | - $ret->maxAge = max( $ret->maxAge, $metadata->maxAge ); |
|
60 | + foreach ($metadatas as $metadata) { |
|
61 | + $ret->maxAge = max($ret->maxAge, $metadata->maxAge); |
|
62 | 62 | } |
63 | 63 | return $ret; |
64 | 64 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * For a fresh value, returns 0. |
77 | 77 | */ |
78 | 78 | public function getMaximumAgeInSeconds() { |
79 | - if ( is_int( $this->maxAge ) ) { |
|
79 | + if (is_int($this->maxAge)) { |
|
80 | 80 | return $this->maxAge; |
81 | 81 | } else { |
82 | 82 | return 0; |
@@ -91,8 +91,7 @@ discard block |
||
91 | 91 | return $this->isCached() ? |
92 | 92 | [ |
93 | 93 | 'maximumAgeInSeconds' => $this->maxAge, |
94 | - ] : |
|
95 | - null; |
|
94 | + ] : null; |
|
96 | 95 | } |
97 | 96 | |
98 | 97 | } |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * @throws ConstraintParameterException |
69 | 69 | * @return CheckResult |
70 | 70 | */ |
71 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
72 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
73 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
71 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
72 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
73 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | $parameters = []; |
@@ -78,42 +78,42 @@ discard block |
||
78 | 78 | |
79 | 79 | $snak = $context->getSnak(); |
80 | 80 | |
81 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
81 | + if (!$snak instanceof PropertyValueSnak) { |
|
82 | 82 | // nothing to check |
83 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
83 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | $dataValue = $snak->getDataValue(); |
87 | 87 | |
88 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
88 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
89 | 89 | $constraintParameters, |
90 | 90 | $constraint->getConstraintTypeItemId(), |
91 | 91 | $dataValue->getType() |
92 | 92 | ); |
93 | 93 | $parameterKey = $dataValue->getType() === 'quantity' ? 'quantity' : 'date'; |
94 | - if ( $min !== null ) { |
|
95 | - $parameters['minimum_' . $parameterKey] = [ $min ]; |
|
94 | + if ($min !== null) { |
|
95 | + $parameters['minimum_'.$parameterKey] = [$min]; |
|
96 | 96 | } |
97 | - if ( $max !== null ) { |
|
98 | - $parameters['maximum_' . $parameterKey] = [ $max ]; |
|
97 | + if ($max !== null) { |
|
98 | + $parameters['maximum_'.$parameterKey] = [$max]; |
|
99 | 99 | } |
100 | 100 | |
101 | - if ( $this->rangeCheckerHelper->getComparison( $min, $dataValue ) > 0 || |
|
102 | - $this->rangeCheckerHelper->getComparison( $dataValue, $max ) > 0 |
|
101 | + if ($this->rangeCheckerHelper->getComparison($min, $dataValue) > 0 || |
|
102 | + $this->rangeCheckerHelper->getComparison($dataValue, $max) > 0 |
|
103 | 103 | ) { |
104 | 104 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
105 | 105 | $type = $dataValue->getType(); |
106 | - $openness = $min !== null ? ( $max !== null ? 'closed' : 'rightopen' ) : 'leftopen'; |
|
107 | - $message = wfMessage( "wbqc-violation-message-range-$type-$openness" ); |
|
106 | + $openness = $min !== null ? ($max !== null ? 'closed' : 'rightopen') : 'leftopen'; |
|
107 | + $message = wfMessage("wbqc-violation-message-range-$type-$openness"); |
|
108 | 108 | $message->rawParams( |
109 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ), |
|
110 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::OBJECT ) |
|
109 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE), |
|
110 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::OBJECT) |
|
111 | 111 | ); |
112 | - if ( $min !== null ) { |
|
113 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $min, Role::OBJECT ) ); |
|
112 | + if ($min !== null) { |
|
113 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($min, Role::OBJECT)); |
|
114 | 114 | } |
115 | - if ( $max !== null ) { |
|
116 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $max, Role::OBJECT ) ); |
|
115 | + if ($max !== null) { |
|
116 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($max, Role::OBJECT)); |
|
117 | 117 | } |
118 | 118 | $message = $message->escaped(); |
119 | 119 | $status = CheckResult::STATUS_VIOLATION; |
@@ -122,22 +122,22 @@ discard block |
||
122 | 122 | $status = CheckResult::STATUS_COMPLIANCE; |
123 | 123 | } |
124 | 124 | |
125 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
125 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
126 | 126 | } |
127 | 127 | |
128 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
128 | + public function checkConstraintParameters(Constraint $constraint) { |
|
129 | 129 | $constraintParameters = $constraint->getConstraintParameters(); |
130 | 130 | $exceptions = []; |
131 | 131 | try { |
132 | 132 | // we don’t have a data value here, so get the type from the property instead |
133 | 133 | // (the distinction between data type and data value type is irrelevant for 'quantity' and 'time') |
134 | - $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty( $constraint->getPropertyId() ); |
|
134 | + $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty($constraint->getPropertyId()); |
|
135 | 135 | $this->constraintParameterParser->parseRangeParameter( |
136 | 136 | $constraintParameters, |
137 | 137 | $constraint->getConstraintTypeItemId(), |
138 | 138 | $type |
139 | 139 | ); |
140 | - } catch ( ConstraintParameterException $e ) { |
|
140 | + } catch (ConstraintParameterException $e) { |
|
141 | 141 | $exceptions[] = $e; |
142 | 142 | } |
143 | 143 | return $exceptions; |
@@ -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 | |
@@ -88,17 +88,17 @@ discard block |
||
88 | 88 | * @throws ConstraintParameterException |
89 | 89 | * @return CheckResult |
90 | 90 | */ |
91 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
91 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
92 | 92 | $parameters = []; |
93 | 93 | $constraintParameters = $constraint->getConstraintParameters(); |
94 | - $namespace = $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
95 | - $parameters['namespace'] = [ $namespace ]; |
|
94 | + $namespace = $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
95 | + $parameters['namespace'] = [$namespace]; |
|
96 | 96 | |
97 | 97 | $snak = $context->getSnak(); |
98 | 98 | |
99 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
99 | + if (!$snak instanceof PropertyValueSnak) { |
|
100 | 100 | // nothing to check |
101 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
101 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $dataValue = $snak->getDataValue(); |
@@ -108,49 +108,49 @@ discard block |
||
108 | 108 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
109 | 109 | * parameter $namespace can be null, works for commons galleries |
110 | 110 | */ |
111 | - if ( $dataValue->getType() !== 'string' ) { |
|
112 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
111 | + if ($dataValue->getType() !== 'string') { |
|
112 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
113 | 113 | ->rawParams( |
114 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
115 | - wfMessage( 'datatypes-type-string' )->escaped() |
|
114 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
115 | + wfMessage('datatypes-type-string')->escaped() |
|
116 | 116 | ) |
117 | 117 | ->escaped(); |
118 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
118 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | $commonsLink = $dataValue->getValue(); |
122 | 122 | |
123 | 123 | try { |
124 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
125 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
124 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
125 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
126 | 126 | } |
127 | - list ( $defaultNamespace, $prefix ) = $this->getCommonsNamespace( $namespace ); |
|
128 | - $title = $this->titleParser->parseTitle( $prefix . $commonsLink, $defaultNamespace ); |
|
129 | - if ( $this->pageExists( $title ) ) { |
|
127 | + list ($defaultNamespace, $prefix) = $this->getCommonsNamespace($namespace); |
|
128 | + $title = $this->titleParser->parseTitle($prefix.$commonsLink, $defaultNamespace); |
|
129 | + if ($this->pageExists($title)) { |
|
130 | 130 | $message = ''; |
131 | 131 | $status = CheckResult::STATUS_COMPLIANCE; |
132 | 132 | } else { |
133 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
134 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
133 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
134 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
135 | 135 | } else { |
136 | - $message = wfMessage( "wbqc-violation-message-commons-link-no-existent" )->escaped(); |
|
136 | + $message = wfMessage("wbqc-violation-message-commons-link-no-existent")->escaped(); |
|
137 | 137 | $status = CheckResult::STATUS_VIOLATION; |
138 | 138 | } |
139 | 139 | } |
140 | - } catch ( MalformedTitleException $e ) { |
|
141 | - $message = wfMessage( "wbqc-violation-message-commons-link-not-well-formed" )->escaped(); |
|
140 | + } catch (MalformedTitleException $e) { |
|
141 | + $message = wfMessage("wbqc-violation-message-commons-link-not-well-formed")->escaped(); |
|
142 | 142 | $status = CheckResult::STATUS_VIOLATION; |
143 | 143 | } |
144 | 144 | |
145 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
145 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
146 | 146 | } |
147 | 147 | |
148 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
148 | + public function checkConstraintParameters(Constraint $constraint) { |
|
149 | 149 | $constraintParameters = $constraint->getConstraintParameters(); |
150 | 150 | $exceptions = []; |
151 | 151 | try { |
152 | - $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
153 | - } catch ( ConstraintParameterException $e ) { |
|
152 | + $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
153 | + } catch (ConstraintParameterException $e) { |
|
154 | 154 | $exceptions[] = $e; |
155 | 155 | } |
156 | 156 | return $exceptions; |
@@ -161,19 +161,19 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @return bool |
163 | 163 | */ |
164 | - private function pageExists( TitleValue $title ) { |
|
164 | + private function pageExists(TitleValue $title) { |
|
165 | 165 | $commonsWikiId = 'commonswiki'; |
166 | - if ( defined( 'MW_PHPUNIT_TEST' ) ) { |
|
166 | + if (defined('MW_PHPUNIT_TEST')) { |
|
167 | 167 | $commonsWikiId = false; |
168 | 168 | } |
169 | 169 | |
170 | - $dbLoadBalancer = wfGetLB( $commonsWikiId ); |
|
170 | + $dbLoadBalancer = wfGetLB($commonsWikiId); |
|
171 | 171 | $dbConnection = $dbLoadBalancer->getConnection( |
172 | 172 | DB_REPLICA, false, $commonsWikiId ); |
173 | - $row = $dbConnection->selectRow( 'page', '*', [ |
|
173 | + $row = $dbConnection->selectRow('page', '*', [ |
|
174 | 174 | 'page_title' => $title->getDBkey(), |
175 | 175 | 'page_namespace' => $title->getNamespace() |
176 | - ] ); |
|
176 | + ]); |
|
177 | 177 | |
178 | 178 | return $row !== false; |
179 | 179 | } |
@@ -183,9 +183,9 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return bool |
185 | 185 | */ |
186 | - private function commonsLinkIsWellFormed( $commonsLink ) { |
|
187 | - $toReplace = [ "_", "%20" ]; |
|
188 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
186 | + private function commonsLinkIsWellFormed($commonsLink) { |
|
187 | + $toReplace = ["_", "%20"]; |
|
188 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
189 | 189 | return $commonsLink === $compareString; |
190 | 190 | } |
191 | 191 | |
@@ -198,9 +198,9 @@ discard block |
||
198 | 198 | * |
199 | 199 | * @return bool |
200 | 200 | */ |
201 | - private function valueIncludesNamespace( $value, $namespace ) { |
|
201 | + private function valueIncludesNamespace($value, $namespace) { |
|
202 | 202 | return $namespace !== '' && |
203 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
203 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | } |
@@ -49,43 +49,43 @@ |
||
49 | 49 | * @throws ConstraintParameterException |
50 | 50 | * @return CheckResult |
51 | 51 | */ |
52 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
53 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
54 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
52 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
53 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
54 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | $parameters = []; |
58 | 58 | $constraintParameters = $constraint->getConstraintParameters(); |
59 | 59 | |
60 | - $items = $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), true ); |
|
60 | + $items = $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), true); |
|
61 | 61 | $parameters['item'] = $items; |
62 | 62 | |
63 | 63 | $snak = $context->getSnak(); |
64 | 64 | |
65 | - $message = wfMessage( 'wbqc-violation-message-one-of' ); |
|
66 | - $message->rawParams( $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) ); |
|
67 | - $message->numParams( count( $items ) ); |
|
68 | - $message->rawParams( $this->constraintParameterRenderer->formatItemIdSnakValueList( $items, Role::OBJECT ) ); |
|
65 | + $message = wfMessage('wbqc-violation-message-one-of'); |
|
66 | + $message->rawParams($this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE)); |
|
67 | + $message->numParams(count($items)); |
|
68 | + $message->rawParams($this->constraintParameterRenderer->formatItemIdSnakValueList($items, Role::OBJECT)); |
|
69 | 69 | $message = $message->escaped(); |
70 | 70 | $status = CheckResult::STATUS_VIOLATION; |
71 | 71 | |
72 | - foreach ( $items as $item ) { |
|
73 | - if ( $item->matchesSnak( $snak ) ) { |
|
72 | + foreach ($items as $item) { |
|
73 | + if ($item->matchesSnak($snak)) { |
|
74 | 74 | $message = ''; |
75 | 75 | $status = CheckResult::STATUS_COMPLIANCE; |
76 | 76 | break; |
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
80 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
81 | 81 | } |
82 | 82 | |
83 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
83 | + public function checkConstraintParameters(Constraint $constraint) { |
|
84 | 84 | $constraintParameters = $constraint->getConstraintParameters(); |
85 | 85 | $exceptions = []; |
86 | 86 | try { |
87 | - $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), true ); |
|
88 | - } catch ( ConstraintParameterException $e ) { |
|
87 | + $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), true); |
|
88 | + } catch (ConstraintParameterException $e) { |
|
89 | 89 | $exceptions[] = $e; |
90 | 90 | } |
91 | 91 | return $exceptions; |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | * @throws ConstraintParameterException |
72 | 72 | * @return CheckResult |
73 | 73 | */ |
74 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
75 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
76 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
74 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
75 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
76 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | $parameters = []; |
80 | 80 | $constraintParameters = $constraint->getConstraintParameters(); |
81 | 81 | |
82 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
83 | - $parameters['property'] = [ $propertyId ]; |
|
82 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
83 | + $parameters['property'] = [$propertyId]; |
|
84 | 84 | |
85 | - $items = $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
85 | + $items = $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
86 | 86 | $parameters['items'] = $items; |
87 | 87 | |
88 | 88 | $snak = $context->getSnak(); |
89 | 89 | |
90 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
90 | + if (!$snak instanceof PropertyValueSnak) { |
|
91 | 91 | // nothing to check |
92 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
92 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | $dataValue = $snak->getDataValue(); |
@@ -98,22 +98,22 @@ discard block |
||
98 | 98 | * error handling: |
99 | 99 | * type of $dataValue for properties with 'Target required claim' constraint has to be 'wikibase-entityid' |
100 | 100 | */ |
101 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
102 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
101 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
102 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
103 | 103 | ->rawParams( |
104 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
104 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
105 | 105 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
106 | 106 | ) |
107 | 107 | ->escaped(); |
108 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
108 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
109 | 109 | } |
110 | 110 | /** @var EntityIdValue $dataValue */ |
111 | 111 | |
112 | 112 | $targetEntityId = $dataValue->getEntityId(); |
113 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
114 | - if ( $targetEntity === null ) { |
|
115 | - $message = wfMessage( "wbqc-violation-message-target-entity-must-exist" )->escaped(); |
|
116 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
113 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
114 | + if ($targetEntity === null) { |
|
115 | + $message = wfMessage("wbqc-violation-message-target-entity-must-exist")->escaped(); |
|
116 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /* |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * a) a property only |
122 | 122 | * b) a property and a number of items (each combination forming an individual claim) |
123 | 123 | */ |
124 | - if ( $items === [] ) { |
|
124 | + if ($items === []) { |
|
125 | 125 | $requiredStatement = $this->connectionCheckerHelper->findStatementWithProperty( |
126 | 126 | $targetEntity->getStatements(), |
127 | 127 | $propertyId |
@@ -134,37 +134,37 @@ discard block |
||
134 | 134 | ); |
135 | 135 | } |
136 | 136 | |
137 | - if ( $requiredStatement !== null ) { |
|
137 | + if ($requiredStatement !== null) { |
|
138 | 138 | $status = CheckResult::STATUS_COMPLIANCE; |
139 | 139 | $message = ''; |
140 | 140 | } else { |
141 | 141 | $status = CheckResult::STATUS_VIOLATION; |
142 | - $message = wfMessage( 'wbqc-violation-message-target-required-claim' ); |
|
142 | + $message = wfMessage('wbqc-violation-message-target-required-claim'); |
|
143 | 143 | $message->rawParams( |
144 | - $this->constraintParameterRenderer->formatEntityId( $targetEntityId, Role::SUBJECT ), |
|
145 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::PREDICATE ) |
|
144 | + $this->constraintParameterRenderer->formatEntityId($targetEntityId, Role::SUBJECT), |
|
145 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::PREDICATE) |
|
146 | 146 | ); |
147 | - $message->numParams( count( $items ) ); |
|
148 | - $message->rawParams( $this->constraintParameterRenderer->formatItemIdSnakValueList( $items, Role::OBJECT ) ); |
|
147 | + $message->numParams(count($items)); |
|
148 | + $message->rawParams($this->constraintParameterRenderer->formatItemIdSnakValueList($items, Role::OBJECT)); |
|
149 | 149 | $message = $message->escaped(); |
150 | 150 | } |
151 | 151 | |
152 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
153 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
154 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
152 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
153 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
154 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
155 | 155 | } |
156 | 156 | |
157 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
157 | + public function checkConstraintParameters(Constraint $constraint) { |
|
158 | 158 | $constraintParameters = $constraint->getConstraintParameters(); |
159 | 159 | $exceptions = []; |
160 | 160 | try { |
161 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
162 | - } catch ( ConstraintParameterException $e ) { |
|
161 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
162 | + } catch (ConstraintParameterException $e) { |
|
163 | 163 | $exceptions[] = $e; |
164 | 164 | } |
165 | 165 | try { |
166 | - $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
167 | - } catch ( ConstraintParameterException $e ) { |
|
166 | + $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
167 | + } catch (ConstraintParameterException $e) { |
|
168 | 168 | $exceptions[] = $e; |
169 | 169 | } |
170 | 170 | return $exceptions; |
@@ -71,26 +71,26 @@ discard block |
||
71 | 71 | * @throws ConstraintParameterException |
72 | 72 | * @return CheckResult |
73 | 73 | */ |
74 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
74 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
75 | 75 | $parameters = []; |
76 | 76 | $constraintParameters = $constraint->getConstraintParameters(); |
77 | 77 | |
78 | - $format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
79 | - $parameters['pattern'] = [ $format ]; |
|
78 | + $format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
79 | + $parameters['pattern'] = [$format]; |
|
80 | 80 | |
81 | 81 | $syntaxClarification = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
82 | 82 | $constraintParameters, |
83 | 83 | WikibaseRepo::getDefaultInstance()->getUserLanguage() // TODO make this part of the Context? |
84 | 84 | ); |
85 | - if ( $syntaxClarification !== null ) { |
|
86 | - $parameters['clarification'] = [ $syntaxClarification ]; |
|
85 | + if ($syntaxClarification !== null) { |
|
86 | + $parameters['clarification'] = [$syntaxClarification]; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | $snak = $context->getSnak(); |
90 | 90 | |
91 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
91 | + if (!$snak instanceof PropertyValueSnak) { |
|
92 | 92 | // nothing to check |
93 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
93 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $dataValue = $snak->getDataValue(); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * error handling: |
100 | 100 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
101 | 101 | */ |
102 | - switch ( $dataValue->getType() ) { |
|
102 | + switch ($dataValue->getType()) { |
|
103 | 103 | case 'string': |
104 | 104 | $text = $dataValue->getValue(); |
105 | 105 | break; |
@@ -108,60 +108,59 @@ discard block |
||
108 | 108 | $text = $dataValue->getText(); |
109 | 109 | break; |
110 | 110 | default: |
111 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
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(), |
|
115 | - wfMessage( 'datatypes-type-monolingualtext' )->escaped() |
|
113 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
114 | + wfMessage('datatypes-type-string')->escaped(), |
|
115 | + wfMessage('datatypes-type-monolingualtext')->escaped() |
|
116 | 116 | ) |
117 | 117 | ->escaped(); |
118 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
118 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( $this->sparqlHelper !== null && $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
122 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
121 | + if ($this->sparqlHelper !== null && $this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
122 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
123 | 123 | $message = ''; |
124 | 124 | $status = CheckResult::STATUS_COMPLIANCE; |
125 | 125 | } else { |
126 | 126 | $message = wfMessage( |
127 | 127 | $syntaxClarification !== null ? |
128 | - 'wbqc-violation-message-format-clarification' : |
|
129 | - 'wbqc-violation-message-format' |
|
128 | + 'wbqc-violation-message-format-clarification' : 'wbqc-violation-message-format' |
|
130 | 129 | )->rawParams( |
131 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
132 | - $this->constraintParameterRenderer->formatDataValue( new StringValue( $text ), Role::OBJECT ), |
|
133 | - $this->constraintParameterRenderer->formatByRole( Role::CONSTRAINT_PARAMETER_VALUE, |
|
134 | - '<code><nowiki>' . htmlspecialchars( $format ) . '</nowiki></code>' ) |
|
130 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
131 | + $this->constraintParameterRenderer->formatDataValue(new StringValue($text), Role::OBJECT), |
|
132 | + $this->constraintParameterRenderer->formatByRole(Role::CONSTRAINT_PARAMETER_VALUE, |
|
133 | + '<code><nowiki>'.htmlspecialchars($format).'</nowiki></code>') |
|
135 | 134 | ); |
136 | - if ( $syntaxClarification !== null ) { |
|
137 | - $message->params( $syntaxClarification ); |
|
135 | + if ($syntaxClarification !== null) { |
|
136 | + $message->params($syntaxClarification); |
|
138 | 137 | } |
139 | 138 | $message = $message->escaped(); |
140 | 139 | $status = CheckResult::STATUS_VIOLATION; |
141 | 140 | } |
142 | 141 | } else { |
143 | - $message = wfMessage( "wbqc-violation-message-security-reason" ) |
|
144 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ) ) |
|
142 | + $message = wfMessage("wbqc-violation-message-security-reason") |
|
143 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM)) |
|
145 | 144 | ->escaped(); |
146 | 145 | $status = CheckResult::STATUS_TODO; |
147 | 146 | } |
148 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
147 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
149 | 148 | } |
150 | 149 | |
151 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
150 | + public function checkConstraintParameters(Constraint $constraint) { |
|
152 | 151 | $constraintParameters = $constraint->getConstraintParameters(); |
153 | 152 | $exceptions = []; |
154 | 153 | try { |
155 | - $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
156 | - } catch ( ConstraintParameterException $e ) { |
|
154 | + $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
155 | + } catch (ConstraintParameterException $e) { |
|
157 | 156 | $exceptions[] = $e; |
158 | 157 | } |
159 | 158 | try { |
160 | 159 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
161 | 160 | $constraintParameters, |
162 | - Language::factory( 'en' ) // errors are reported independent of language requested |
|
161 | + Language::factory('en') // errors are reported independent of language requested |
|
163 | 162 | ); |
164 | - } catch ( ConstraintParameterException $e ) { |
|
163 | + } catch (ConstraintParameterException $e) { |
|
165 | 164 | $exceptions[] = $e; |
166 | 165 | } |
167 | 166 | return $exceptions; |
@@ -82,35 +82,35 @@ discard block |
||
82 | 82 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
83 | 83 | * @return CheckResult |
84 | 84 | */ |
85 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
86 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
87 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
85 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
86 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
87 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | $parameters = []; |
91 | 91 | $constraintParameters = $constraint->getConstraintParameters(); |
92 | 92 | |
93 | - $classes = $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
93 | + $classes = $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
94 | 94 | $parameters['class'] = array_map( |
95 | - function( $id ) { |
|
96 | - return new ItemId( $id ); |
|
95 | + function($id) { |
|
96 | + return new ItemId($id); |
|
97 | 97 | }, |
98 | 98 | $classes |
99 | 99 | ); |
100 | 100 | |
101 | - $relation = $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
102 | - if ( $relation === 'instance' ) { |
|
103 | - $relationId = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
104 | - } elseif ( $relation === 'subclass' ) { |
|
105 | - $relationId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
101 | + $relation = $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
102 | + if ($relation === 'instance') { |
|
103 | + $relationId = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
104 | + } elseif ($relation === 'subclass') { |
|
105 | + $relationId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
106 | 106 | } |
107 | - $parameters['relation'] = [ $relation ]; |
|
107 | + $parameters['relation'] = [$relation]; |
|
108 | 108 | |
109 | 109 | $snak = $context->getSnak(); |
110 | 110 | |
111 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
111 | + if (!$snak instanceof PropertyValueSnak) { |
|
112 | 112 | // nothing to check |
113 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
113 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | $dataValue = $snak->getDataValue(); |
@@ -119,22 +119,22 @@ discard block |
||
119 | 119 | * error handling: |
120 | 120 | * type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid' |
121 | 121 | */ |
122 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
123 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
122 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
123 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
124 | 124 | ->rawParams( |
125 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
125 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
126 | 126 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
127 | 127 | ) |
128 | 128 | ->escaped(); |
129 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
129 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
130 | 130 | } |
131 | 131 | /** @var EntityIdValue $dataValue */ |
132 | 132 | |
133 | - $item = $this->entityLookup->getEntity( $dataValue->getEntityId() ); |
|
133 | + $item = $this->entityLookup->getEntity($dataValue->getEntityId()); |
|
134 | 134 | |
135 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
136 | - $message = wfMessage( "wbqc-violation-message-value-entity-must-exist" )->escaped(); |
|
137 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
135 | + if (!($item instanceof StatementListProvider)) { |
|
136 | + $message = wfMessage("wbqc-violation-message-value-entity-must-exist")->escaped(); |
|
137 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $statements = $item->getStatements(); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $classes |
146 | 146 | ); |
147 | 147 | |
148 | - if ( $result->getBool() ) { |
|
148 | + if ($result->getBool()) { |
|
149 | 149 | $message = ''; |
150 | 150 | $status = CheckResult::STATUS_COMPLIANCE; |
151 | 151 | } else { |
@@ -159,21 +159,21 @@ discard block |
||
159 | 159 | $status = CheckResult::STATUS_VIOLATION; |
160 | 160 | } |
161 | 161 | |
162 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
163 | - ->withMetadata( $result->getMetadata() ); |
|
162 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
163 | + ->withMetadata($result->getMetadata()); |
|
164 | 164 | } |
165 | 165 | |
166 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
166 | + public function checkConstraintParameters(Constraint $constraint) { |
|
167 | 167 | $constraintParameters = $constraint->getConstraintParameters(); |
168 | 168 | $exceptions = []; |
169 | 169 | try { |
170 | - $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
171 | - } catch ( ConstraintParameterException $e ) { |
|
170 | + $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
171 | + } catch (ConstraintParameterException $e) { |
|
172 | 172 | $exceptions[] = $e; |
173 | 173 | } |
174 | 174 | try { |
175 | - $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
176 | - } catch ( ConstraintParameterException $e ) { |
|
175 | + $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
176 | + } catch (ConstraintParameterException $e) { |
|
177 | 177 | $exceptions[] = $e; |
178 | 178 | } |
179 | 179 | return $exceptions; |
@@ -50,22 +50,22 @@ discard block |
||
50 | 50 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
51 | 51 | * @return CheckResult |
52 | 52 | */ |
53 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
54 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
55 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
53 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
54 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
55 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | $parameters = []; |
59 | 59 | |
60 | - if ( $this->sparqlHelper !== null ) { |
|
61 | - if ( $context->getType() === 'statement' ) { |
|
60 | + if ($this->sparqlHelper !== null) { |
|
61 | + if ($context->getType() === 'statement') { |
|
62 | 62 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
63 | 63 | $context->getSnakStatement(), |
64 | 64 | true // ignore deprecated statements |
65 | 65 | ); |
66 | 66 | } else { |
67 | - if ( $context->getSnak()->getType() !== 'value' ) { |
|
68 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
67 | + if ($context->getSnak()->getType() !== 'value') { |
|
68 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
69 | 69 | } |
70 | 70 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
71 | 71 | $context->getEntity()->getId(), |
@@ -78,29 +78,29 @@ discard block |
||
78 | 78 | $otherEntities = $result->getArray(); |
79 | 79 | $metadata = $result->getMetadata(); |
80 | 80 | |
81 | - if ( $otherEntities === [] ) { |
|
81 | + if ($otherEntities === []) { |
|
82 | 82 | $status = CheckResult::STATUS_COMPLIANCE; |
83 | 83 | $message = ''; |
84 | 84 | } else { |
85 | 85 | $status = CheckResult::STATUS_VIOLATION; |
86 | - $message = wfMessage( 'wbqc-violation-message-unique-value' ) |
|
87 | - ->numParams( count( $otherEntities ) ) |
|
88 | - ->rawParams( $this->constraintParameterRenderer->formatEntityIdList( $otherEntities, Role::SUBJECT ) ) |
|
86 | + $message = wfMessage('wbqc-violation-message-unique-value') |
|
87 | + ->numParams(count($otherEntities)) |
|
88 | + ->rawParams($this->constraintParameterRenderer->formatEntityIdList($otherEntities, Role::SUBJECT)) |
|
89 | 89 | ->escaped(); |
90 | 90 | } |
91 | 91 | } else { |
92 | 92 | $status = CheckResult::STATUS_TODO; |
93 | - $message = wfMessage( "wbqc-violation-message-not-yet-implemented" ) |
|
94 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ) ) |
|
93 | + $message = wfMessage("wbqc-violation-message-not-yet-implemented") |
|
94 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM)) |
|
95 | 95 | ->escaped(); |
96 | 96 | $metadata = Metadata::blank(); |
97 | 97 | } |
98 | 98 | |
99 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
100 | - ->withMetadata( $metadata ); |
|
99 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
100 | + ->withMetadata($metadata); |
|
101 | 101 | } |
102 | 102 | |
103 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
103 | + public function checkConstraintParameters(Constraint $constraint) { |
|
104 | 104 | // no parameters |
105 | 105 | return []; |
106 | 106 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | Config $config, |
140 | 140 | IBufferingStatsdDataFactory $dataFactory |
141 | 141 | ) { |
142 | - parent::__construct( 'ConstraintReport' ); |
|
142 | + parent::__construct('ConstraintReport'); |
|
143 | 143 | |
144 | 144 | $this->entityLookup = $entityLookup; |
145 | 145 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | $language = $this->getLanguage(); |
149 | 149 | |
150 | 150 | $formatterOptions = new FormatterOptions(); |
151 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
151 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
152 | 152 | $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter( |
153 | 153 | SnakFormatter::FORMAT_HTML, |
154 | 154 | $formatterOptions |
155 | 155 | ); |
156 | 156 | |
157 | - $labelLookup = $fallbackLabelDescLookupFactory->newLabelDescriptionLookup( $language ); |
|
157 | + $labelLookup = $fallbackLabelDescLookupFactory->newLabelDescriptionLookup($language); |
|
158 | 158 | |
159 | 159 | $this->entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( |
160 | 160 | $labelLookup |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @return array |
183 | 183 | */ |
184 | 184 | private function getModules() { |
185 | - return [ 'SpecialConstraintReportPage' ]; |
|
185 | + return ['SpecialConstraintReportPage']; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @return string |
201 | 201 | */ |
202 | 202 | public function getDescription() { |
203 | - return $this->msg( 'wbqc-constraintreport' )->escaped(); |
|
203 | + return $this->msg('wbqc-constraintreport')->escaped(); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -212,42 +212,42 @@ discard block |
||
212 | 212 | * @throws EntityIdParsingException |
213 | 213 | * @throws UnexpectedValueException |
214 | 214 | */ |
215 | - public function execute( $subPage ) { |
|
215 | + public function execute($subPage) { |
|
216 | 216 | $out = $this->getOutput(); |
217 | 217 | |
218 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
219 | - if ( $postRequest ) { |
|
220 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
218 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
219 | + if ($postRequest) { |
|
220 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
221 | 221 | return; |
222 | 222 | } |
223 | 223 | |
224 | - $out->addModules( $this->getModules() ); |
|
224 | + $out->addModules($this->getModules()); |
|
225 | 225 | |
226 | 226 | $this->setHeaders(); |
227 | 227 | |
228 | - $out->addHTML( $this->getExplanationText() ); |
|
228 | + $out->addHTML($this->getExplanationText()); |
|
229 | 229 | $this->buildEntityIdForm(); |
230 | 230 | |
231 | - if ( !$subPage ) { |
|
231 | + if (!$subPage) { |
|
232 | 232 | return; |
233 | 233 | } |
234 | 234 | |
235 | - if ( !is_string( $subPage ) ) { |
|
236 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
235 | + if (!is_string($subPage)) { |
|
236 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | try { |
240 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
241 | - } catch ( EntityIdParsingException $e ) { |
|
240 | + $entityId = $this->entityIdParser->parse($subPage); |
|
241 | + } catch (EntityIdParsingException $e) { |
|
242 | 242 | $out->addHTML( |
243 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
243 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
244 | 244 | ); |
245 | 245 | return; |
246 | 246 | } |
247 | 247 | |
248 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
248 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
249 | 249 | $out->addHTML( |
250 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
250 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
251 | 251 | ); |
252 | 252 | return; |
253 | 253 | } |
@@ -255,18 +255,18 @@ discard block |
||
255 | 255 | $this->dataFactory->increment( |
256 | 256 | 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck' |
257 | 257 | ); |
258 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
258 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
259 | 259 | |
260 | - if ( count( $results ) > 0 ) { |
|
260 | + if (count($results) > 0) { |
|
261 | 261 | $out->addHTML( |
262 | - $this->buildResultHeader( $entityId ) |
|
263 | - . $this->buildSummary( $results ) |
|
264 | - . $this->buildResultTable( $entityId, $results ) |
|
262 | + $this->buildResultHeader($entityId) |
|
263 | + . $this->buildSummary($results) |
|
264 | + . $this->buildResultTable($entityId, $results) |
|
265 | 265 | ); |
266 | 266 | } else { |
267 | 267 | $out->addHTML( |
268 | - $this->buildResultHeader( $entityId ) |
|
269 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
268 | + $this->buildResultHeader($entityId) |
|
269 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
270 | 270 | ); |
271 | 271 | } |
272 | 272 | } |
@@ -282,15 +282,15 @@ discard block |
||
282 | 282 | 'name' => 'entityid', |
283 | 283 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
284 | 284 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
285 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped() |
|
285 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped() |
|
286 | 286 | ] |
287 | 287 | ]; |
288 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
289 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
290 | - $htmlForm->setSubmitCallback( function() { |
|
288 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
289 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
290 | + $htmlForm->setSubmitCallback(function() { |
|
291 | 291 | return false; |
292 | 292 | } ); |
293 | - $htmlForm->setMethod( 'post' ); |
|
293 | + $htmlForm->setMethod('post'); |
|
294 | 294 | $htmlForm->show(); |
295 | 295 | } |
296 | 296 | |
@@ -304,16 +304,16 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return string HTML |
306 | 306 | */ |
307 | - private function buildNotice( $messageKey, $error = false ) { |
|
308 | - if ( !is_string( $messageKey ) ) { |
|
309 | - throw new InvalidArgumentException( '$message must be string.' ); |
|
307 | + private function buildNotice($messageKey, $error = false) { |
|
308 | + if (!is_string($messageKey)) { |
|
309 | + throw new InvalidArgumentException('$message must be string.'); |
|
310 | 310 | } |
311 | - if ( !is_bool( $error ) ) { |
|
312 | - throw new InvalidArgumentException( '$error must be bool.' ); |
|
311 | + if (!is_bool($error)) { |
|
312 | + throw new InvalidArgumentException('$error must be bool.'); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | $cssClasses = 'wbqc-constraintreport-notice'; |
316 | - if ( $error ) { |
|
316 | + if ($error) { |
|
317 | 317 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
318 | 318 | } |
319 | 319 | |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | [ |
323 | 323 | 'class' => $cssClasses |
324 | 324 | ], |
325 | - $this->msg( $messageKey )->escaped() |
|
325 | + $this->msg($messageKey)->escaped() |
|
326 | 326 | ); |
327 | 327 | } |
328 | 328 | |
@@ -332,16 +332,16 @@ discard block |
||
332 | 332 | private function getExplanationText() { |
333 | 333 | return Html::rawElement( |
334 | 334 | 'div', |
335 | - [ 'class' => 'wbqc-explanation' ], |
|
335 | + ['class' => 'wbqc-explanation'], |
|
336 | 336 | Html::rawElement( |
337 | 337 | 'p', |
338 | 338 | [], |
339 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
339 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
340 | 340 | ) |
341 | 341 | . Html::rawElement( |
342 | 342 | 'p', |
343 | 343 | [], |
344 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
344 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
345 | 345 | ) |
346 | 346 | ); |
347 | 347 | } |
@@ -352,69 +352,69 @@ discard block |
||
352 | 352 | * |
353 | 353 | * @return string HTML |
354 | 354 | */ |
355 | - private function buildResultTable( EntityId $entityId, array $results ) { |
|
355 | + private function buildResultTable(EntityId $entityId, array $results) { |
|
356 | 356 | // Set table headers |
357 | 357 | $table = new HtmlTableBuilder( |
358 | 358 | [ |
359 | 359 | new HtmlTableHeaderBuilder( |
360 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(), |
|
360 | + $this->msg('wbqc-constraintreport-result-table-header-status')->escaped(), |
|
361 | 361 | true |
362 | 362 | ), |
363 | 363 | new HtmlTableHeaderBuilder( |
364 | - $this->msg( 'wbqc-constraintreport-result-table-header-claim' )->escaped(), |
|
364 | + $this->msg('wbqc-constraintreport-result-table-header-claim')->escaped(), |
|
365 | 365 | true |
366 | 366 | ), |
367 | 367 | new HtmlTableHeaderBuilder( |
368 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(), |
|
368 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(), |
|
369 | 369 | true |
370 | 370 | ) |
371 | 371 | ] |
372 | 372 | ); |
373 | 373 | |
374 | - foreach ( $results as $result ) { |
|
375 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
374 | + foreach ($results as $result) { |
|
375 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | return $table->toHtml(); |
379 | 379 | } |
380 | 380 | |
381 | - private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) { |
|
381 | + private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) { |
|
382 | 382 | // Status column |
383 | 383 | $statusColumn = $this->buildTooltipElement( |
384 | - $this->formatStatus( $result->getStatus() ), |
|
384 | + $this->formatStatus($result->getStatus()), |
|
385 | 385 | $result->getMessage(), |
386 | 386 | '[?]' |
387 | 387 | ); |
388 | 388 | |
389 | 389 | // Claim column |
390 | - $property = $this->entityIdLabelFormatter->formatEntityId( $result->getContext()->getSnak()->getPropertyId() ); |
|
391 | - if ( $result->getSnakType() === 'value' ) { |
|
392 | - $value = $this->constraintParameterRenderer->formatValue( $result->getDataValue() ); |
|
390 | + $property = $this->entityIdLabelFormatter->formatEntityId($result->getContext()->getSnak()->getPropertyId()); |
|
391 | + if ($result->getSnakType() === 'value') { |
|
392 | + $value = $this->constraintParameterRenderer->formatValue($result->getDataValue()); |
|
393 | 393 | } else { |
394 | - $value = htmlspecialchars( $result->getSnakType() ); |
|
394 | + $value = htmlspecialchars($result->getSnakType()); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | $claimColumn = $this->getClaimLink( |
398 | 398 | $entityId, |
399 | 399 | $result->getContext()->getSnak()->getPropertyId(), |
400 | - $property . ': ' . $value |
|
400 | + $property.': '.$value |
|
401 | 401 | ); |
402 | 402 | |
403 | 403 | // Constraint column |
404 | 404 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
405 | 405 | try { |
406 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
407 | - } catch ( InvalidArgumentException $e ) { |
|
408 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
406 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
407 | + } catch (InvalidArgumentException $e) { |
|
408 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
409 | 409 | } |
410 | 410 | $constraintLink = $this->getClaimLink( |
411 | 411 | $result->getContext()->getSnak()->getPropertyId(), |
412 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
412 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
413 | 413 | $constraintTypeLabel |
414 | 414 | ); |
415 | 415 | $constraintColumn = $this->buildExpandableElement( |
416 | 416 | $constraintLink, |
417 | - $this->constraintParameterRenderer->formatParameters( $result->getParameters() ), |
|
417 | + $this->constraintParameterRenderer->formatParameters($result->getParameters()), |
|
418 | 418 | '[...]' |
419 | 419 | ); |
420 | 420 | |
@@ -449,15 +449,15 @@ discard block |
||
449 | 449 | * |
450 | 450 | * @return string HTML |
451 | 451 | */ |
452 | - protected function buildResultHeader( EntityId $entityId ) { |
|
453 | - $entityLink = sprintf( '%s (%s)', |
|
454 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
455 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
452 | + protected function buildResultHeader(EntityId $entityId) { |
|
453 | + $entityLink = sprintf('%s (%s)', |
|
454 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
455 | + htmlspecialchars($entityId->getSerialization())); |
|
456 | 456 | |
457 | 457 | return Html::rawElement( |
458 | 458 | 'h3', |
459 | 459 | [], |
460 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
460 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
461 | 461 | ); |
462 | 462 | } |
463 | 463 | |
@@ -468,24 +468,24 @@ discard block |
||
468 | 468 | * |
469 | 469 | * @return string HTML |
470 | 470 | */ |
471 | - protected function buildSummary( array $results ) { |
|
471 | + protected function buildSummary(array $results) { |
|
472 | 472 | $statuses = []; |
473 | - foreach ( $results as $result ) { |
|
474 | - $status = strtolower( $result->getStatus() ); |
|
475 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
473 | + foreach ($results as $result) { |
|
474 | + $status = strtolower($result->getStatus()); |
|
475 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | $statusElements = []; |
479 | - foreach ( $statuses as $status => $count ) { |
|
480 | - if ( $count > 0 ) { |
|
479 | + foreach ($statuses as $status => $count) { |
|
480 | + if ($count > 0) { |
|
481 | 481 | $statusElements[] = |
482 | - $this->formatStatus( $status ) |
|
482 | + $this->formatStatus($status) |
|
483 | 483 | . ': ' |
484 | 484 | . $count; |
485 | 485 | } |
486 | 486 | } |
487 | 487 | |
488 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
488 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | /** |
@@ -500,15 +500,15 @@ discard block |
||
500 | 500 | * |
501 | 501 | * @return string HTML |
502 | 502 | */ |
503 | - protected function buildTooltipElement( $content, $tooltipContent, $indicator ) { |
|
504 | - if ( !is_string( $content ) ) { |
|
505 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
503 | + protected function buildTooltipElement($content, $tooltipContent, $indicator) { |
|
504 | + if (!is_string($content)) { |
|
505 | + throw new InvalidArgumentException('$content has to be string.'); |
|
506 | 506 | } |
507 | - if ( $tooltipContent && ( !is_string( $tooltipContent ) ) ) { |
|
508 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
507 | + if ($tooltipContent && (!is_string($tooltipContent))) { |
|
508 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
509 | 509 | } |
510 | 510 | |
511 | - if ( empty( $tooltipContent ) ) { |
|
511 | + if (empty($tooltipContent)) { |
|
512 | 512 | return $content; |
513 | 513 | } |
514 | 514 | |
@@ -525,13 +525,13 @@ discard block |
||
525 | 525 | [ |
526 | 526 | 'class' => 'wbqc-indicator' |
527 | 527 | ], |
528 | - htmlspecialchars( $indicator ) . $tooltip |
|
528 | + htmlspecialchars($indicator).$tooltip |
|
529 | 529 | ); |
530 | 530 | |
531 | 531 | return Html::rawElement( |
532 | 532 | 'span', |
533 | 533 | [], |
534 | - sprintf( '%s %s', $content, $tooltipIndicator ) |
|
534 | + sprintf('%s %s', $content, $tooltipIndicator) |
|
535 | 535 | ); |
536 | 536 | } |
537 | 537 | |
@@ -547,15 +547,15 @@ discard block |
||
547 | 547 | * |
548 | 548 | * @return string HTML |
549 | 549 | */ |
550 | - protected function buildExpandableElement( $content, $expandableContent, $indicator ) { |
|
551 | - if ( !is_string( $content ) ) { |
|
552 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
550 | + protected function buildExpandableElement($content, $expandableContent, $indicator) { |
|
551 | + if (!is_string($content)) { |
|
552 | + throw new InvalidArgumentException('$content has to be string.'); |
|
553 | 553 | } |
554 | - if ( $expandableContent && ( !is_string( $expandableContent ) ) ) { |
|
555 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
554 | + if ($expandableContent && (!is_string($expandableContent))) { |
|
555 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
556 | 556 | } |
557 | 557 | |
558 | - if ( empty( $expandableContent ) ) { |
|
558 | + if (empty($expandableContent)) { |
|
559 | 559 | return $content; |
560 | 560 | } |
561 | 561 | |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | ); |
577 | 577 | |
578 | 578 | return |
579 | - sprintf( '%s %s %s', $content, $tooltipIndicator, $expandableContent ); |
|
579 | + sprintf('%s %s %s', $content, $tooltipIndicator, $expandableContent); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | /** |
@@ -588,16 +588,16 @@ discard block |
||
588 | 588 | * |
589 | 589 | * @return string HTML |
590 | 590 | */ |
591 | - private function formatStatus( $status ) { |
|
592 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
591 | + private function formatStatus($status) { |
|
592 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
593 | 593 | |
594 | 594 | $formattedStatus = |
595 | 595 | Html::element( |
596 | 596 | 'span', |
597 | 597 | [ |
598 | - 'class' => 'wbqc-status wbqc-status-' . $status |
|
598 | + 'class' => 'wbqc-status wbqc-status-'.$status |
|
599 | 599 | ], |
600 | - $this->msg( $messageName )->text() |
|
600 | + $this->msg($messageName)->text() |
|
601 | 601 | ); |
602 | 602 | |
603 | 603 | return $formattedStatus; |
@@ -613,26 +613,26 @@ discard block |
||
613 | 613 | * |
614 | 614 | * @return string HTML |
615 | 615 | */ |
616 | - protected function formatDataValues( $dataValues, $separator = ', ' ) { |
|
617 | - if ( $dataValues instanceof DataValue ) { |
|
618 | - $dataValues = [ $dataValues ]; |
|
619 | - } elseif ( !is_array( $dataValues ) ) { |
|
620 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
616 | + protected function formatDataValues($dataValues, $separator = ', ') { |
|
617 | + if ($dataValues instanceof DataValue) { |
|
618 | + $dataValues = [$dataValues]; |
|
619 | + } elseif (!is_array($dataValues)) { |
|
620 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | $formattedDataValues = []; |
624 | - foreach ( $dataValues as $dataValue ) { |
|
625 | - if ( !( $dataValue instanceof DataValue ) ) { |
|
626 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
624 | + foreach ($dataValues as $dataValue) { |
|
625 | + if (!($dataValue instanceof DataValue)) { |
|
626 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
627 | 627 | } |
628 | - if ( $dataValue instanceof EntityIdValue ) { |
|
629 | - $formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() ); |
|
628 | + if ($dataValue instanceof EntityIdValue) { |
|
629 | + $formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId()); |
|
630 | 630 | } else { |
631 | - $formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue ); |
|
631 | + $formattedDataValues[] = $this->dataValueFormatter->format($dataValue); |
|
632 | 632 | } |
633 | 633 | } |
634 | 634 | |
635 | - return implode( $separator, $formattedDataValues ); |
|
635 | + return implode($separator, $formattedDataValues); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | /** |
@@ -644,12 +644,12 @@ discard block |
||
644 | 644 | * |
645 | 645 | * @return string HTML |
646 | 646 | */ |
647 | - private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) { |
|
647 | + private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) { |
|
648 | 648 | return |
649 | 649 | Html::rawElement( |
650 | 650 | 'a', |
651 | 651 | [ |
652 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
652 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
653 | 653 | 'target' => '_blank' |
654 | 654 | ], |
655 | 655 | $text |
@@ -664,9 +664,9 @@ discard block |
||
664 | 664 | * |
665 | 665 | * @return string |
666 | 666 | */ |
667 | - private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) { |
|
668 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
669 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
667 | + private function getClaimUrl(EntityId $entityId, PropertyId $propertyId) { |
|
668 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
669 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
670 | 670 | |
671 | 671 | return $entityUrl; |
672 | 672 | } |