@@ -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 | } |
@@ -28,16 +28,16 @@ |
||
28 | 28 | * |
29 | 29 | * @return CheckResult |
30 | 30 | */ |
31 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
32 | - if ( $context->getType() === Context::TYPE_QUALIFIER ) { |
|
33 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE, '' ); |
|
31 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
32 | + if ($context->getType() === Context::TYPE_QUALIFIER) { |
|
33 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE, ''); |
|
34 | 34 | } else { |
35 | - $message = wfMessage( 'wbqc-violation-message-qualifier' )->escaped(); |
|
36 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
35 | + $message = wfMessage('wbqc-violation-message-qualifier')->escaped(); |
|
36 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
40 | + public function checkConstraintParameters(Constraint $constraint) { |
|
41 | 41 | // no parameters |
42 | 42 | return []; |
43 | 43 | } |
@@ -10,7 +10,7 @@ |
||
10 | 10 | class SparqlHelperException extends RuntimeException { |
11 | 11 | |
12 | 12 | public function __construct() { |
13 | - parent::__construct( 'The SPARQL query endpoint returned an error.' ); |
|
13 | + parent::__construct('The SPARQL query endpoint returned an error.'); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | } |
@@ -16,8 +16,8 @@ |
||
16 | 16 | /** |
17 | 17 | * @param string $message HTML |
18 | 18 | */ |
19 | - public function __construct( $message ) { |
|
20 | - parent::__construct( $message ); |
|
19 | + public function __construct($message) { |
|
20 | + parent::__construct($message); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | } |
@@ -24,14 +24,14 @@ |
||
24 | 24 | * |
25 | 25 | * @return int[] |
26 | 26 | */ |
27 | - public function getPropertyCount( StatementList $statements ) { |
|
28 | - if ( !isset( $this->propertyCount ) ) { |
|
27 | + public function getPropertyCount(StatementList $statements) { |
|
28 | + if (!isset($this->propertyCount)) { |
|
29 | 29 | $this->propertyCount = []; |
30 | 30 | |
31 | 31 | /** @var Statement $statement */ |
32 | - foreach ( $statements as $statement ) { |
|
32 | + foreach ($statements as $statement) { |
|
33 | 33 | $counter = $statement->getRank() === Statement::RANK_DEPRECATED ? 0 : 1; |
34 | - if ( array_key_exists( $statement->getPropertyId()->getSerialization(), $this->propertyCount ) ) { |
|
34 | + if (array_key_exists($statement->getPropertyId()->getSerialization(), $this->propertyCount)) { |
|
35 | 35 | $this->propertyCount[$statement->getPropertyId()->getSerialization()] += $counter; |
36 | 36 | } else { |
37 | 37 | $this->propertyCount[$statement->getPropertyId()->getSerialization()] = $counter; |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | $this->dataFactory = $dataFactory; |
49 | 49 | $this->logger = $logger; |
50 | 50 | $this->constraintCheckDurationLimits = [ |
51 | - 'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ), |
|
52 | - 'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ), |
|
51 | + 'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'), |
|
52 | + 'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'), |
|
53 | 53 | ]; |
54 | 54 | } |
55 | 55 | |
@@ -75,41 +75,41 @@ discard block |
||
75 | 75 | $durationSeconds, |
76 | 76 | $method |
77 | 77 | ) { |
78 | - $constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 ); |
|
78 | + $constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1); |
|
79 | 79 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
80 | 80 | |
81 | 81 | $this->dataFactory->timing( |
82 | - 'wikibase.quality.constraints.check.timing.' . |
|
83 | - $constraintTypeItemId . '-' . |
|
82 | + 'wikibase.quality.constraints.check.timing.'. |
|
83 | + $constraintTypeItemId.'-'. |
|
84 | 84 | $constraintCheckerClassShortName, |
85 | 85 | $durationSeconds * 1000 |
86 | 86 | ); |
87 | 87 | |
88 | 88 | // find the longest limit (and associated log level) that the duration exceeds |
89 | - foreach ( $this->constraintCheckDurationLimits as $level => $limit ) { |
|
89 | + foreach ($this->constraintCheckDurationLimits as $level => $limit) { |
|
90 | 90 | if ( |
91 | 91 | // duration exceeds this limit |
92 | - isset( $limit ) && $durationSeconds > $limit && |
|
92 | + isset($limit) && $durationSeconds > $limit && |
|
93 | 93 | // this limit is longer than previous longest limit |
94 | - ( !isset( $limitSeconds ) || $limit > $limitSeconds ) |
|
94 | + (!isset($limitSeconds) || $limit > $limitSeconds) |
|
95 | 95 | ) { |
96 | 96 | $limitSeconds = $limit; |
97 | 97 | $logLevel = $level; |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | - if ( !isset( $limitSeconds ) ) { |
|
101 | + if (!isset($limitSeconds)) { |
|
102 | 102 | return; |
103 | 103 | } |
104 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
104 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
105 | 105 | // TODO log less details but still log something |
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | 109 | $this->logger->log( |
110 | 110 | $logLevel, |
111 | - 'Constraint check with {constraintCheckerClassShortName} ' . |
|
112 | - 'took longer than {limitSeconds} second(s) ' . |
|
111 | + 'Constraint check with {constraintCheckerClassShortName} '. |
|
112 | + 'took longer than {limitSeconds} second(s) '. |
|
113 | 113 | '(duration: {durationSeconds} seconds).', |
114 | 114 | [ |
115 | 115 | 'method' => $method, |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | UnitConverter $unitConverter = null |
48 | 48 | ) { |
49 | 49 | $this->config = $config; |
50 | - $this->timeParser = ( new TimeParserFactory() )->getTimeParser(); |
|
50 | + $this->timeParser = (new TimeParserFactory())->getTimeParser(); |
|
51 | 51 | $this->timeCalculator = new TimeValueCalculator(); |
52 | 52 | $this->unitConverter = $unitConverter; |
53 | 53 | } |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | * @param UnboundedQuantityValue $value |
57 | 57 | * @return UnboundedQuantityValue $value converted to standard units if possible, otherwise unchanged $value. |
58 | 58 | */ |
59 | - private function standardize( UnboundedQuantityValue $value ) { |
|
60 | - if ( $this->unitConverter !== null ) { |
|
61 | - $standard = $this->unitConverter->toStandardUnits( $value ); |
|
62 | - if ( $standard !== null ) { |
|
59 | + private function standardize(UnboundedQuantityValue $value) { |
|
60 | + if ($this->unitConverter !== null) { |
|
61 | + $standard = $this->unitConverter->toStandardUnits($value); |
|
62 | + if ($standard !== null) { |
|
63 | 63 | return $standard; |
64 | 64 | } else { |
65 | 65 | return $value; |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | * when $lhs is respectively less than, equal to, or greater than $rhs. |
82 | 82 | * (In other words, just like the “spaceship” operator <=>.) |
83 | 83 | */ |
84 | - public function getComparison( DataValue $lhs = null, DataValue $rhs = null ) { |
|
85 | - if ( $lhs === null || $rhs === null ) { |
|
84 | + public function getComparison(DataValue $lhs = null, DataValue $rhs = null) { |
|
85 | + if ($lhs === null || $rhs === null) { |
|
86 | 86 | return 0; |
87 | 87 | } |
88 | 88 | |
89 | - if ( $lhs->getType() !== $rhs->getType() ) { |
|
90 | - throw new InvalidArgumentException( 'Different data value types' ); |
|
89 | + if ($lhs->getType() !== $rhs->getType()) { |
|
90 | + throw new InvalidArgumentException('Different data value types'); |
|
91 | 91 | } |
92 | 92 | |
93 | - switch ( $lhs->getType() ) { |
|
93 | + switch ($lhs->getType()) { |
|
94 | 94 | case 'time': |
95 | 95 | /** @var TimeValue $lhs */ |
96 | 96 | /** @var TimeValue $rhs */ |
97 | - $lhsTimestamp = $this->timeCalculator->getTimestamp( $lhs ); |
|
98 | - $rhsTimestamp = $this->timeCalculator->getTimestamp( $rhs ); |
|
97 | + $lhsTimestamp = $this->timeCalculator->getTimestamp($lhs); |
|
98 | + $rhsTimestamp = $this->timeCalculator->getTimestamp($rhs); |
|
99 | 99 | |
100 | - if ( $lhsTimestamp === $rhsTimestamp ) { |
|
100 | + if ($lhsTimestamp === $rhsTimestamp) { |
|
101 | 101 | return 0; |
102 | 102 | } |
103 | 103 | |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | case 'quantity': |
106 | 106 | /** @var QuantityValue|UnboundedQuantityValue $lhs */ |
107 | 107 | /** @var QuantityValue|UnboundedQuantityValue $rhs */ |
108 | - $lhsStandard = $this->standardize( $lhs ); |
|
109 | - $rhsStandard = $this->standardize( $rhs ); |
|
110 | - return $lhsStandard->getAmount()->compare( $rhsStandard->getAmount() ); |
|
108 | + $lhsStandard = $this->standardize($lhs); |
|
109 | + $rhsStandard = $this->standardize($rhs); |
|
110 | + return $lhsStandard->getAmount()->compare($rhsStandard->getAmount()); |
|
111 | 111 | } |
112 | 112 | |
113 | - throw new InvalidArgumentException( 'Unsupported data value type' ); |
|
113 | + throw new InvalidArgumentException('Unsupported data value type'); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -125,83 +125,83 @@ discard block |
||
125 | 125 | * @throws InvalidArgumentException if the values do not both have the same, supported data value type |
126 | 126 | * @return UnboundedQuantityValue |
127 | 127 | */ |
128 | - public function getDifference( DataValue $minuend, DataValue $subtrahend ) { |
|
129 | - if ( $minuend->getType() === 'time' && $subtrahend->getType() === 'time' ) { |
|
130 | - $minuendSeconds = $this->timeCalculator->getTimestamp( $minuend ); |
|
131 | - $subtrahendSeconds = $this->timeCalculator->getTimestamp( $subtrahend ); |
|
128 | + public function getDifference(DataValue $minuend, DataValue $subtrahend) { |
|
129 | + if ($minuend->getType() === 'time' && $subtrahend->getType() === 'time') { |
|
130 | + $minuendSeconds = $this->timeCalculator->getTimestamp($minuend); |
|
131 | + $subtrahendSeconds = $this->timeCalculator->getTimestamp($subtrahend); |
|
132 | 132 | return UnboundedQuantityValue::newFromNumber( |
133 | 133 | $minuendSeconds - $subtrahendSeconds, |
134 | - $this->config->get( 'WBQualityConstraintsSecondUnit' ) |
|
134 | + $this->config->get('WBQualityConstraintsSecondUnit') |
|
135 | 135 | ); |
136 | 136 | } |
137 | - if ( $minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity' ) { |
|
138 | - $minuendStandard = $this->standardize( $minuend ); |
|
139 | - $subtrahendStandard = $this->standardize( $subtrahend ); |
|
137 | + if ($minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity') { |
|
138 | + $minuendStandard = $this->standardize($minuend); |
|
139 | + $subtrahendStandard = $this->standardize($subtrahend); |
|
140 | 140 | $minuendValue = $minuendStandard->getAmount()->getValueFloat(); |
141 | 141 | $subtrahendValue = $subtrahendStandard->getAmount()->getValueFloat(); |
142 | 142 | $diff = $minuendValue - $subtrahendValue; |
143 | 143 | // we don’t check whether both quantities have the same standard unit – |
144 | 144 | // that’s the job of a different constraint type, Units (T164372) |
145 | - return UnboundedQuantityValue::newFromNumber( $diff, $minuendStandard->getUnit() ); |
|
145 | + return UnboundedQuantityValue::newFromNumber($diff, $minuendStandard->getUnit()); |
|
146 | 146 | } |
147 | 147 | |
148 | - throw new InvalidArgumentException( 'Unsupported or different data value types' ); |
|
148 | + throw new InvalidArgumentException('Unsupported or different data value types'); |
|
149 | 149 | } |
150 | 150 | |
151 | - public function getDifferenceInYears( TimeValue $minuend, TimeValue $subtrahend ) { |
|
152 | - if ( !preg_match( '/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches ) || |
|
153 | - !preg_match( '/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches ) |
|
151 | + public function getDifferenceInYears(TimeValue $minuend, TimeValue $subtrahend) { |
|
152 | + if (!preg_match('/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches) || |
|
153 | + !preg_match('/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches) |
|
154 | 154 | ) { |
155 | - throw new InvalidArgumentException( 'TimeValue::getTime() did not match expected format' ); |
|
155 | + throw new InvalidArgumentException('TimeValue::getTime() did not match expected format'); |
|
156 | 156 | } |
157 | - $minuendYear = (float)$minuendMatches[1]; |
|
158 | - $subtrahendYear = (float)$subtrahendMatches[1]; |
|
157 | + $minuendYear = (float) $minuendMatches[1]; |
|
158 | + $subtrahendYear = (float) $subtrahendMatches[1]; |
|
159 | 159 | $minuendRest = $minuendMatches[2]; |
160 | 160 | $subtrahendRest = $subtrahendMatches[2]; |
161 | 161 | |
162 | 162 | // calculate difference of years |
163 | 163 | $diff = $minuendYear - $subtrahendYear; |
164 | - if ( $minuendYear > 0.0 && $subtrahendYear < 0.0 ) { |
|
164 | + if ($minuendYear > 0.0 && $subtrahendYear < 0.0) { |
|
165 | 165 | $diff -= 1.0; // there is no year 0, remove it from difference |
166 | - } elseif ( $minuendYear < 0.0 && $subtrahendYear > 0.0 ) { |
|
166 | + } elseif ($minuendYear < 0.0 && $subtrahendYear > 0.0) { |
|
167 | 167 | $diff -= -1.0; // there is no year 0, remove it from negative difference |
168 | 168 | } |
169 | 169 | |
170 | 170 | // adjust for date within year by parsing the month-day part within the same year |
171 | - $minuendDateValue = $this->timeParser->parse( '+0000000000001970-' . $minuendRest ); |
|
172 | - $subtrahendDateValue = $this->timeParser->parse( '+0000000000001970-' . $subtrahendRest ); |
|
173 | - $minuendDateSeconds = $this->timeCalculator->getTimestamp( $minuendDateValue ); |
|
174 | - $subtrahendDateSeconds = $this->timeCalculator->getTimestamp( $subtrahendDateValue ); |
|
175 | - if ( $minuendDateSeconds < $subtrahendDateSeconds ) { |
|
171 | + $minuendDateValue = $this->timeParser->parse('+0000000000001970-'.$minuendRest); |
|
172 | + $subtrahendDateValue = $this->timeParser->parse('+0000000000001970-'.$subtrahendRest); |
|
173 | + $minuendDateSeconds = $this->timeCalculator->getTimestamp($minuendDateValue); |
|
174 | + $subtrahendDateSeconds = $this->timeCalculator->getTimestamp($subtrahendDateValue); |
|
175 | + if ($minuendDateSeconds < $subtrahendDateSeconds) { |
|
176 | 176 | // difference in the last year is actually less than one full year |
177 | 177 | // e. g. 1975-03-01 - 1974-09-01 is just six months |
178 | 178 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
179 | 179 | $diff -= 0.5; |
180 | - } elseif ( $minuendDateSeconds > $subtrahendDateSeconds ) { |
|
180 | + } elseif ($minuendDateSeconds > $subtrahendDateSeconds) { |
|
181 | 181 | // difference in the last year is actually more than one full year |
182 | 182 | // e. g. 1975-09-01 - 1974-03-01 is 18 months |
183 | 183 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
184 | 184 | $diff += 0.5; |
185 | 185 | } |
186 | 186 | |
187 | - $unit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
188 | - return UnboundedQuantityValue::newFromNumber( $diff, $unit ); |
|
187 | + $unit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
188 | + return UnboundedQuantityValue::newFromNumber($diff, $unit); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * @param string $timeString |
193 | 193 | * @return TimeValue |
194 | 194 | */ |
195 | - public function parseTime( $timeString ) { |
|
196 | - return $this->timeParser->parse( $timeString ); |
|
195 | + public function parseTime($timeString) { |
|
196 | + return $this->timeParser->parse($timeString); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
200 | 200 | * @param string $quantityString |
201 | 201 | * @return QuantityValue|UnboundedQuantityValue |
202 | 202 | */ |
203 | - public function parseQuantity( $quantityString ) { |
|
204 | - return UnboundedQuantityValue::newFromNumber( $quantityString ); |
|
203 | + public function parseQuantity($quantityString) { |
|
204 | + return UnboundedQuantityValue::newFromNumber($quantityString); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | } |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | public function getDataValue() { |
147 | 147 | $mainSnak = $this->context->getSnak(); |
148 | 148 | |
149 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
149 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
150 | 150 | return $mainSnak->getDataValue(); |
151 | 151 | } |
152 | 152 | |
153 | - throw new LogicException( 'Cannot get DataValue, Snak is of type ' . $this->getSnakType() . '.' ); |
|
153 | + throw new LogicException('Cannot get DataValue, Snak is of type '.$this->getSnakType().'.'); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @param string $key |
179 | 179 | * @param string $value |
180 | 180 | */ |
181 | - public function addParameter( $key, $value ) { |
|
181 | + public function addParameter($key, $value) { |
|
182 | 182 | $this->parameters[$key][] = $value; |
183 | 183 | } |
184 | 184 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | /** |
193 | 193 | * @param string $status |
194 | 194 | */ |
195 | - public function setStatus( $status ) { |
|
195 | + public function setStatus($status) { |
|
196 | 196 | $this->status = $status; |
197 | 197 | } |
198 | 198 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * @param Metadata $cm |
208 | 208 | * @return self |
209 | 209 | */ |
210 | - public function withMetadata( Metadata $cm ) { |
|
210 | + public function withMetadata(Metadata $cm) { |
|
211 | 211 | $this->metadata = $cm; |
212 | 212 | return $this; |
213 | 213 | } |