@@ -21,23 +21,23 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @return Constraint[] |
23 | 23 | */ |
24 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
25 | - $db = wfGetDB( DB_REPLICA ); |
|
24 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
25 | + $db = wfGetDB(DB_REPLICA); |
|
26 | 26 | |
27 | 27 | $results = $db->select( |
28 | 28 | 'wbqc_constraints', |
29 | 29 | '*', |
30 | - [ 'pid' => $propertyId->getNumericId() ] |
|
30 | + ['pid' => $propertyId->getNumericId()] |
|
31 | 31 | ); |
32 | 32 | |
33 | - return $this->convertToConstraints( $results ); |
|
33 | + return $this->convertToConstraints($results); |
|
34 | 34 | } |
35 | 35 | |
36 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
37 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
36 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
37 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
38 | 38 | |
39 | - if ( strlen( $json ) > 50000 ) { |
|
40 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
39 | + if (strlen($json) > 50000) { |
|
40 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | return $json; |
@@ -49,21 +49,21 @@ discard block |
||
49 | 49 | * @throws DBUnexpectedError |
50 | 50 | * @return bool |
51 | 51 | */ |
52 | - public function insertBatch( array $constraints ) { |
|
52 | + public function insertBatch(array $constraints) { |
|
53 | 53 | $accumulator = array_map( |
54 | - function ( Constraint $constraint ) { |
|
54 | + function(Constraint $constraint) { |
|
55 | 55 | return [ |
56 | 56 | 'constraint_guid' => $constraint->getConstraintId(), |
57 | 57 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
58 | 58 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
59 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
59 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
60 | 60 | ]; |
61 | 61 | }, |
62 | 62 | $constraints |
63 | 63 | ); |
64 | 64 | |
65 | - $db = wfGetDB( DB_MASTER ); |
|
66 | - return $db->insert( 'wbqc_constraints', $accumulator ); |
|
65 | + $db = wfGetDB(DB_MASTER); |
|
66 | + return $db->insert('wbqc_constraints', $accumulator); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string[] |
73 | 73 | */ |
74 | - private function uuidPattern( LikeMatch $any ) { |
|
74 | + private function uuidPattern(LikeMatch $any) { |
|
75 | 75 | return array_merge( |
76 | - array_fill( 0, 8, $any ), [ '-' ], |
|
77 | - array_fill( 0, 4, $any ), [ '-' ], |
|
78 | - array_fill( 0, 4, $any ), [ '-' ], |
|
79 | - array_fill( 0, 4, $any ), [ '-' ], |
|
80 | - array_fill( 0, 12, $any ) |
|
76 | + array_fill(0, 8, $any), ['-'], |
|
77 | + array_fill(0, 4, $any), ['-'], |
|
78 | + array_fill(0, 4, $any), ['-'], |
|
79 | + array_fill(0, 4, $any), ['-'], |
|
80 | + array_fill(0, 12, $any) |
|
81 | 81 | ); |
82 | 82 | } |
83 | 83 | |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | * @throws DBUnexpectedError |
89 | 89 | */ |
90 | 90 | public function deleteWhereConstraintIdIsUuid() { |
91 | - $db = wfGetDB( DB_MASTER ); |
|
91 | + $db = wfGetDB(DB_MASTER); |
|
92 | 92 | $db->delete( |
93 | 93 | 'wbqc_constraints', |
94 | 94 | // WHERE constraint_guid LIKE ________-____-____-____-____________ |
95 | - 'constraint_guid ' . $db->buildLike( $this->uuidPattern( $db->anyChar() ) ) |
|
95 | + 'constraint_guid '.$db->buildLike($this->uuidPattern($db->anyChar())) |
|
96 | 96 | ); |
97 | 97 | } |
98 | 98 | |
@@ -104,14 +104,14 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @throws DBUnexpectedError |
106 | 106 | */ |
107 | - public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) { |
|
108 | - $db = wfGetDB( DB_MASTER ); |
|
107 | + public function deleteForPropertyWhereConstraintIdIsStatementId(PropertyId $propertyId) { |
|
108 | + $db = wfGetDB(DB_MASTER); |
|
109 | 109 | $db->delete( |
110 | 110 | 'wbqc_constraints', |
111 | 111 | [ |
112 | 112 | 'pid' => $propertyId->getNumericId(), |
113 | 113 | // AND constraint_guid LIKE %$________-____-____-____-____________ |
114 | - 'constraint_guid ' . $db->buildLike( array_merge( [ $db->anyString(), '$' ], $this->uuidPattern( $db->anyChar() ) ) ) |
|
114 | + 'constraint_guid '.$db->buildLike(array_merge([$db->anyString(), '$'], $this->uuidPattern($db->anyChar()))) |
|
115 | 115 | ] |
116 | 116 | ); |
117 | 117 | } |
@@ -122,21 +122,21 @@ discard block |
||
122 | 122 | * @throws InvalidArgumentException |
123 | 123 | * @throws DBUnexpectedError |
124 | 124 | */ |
125 | - public function deleteAll( $batchSize = 1000 ) { |
|
126 | - if ( !is_int( $batchSize ) ) { |
|
125 | + public function deleteAll($batchSize = 1000) { |
|
126 | + if (!is_int($batchSize)) { |
|
127 | 127 | throw new InvalidArgumentException(); |
128 | 128 | } |
129 | 129 | $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); |
130 | - $db = $lbFactory->getMainLB()->getConnection( DB_MASTER ); |
|
131 | - if ( $db->getType() === 'sqlite' ) { |
|
132 | - $db->delete( 'wbqc_constraints', '*' ); |
|
130 | + $db = $lbFactory->getMainLB()->getConnection(DB_MASTER); |
|
131 | + if ($db->getType() === 'sqlite') { |
|
132 | + $db->delete('wbqc_constraints', '*'); |
|
133 | 133 | } else { |
134 | 134 | do { |
135 | - $db->commit( __METHOD__, 'flush' ); |
|
135 | + $db->commit(__METHOD__, 'flush'); |
|
136 | 136 | $lbFactory->waitForReplication(); |
137 | - $table = $db->tableName( 'wbqc_constraints' ); |
|
138 | - $db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) ); |
|
139 | - } while ( $db->affectedRows() > 0 ); |
|
137 | + $table = $db->tableName('wbqc_constraints'); |
|
138 | + $db->query(sprintf('DELETE FROM %s LIMIT %d', $table, $batchSize)); |
|
139 | + } while ($db->affectedRows() > 0); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
@@ -145,26 +145,26 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return Constraint[] |
147 | 147 | */ |
148 | - private function convertToConstraints( IResultWrapper $results ) { |
|
148 | + private function convertToConstraints(IResultWrapper $results) { |
|
149 | 149 | $constraints = []; |
150 | - foreach ( $results as $result ) { |
|
150 | + foreach ($results as $result) { |
|
151 | 151 | $constraintTypeItemId = $result->constraint_type_qid; |
152 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
152 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
153 | 153 | |
154 | - if ( $constraintParameters === null ) { |
|
154 | + if ($constraintParameters === null) { |
|
155 | 155 | // T171295 |
156 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ) |
|
157 | - ->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
156 | + LoggerFactory::getInstance('WikibaseQualityConstraints') |
|
157 | + ->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
158 | 158 | 'method' => __METHOD__, |
159 | 159 | 'constraintId' => $result->constraint_guid, |
160 | 160 | 'constraintParameters' => $result->constraint_parameters, |
161 | - ] ); |
|
162 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
161 | + ]); |
|
162 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | $constraints[] = new Constraint( |
166 | 166 | $result->constraint_guid, |
167 | - PropertyId::newFromNumber( $result->pid ), |
|
167 | + PropertyId::newFromNumber($result->pid), |
|
168 | 168 | $constraintTypeItemId, |
169 | 169 | $constraintParameters |
170 | 170 | ); |
@@ -71,20 +71,20 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string HTML |
73 | 73 | */ |
74 | - public function formatValue( $value ) { |
|
75 | - if ( is_string( $value ) ) { |
|
74 | + public function formatValue($value) { |
|
75 | + if (is_string($value)) { |
|
76 | 76 | // Cases like 'Format' 'pattern' or 'minimum'/'maximum' values, which we have stored as |
77 | 77 | // strings |
78 | - return htmlspecialchars( $value ); |
|
79 | - } elseif ( $value instanceof EntityId ) { |
|
78 | + return htmlspecialchars($value); |
|
79 | + } elseif ($value instanceof EntityId) { |
|
80 | 80 | // Cases like 'Conflicts with' 'property', to which we can link |
81 | - return $this->formatEntityId( $value ); |
|
82 | - } elseif ( $value instanceof ItemIdSnakValue ) { |
|
81 | + return $this->formatEntityId($value); |
|
82 | + } elseif ($value instanceof ItemIdSnakValue) { |
|
83 | 83 | // Cases like EntityId but can also be somevalue or novalue |
84 | - return $this->formatItemIdSnakValue( $value ); |
|
84 | + return $this->formatItemIdSnakValue($value); |
|
85 | 85 | } else { |
86 | 86 | // Cases where we format a DataValue |
87 | - return $this->formatDataValue( $value ); |
|
87 | + return $this->formatDataValue($value); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -95,23 +95,23 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return string HTML |
97 | 97 | */ |
98 | - public function formatParameters( $parameters ) { |
|
99 | - if ( $parameters === null || $parameters === [] ) { |
|
98 | + public function formatParameters($parameters) { |
|
99 | + if ($parameters === null || $parameters === []) { |
|
100 | 100 | return null; |
101 | 101 | } |
102 | 102 | |
103 | - $valueFormatter = function ( $value ) { |
|
104 | - return $this->formatValue( $value ); |
|
103 | + $valueFormatter = function($value) { |
|
104 | + return $this->formatValue($value); |
|
105 | 105 | }; |
106 | 106 | |
107 | 107 | $formattedParameters = []; |
108 | - foreach ( $parameters as $parameterName => $parameterValue ) { |
|
109 | - $formattedParameterValues = implode( ', ', |
|
110 | - $this->limitArrayLength( array_map( $valueFormatter, $parameterValue ) ) ); |
|
111 | - $formattedParameters[] = sprintf( '%s: %s', $parameterName, $formattedParameterValues ); |
|
108 | + foreach ($parameters as $parameterName => $parameterValue) { |
|
109 | + $formattedParameterValues = implode(', ', |
|
110 | + $this->limitArrayLength(array_map($valueFormatter, $parameterValue))); |
|
111 | + $formattedParameters[] = sprintf('%s: %s', $parameterName, $formattedParameterValues); |
|
112 | 112 | } |
113 | 113 | |
114 | - return implode( '; ', $formattedParameters ); |
|
114 | + return implode('; ', $formattedParameters); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -121,10 +121,10 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @return string[] |
123 | 123 | */ |
124 | - private function limitArrayLength( array $array ) { |
|
125 | - if ( count( $array ) > self::MAX_PARAMETER_ARRAY_LENGTH ) { |
|
126 | - $array = array_slice( $array, 0, self::MAX_PARAMETER_ARRAY_LENGTH ); |
|
127 | - array_push( $array, '...' ); |
|
124 | + private function limitArrayLength(array $array) { |
|
125 | + if (count($array) > self::MAX_PARAMETER_ARRAY_LENGTH) { |
|
126 | + $array = array_slice($array, 0, self::MAX_PARAMETER_ARRAY_LENGTH); |
|
127 | + array_push($array, '...'); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | return $array; |
@@ -134,16 +134,16 @@ discard block |
||
134 | 134 | * @param DataValue $value |
135 | 135 | * @return string HTML |
136 | 136 | */ |
137 | - public function formatDataValue( DataValue $value ) { |
|
138 | - return $this->dataValueFormatter->format( $value ); |
|
137 | + public function formatDataValue(DataValue $value) { |
|
138 | + return $this->dataValueFormatter->format($value); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
142 | 142 | * @param EntityId $entityId |
143 | 143 | * @return string HTML |
144 | 144 | */ |
145 | - public function formatEntityId( EntityId $entityId ) { |
|
146 | - return $this->entityIdLabelFormatter->formatEntityId( $entityId ); |
|
145 | + public function formatEntityId(EntityId $entityId) { |
|
146 | + return $this->entityIdLabelFormatter->formatEntityId($entityId); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -152,17 +152,17 @@ discard block |
||
152 | 152 | * @param ItemIdSnakValue $value |
153 | 153 | * @return string HTML |
154 | 154 | */ |
155 | - public function formatItemIdSnakValue( ItemIdSnakValue $value ) { |
|
156 | - switch ( true ) { |
|
155 | + public function formatItemIdSnakValue(ItemIdSnakValue $value) { |
|
156 | + switch (true) { |
|
157 | 157 | case $value->isValue(): |
158 | - return $this->formatEntityId( $value->getItemId() ); |
|
158 | + return $this->formatEntityId($value->getItemId()); |
|
159 | 159 | case $value->isSomeValue(): |
160 | 160 | return $this->messageLocalizer |
161 | - ->msg( 'wikibase-snakview-snaktypeselector-somevalue' ) |
|
161 | + ->msg('wikibase-snakview-snaktypeselector-somevalue') |
|
162 | 162 | ->escaped(); |
163 | 163 | case $value->isNoValue(): |
164 | 164 | return $this->messageLocalizer |
165 | - ->msg( 'wikibase-snakview-snaktypeselector-novalue' ) |
|
165 | + ->msg('wikibase-snakview-snaktypeselector-novalue') |
|
166 | 166 | ->escaped(); |
167 | 167 | } |
168 | 168 | } |
@@ -74,20 +74,20 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return self |
76 | 76 | */ |
77 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
77 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
78 | 78 | $constraintReportFactory = ConstraintReportFactory::getDefaultInstance(); |
79 | 79 | $repo = WikibaseRepo::getDefaultInstance(); |
80 | - $helperFactory = $repo->getApiHelperFactory( RequestContext::getMain() ); |
|
80 | + $helperFactory = $repo->getApiHelperFactory(RequestContext::getMain()); |
|
81 | 81 | $language = $repo->getUserLanguage(); |
82 | 82 | |
83 | 83 | $languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory(); |
84 | - $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language ); |
|
84 | + $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language); |
|
85 | 85 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
86 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
86 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
87 | 87 | $formatterOptions = new FormatterOptions(); |
88 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
88 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
89 | 89 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
90 | - $dataValueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
90 | + $dataValueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
91 | 91 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
92 | 92 | $violationMessageRenderer = new MultilingualTextViolationMessageRenderer( |
93 | 93 | $entityIdHtmlLinkFormatter, |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | StatementGuidParser $statementGuidParser, |
128 | 128 | IBufferingStatsdDataFactory $dataFactory |
129 | 129 | ) { |
130 | - parent::__construct( $main, $name, $prefix ); |
|
130 | + parent::__construct($main, $name, $prefix); |
|
131 | 131 | |
132 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
132 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
133 | 133 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
134 | 134 | $this->violationMessageRenderer = $violationMessageRenderer; |
135 | 135 | $this->statementGuidParser = $statementGuidParser; |
@@ -144,39 +144,39 @@ discard block |
||
144 | 144 | $params = $this->extractRequestParams(); |
145 | 145 | $result = $this->getResult(); |
146 | 146 | |
147 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
148 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
147 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
148 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
149 | 149 | |
150 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
151 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
150 | + $this->checkPropertyIds($propertyIds, $result); |
|
151 | + $this->checkConstraintIds($constraintIds, $result); |
|
152 | 152 | |
153 | - $result->addValue( null, 'success', 1 ); |
|
153 | + $result->addValue(null, 'success', 1); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
157 | 157 | * @param array|null $propertyIdSerializations |
158 | 158 | * @return PropertyId[] |
159 | 159 | */ |
160 | - private function parsePropertyIds( $propertyIdSerializations ) { |
|
161 | - if ( $propertyIdSerializations === null ) { |
|
160 | + private function parsePropertyIds($propertyIdSerializations) { |
|
161 | + if ($propertyIdSerializations === null) { |
|
162 | 162 | return []; |
163 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
163 | + } elseif (empty($propertyIdSerializations)) { |
|
164 | 164 | $this->apiErrorReporter->dieError( |
165 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
165 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
166 | 166 | 'no-data' |
167 | 167 | ); |
168 | 168 | } |
169 | 169 | |
170 | 170 | return array_map( |
171 | - function( $propertyIdSerialization ) { |
|
171 | + function($propertyIdSerialization) { |
|
172 | 172 | try { |
173 | - return new PropertyId( $propertyIdSerialization ); |
|
174 | - } catch ( InvalidArgumentException $e ) { |
|
173 | + return new PropertyId($propertyIdSerialization); |
|
174 | + } catch (InvalidArgumentException $e) { |
|
175 | 175 | $this->apiErrorReporter->dieError( |
176 | 176 | "Invalid id: $propertyIdSerialization", |
177 | 177 | 'invalid-property-id', |
178 | 178 | 0, // default argument |
179 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
179 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
180 | 180 | ); |
181 | 181 | } |
182 | 182 | }, |
@@ -188,35 +188,35 @@ discard block |
||
188 | 188 | * @param array|null $constraintIds |
189 | 189 | * @return string[] |
190 | 190 | */ |
191 | - private function parseConstraintIds( $constraintIds ) { |
|
192 | - if ( $constraintIds === null ) { |
|
191 | + private function parseConstraintIds($constraintIds) { |
|
192 | + if ($constraintIds === null) { |
|
193 | 193 | return []; |
194 | - } elseif ( empty( $constraintIds ) ) { |
|
194 | + } elseif (empty($constraintIds)) { |
|
195 | 195 | $this->apiErrorReporter->dieError( |
196 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
196 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
197 | 197 | 'no-data' |
198 | 198 | ); |
199 | 199 | } |
200 | 200 | |
201 | 201 | return array_map( |
202 | - function( $constraintId ) { |
|
202 | + function($constraintId) { |
|
203 | 203 | try { |
204 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
205 | - if ( !$propertyId instanceof PropertyId ) { |
|
204 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
205 | + if (!$propertyId instanceof PropertyId) { |
|
206 | 206 | $this->apiErrorReporter->dieError( |
207 | 207 | "Invalid property ID: {$propertyId->getSerialization()}", |
208 | 208 | 'invalid-property-id', |
209 | 209 | 0, // default argument |
210 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
210 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
211 | 211 | ); |
212 | 212 | } |
213 | 213 | return $constraintId; |
214 | - } catch ( StatementGuidParsingException $e ) { |
|
214 | + } catch (StatementGuidParsingException $e) { |
|
215 | 215 | $this->apiErrorReporter->dieError( |
216 | 216 | "Invalid statement GUID: $constraintId", |
217 | 217 | 'invalid-guid', |
218 | 218 | 0, // default argument |
219 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
219 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
220 | 220 | ); |
221 | 221 | } |
222 | 222 | }, |
@@ -228,12 +228,12 @@ discard block |
||
228 | 228 | * @param PropertyId[] $propertyIds |
229 | 229 | * @param ApiResult $result |
230 | 230 | */ |
231 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ) { |
|
232 | - foreach ( $propertyIds as $propertyId ) { |
|
233 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
234 | - $allConstraintExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnPropertyId( $propertyId ); |
|
235 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
236 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
231 | + private function checkPropertyIds(array $propertyIds, ApiResult $result) { |
|
232 | + foreach ($propertyIds as $propertyId) { |
|
233 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
234 | + $allConstraintExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnPropertyId($propertyId); |
|
235 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
236 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | } |
@@ -242,14 +242,14 @@ discard block |
||
242 | 242 | * @param string[] $constraintIds |
243 | 243 | * @param ApiResult $result |
244 | 244 | */ |
245 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ) { |
|
246 | - foreach ( $constraintIds as $constraintId ) { |
|
247 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
245 | + private function checkConstraintIds(array $constraintIds, ApiResult $result) { |
|
246 | + foreach ($constraintIds as $constraintId) { |
|
247 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
248 | 248 | // already checked as part of checkPropertyIds() |
249 | 249 | continue; |
250 | 250 | } |
251 | - $constraintParameterExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnConstraintId( $constraintId ); |
|
252 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
251 | + $constraintParameterExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnConstraintId($constraintId); |
|
252 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
@@ -257,17 +257,17 @@ discard block |
||
257 | 257 | * @param PropertyId $propertyId |
258 | 258 | * @return string[] |
259 | 259 | */ |
260 | - private function getResultPathForPropertyId( PropertyId $propertyId ) { |
|
261 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
260 | + private function getResultPathForPropertyId(PropertyId $propertyId) { |
|
261 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
265 | 265 | * @param string $constraintId |
266 | 266 | * @return string[] |
267 | 267 | */ |
268 | - private function getResultPathForConstraintId( $constraintId ) { |
|
269 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
270 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
268 | + private function getResultPathForConstraintId($constraintId) { |
|
269 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
270 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | * @param ConstraintParameterException[]|null $constraintParameterExceptions |
278 | 278 | * @param ApiResult $result |
279 | 279 | */ |
280 | - private function addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, ApiResult $result ) { |
|
281 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
282 | - if ( $constraintParameterExceptions === null ) { |
|
280 | + private function addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, ApiResult $result) { |
|
281 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
282 | + if ($constraintParameterExceptions === null) { |
|
283 | 283 | $result->addValue( |
284 | 284 | $path, |
285 | 285 | self::KEY_STATUS, |
@@ -289,12 +289,12 @@ discard block |
||
289 | 289 | $result->addValue( |
290 | 290 | $path, |
291 | 291 | self::KEY_STATUS, |
292 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
292 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
293 | 293 | ); |
294 | 294 | $result->addValue( |
295 | 295 | $path, |
296 | 296 | self::KEY_PROBLEMS, |
297 | - array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions ) |
|
297 | + array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions) |
|
298 | 298 | ); |
299 | 299 | } |
300 | 300 | } |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | * @param ConstraintParameterException $e |
306 | 306 | * @return string[] |
307 | 307 | */ |
308 | - private function formatConstraintParameterException( ConstraintParameterException $e ) { |
|
308 | + private function formatConstraintParameterException(ConstraintParameterException $e) { |
|
309 | 309 | return [ |
310 | 310 | self::KEY_MESSAGE_HTML => $this->violationMessageRenderer->render( |
311 | 311 | $e->getViolationMessage() |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @codeCoverageIgnore This method is not supported. |
36 | 36 | */ |
37 | 37 | public function getType() { |
38 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
38 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | public function getEntityId() { |
@@ -46,35 +46,35 @@ discard block |
||
46 | 46 | * @codeCoverageIgnore This method is not supported. |
47 | 47 | */ |
48 | 48 | public function getStatementPropertyId() { |
49 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
49 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @codeCoverageIgnore This method is not supported. |
54 | 54 | */ |
55 | 55 | public function getStatementGuid() { |
56 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
56 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
60 | 60 | * @codeCoverageIgnore This method is not supported. |
61 | 61 | */ |
62 | 62 | public function getSnakPropertyId() { |
63 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
63 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @codeCoverageIgnore This method is not supported. |
68 | 68 | */ |
69 | 69 | public function getSnakHash() { |
70 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
70 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | 74 | * @codeCoverageIgnore This method is not supported. |
75 | 75 | */ |
76 | - public function &getMainArray( array &$container ) { |
|
77 | - throw new LogicException( 'EntityContextCursor cannot store check results' ); |
|
76 | + public function &getMainArray(array &$container) { |
|
77 | + throw new LogicException('EntityContextCursor cannot store check results'); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -83,14 +83,14 @@ discard block |
||
83 | 83 | * @param array|null $result must be null |
84 | 84 | * @param array[] &$container |
85 | 85 | */ |
86 | - public function storeCheckResultInArray( array $result = null, array &$container ) { |
|
87 | - if ( $result !== null ) { |
|
88 | - throw new LogicException( 'EntityContextCursor cannot store check results' ); |
|
86 | + public function storeCheckResultInArray(array $result = null, array &$container) { |
|
87 | + if ($result !== null) { |
|
88 | + throw new LogicException('EntityContextCursor cannot store check results'); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // this ensures that the claims array is present in the $container, |
92 | 92 | // populating it if necessary, even though we ignore the return value |
93 | - $this->getClaimsArray( $container ); |
|
93 | + $this->getClaimsArray($container); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | } |
@@ -9,10 +9,10 @@ discard block |
||
9 | 9 | use Wikibase\Repo\WikibaseRepo; |
10 | 10 | |
11 | 11 | // @codeCoverageIgnoreStart |
12 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
13 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
12 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
13 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
14 | 14 | |
15 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
15 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
16 | 16 | // @codeCoverageIgnoreEnd |
17 | 17 | |
18 | 18 | /** |
@@ -38,39 +38,39 @@ discard block |
||
38 | 38 | |
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | - $this->newUpdateConstraintsTableJob = function ( $propertyIdSerialization ) { |
|
41 | + $this->newUpdateConstraintsTableJob = function($propertyIdSerialization) { |
|
42 | 42 | return UpdateConstraintsTableJob::newFromGlobalState( |
43 | 43 | Title::newMainPage(), |
44 | - [ 'propertyId' => $propertyIdSerialization ] |
|
44 | + ['propertyId' => $propertyIdSerialization] |
|
45 | 45 | ); |
46 | 46 | }; |
47 | 47 | |
48 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
49 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
48 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
49 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
50 | 50 | |
51 | 51 | // Wikibase classes are not yet loaded, so setup services in a callback run in execute |
52 | 52 | // that can be overridden in tests. |
53 | - $this->setupServices = function () { |
|
53 | + $this->setupServices = function() { |
|
54 | 54 | $repo = WikibaseRepo::getDefaultInstance(); |
55 | 55 | $this->propertyInfoLookup = $repo->getStore()->getPropertyInfoLookup(); |
56 | 56 | }; |
57 | 57 | } |
58 | 58 | |
59 | 59 | public function execute() { |
60 | - ( $this->setupServices )(); |
|
61 | - if ( !$this->getConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
62 | - $this->error( 'Constraint statements are not enabled. Aborting.' ); |
|
60 | + ($this->setupServices)(); |
|
61 | + if (!$this->getConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
62 | + $this->error('Constraint statements are not enabled. Aborting.'); |
|
63 | 63 | return; |
64 | 64 | } |
65 | 65 | |
66 | - foreach ( $this->propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info ) { |
|
67 | - $this->output( sprintf( 'Importing constraint statements for % 6s... ', $propertyIdSerialization ), $propertyIdSerialization ); |
|
68 | - $startTime = microtime( true ); |
|
69 | - $job = call_user_func( $this->newUpdateConstraintsTableJob, $propertyIdSerialization ); |
|
66 | + foreach ($this->propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info) { |
|
67 | + $this->output(sprintf('Importing constraint statements for % 6s... ', $propertyIdSerialization), $propertyIdSerialization); |
|
68 | + $startTime = microtime(true); |
|
69 | + $job = call_user_func($this->newUpdateConstraintsTableJob, $propertyIdSerialization); |
|
70 | 70 | $job->run(); |
71 | - $endTime = microtime( true ); |
|
72 | - $millis = ( $endTime - $startTime ) * 1000; |
|
73 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
71 | + $endTime = microtime(true); |
|
72 | + $millis = ($endTime - $startTime) * 1000; |
|
73 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 |
@@ -80,23 +80,23 @@ discard block |
||
80 | 80 | * @return bool |
81 | 81 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
82 | 82 | */ |
83 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
84 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
83 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
84 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
85 | 85 | if ( ++$entitiesChecked > $maxEntities ) { |
86 | - throw new OverflowException( 'Too many entities to check' ); |
|
86 | + throw new OverflowException('Too many entities to check'); |
|
87 | 87 | } |
88 | 88 | |
89 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
90 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
89 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
90 | + if (!($item instanceof StatementListProvider)) { |
|
91 | 91 | return false; // lookup failed, probably because item doesn't exist |
92 | 92 | } |
93 | 93 | |
94 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
94 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
95 | 95 | /** @var Statement $statement */ |
96 | - foreach ( $item->getStatements()->getByPropertyId( new PropertyId( $subclassId ) ) as $statement ) { |
|
96 | + foreach ($item->getStatements()->getByPropertyId(new PropertyId($subclassId)) as $statement) { |
|
97 | 97 | $mainSnak = $statement->getMainSnak(); |
98 | 98 | |
99 | - if ( !( $this->hasCorrectType( $mainSnak ) ) ) { |
|
99 | + if (!($this->hasCorrectType($mainSnak))) { |
|
100 | 100 | continue; |
101 | 101 | } |
102 | 102 | /** @var PropertyValueSnak $mainSnak */ |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | $dataValue = $mainSnak->getDataValue(); |
106 | 106 | $comparativeClass = $dataValue->getEntityId(); |
107 | 107 | |
108 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
108 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
109 | 109 | return true; |
110 | 110 | } |
111 | 111 | |
112 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
112 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
113 | 113 | return true; |
114 | 114 | } |
115 | 115 | } |
@@ -130,14 +130,14 @@ discard block |
||
130 | 130 | * @return CachedBool |
131 | 131 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
132 | 132 | */ |
133 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
133 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
134 | 134 | try { |
135 | 135 | return new CachedBool( |
136 | - $this->isSubclassOf( $comparativeClass, $classesToCheck ), |
|
136 | + $this->isSubclassOf($comparativeClass, $classesToCheck), |
|
137 | 137 | Metadata::blank() |
138 | 138 | ); |
139 | - } catch ( OverflowException $e ) { |
|
140 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
139 | + } catch (OverflowException $e) { |
|
140 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
141 | 141 | $this->dataFactory->increment( |
142 | 142 | 'wikibase.quality.constraints.sparql.typeFallback' |
143 | 143 | ); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | /* withInstance = */ false |
148 | 148 | ); |
149 | 149 | } else { |
150 | - return new CachedBool( false, Metadata::blank() ); |
|
150 | + return new CachedBool(false, Metadata::blank()); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
@@ -165,13 +165,13 @@ discard block |
||
165 | 165 | * @return CachedBool |
166 | 166 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
167 | 167 | */ |
168 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
168 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
169 | 169 | $metadatas = []; |
170 | 170 | |
171 | - foreach ( $this->getStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
171 | + foreach ($this->getStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
172 | 172 | $mainSnak = $statement->getMainSnak(); |
173 | 173 | |
174 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
174 | + if (!$this->hasCorrectType($mainSnak)) { |
|
175 | 175 | continue; |
176 | 176 | } |
177 | 177 | /** @var PropertyValueSnak $mainSnak */ |
@@ -180,28 +180,28 @@ discard block |
||
180 | 180 | $dataValue = $mainSnak->getDataValue(); |
181 | 181 | $comparativeClass = $dataValue->getEntityId(); |
182 | 182 | |
183 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
183 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
184 | 184 | // discard $metadatas, we know this is fresh |
185 | - return new CachedBool( true, Metadata::blank() ); |
|
185 | + return new CachedBool(true, Metadata::blank()); |
|
186 | 186 | } |
187 | 187 | |
188 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
188 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
189 | 189 | $metadatas[] = $result->getMetadata(); |
190 | - if ( $result->getBool() ) { |
|
190 | + if ($result->getBool()) { |
|
191 | 191 | return new CachedBool( |
192 | 192 | true, |
193 | - Metadata::merge( $metadatas ) |
|
193 | + Metadata::merge($metadatas) |
|
194 | 194 | ); |
195 | 195 | } |
196 | 196 | } |
197 | 197 | |
198 | 198 | return new CachedBool( |
199 | 199 | false, |
200 | - Metadata::merge( $metadatas ) |
|
200 | + Metadata::merge($metadatas) |
|
201 | 201 | ); |
202 | 202 | } |
203 | 203 | |
204 | - private function hasCorrectType( Snak $mainSnak ) { |
|
204 | + private function hasCorrectType(Snak $mainSnak) { |
|
205 | 205 | return $mainSnak instanceof PropertyValueSnak |
206 | 206 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
207 | 207 | } |
@@ -218,12 +218,12 @@ discard block |
||
218 | 218 | ) { |
219 | 219 | $statementArrays = []; |
220 | 220 | |
221 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
222 | - $propertyId = new PropertyId( $propertyIdSerialization ); |
|
223 | - $statementArrays[] = $statements->getByPropertyId( $propertyId )->toArray(); |
|
221 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
222 | + $propertyId = new PropertyId($propertyIdSerialization); |
|
223 | + $statementArrays[] = $statements->getByPropertyId($propertyId)->toArray(); |
|
224 | 224 | } |
225 | 225 | |
226 | - return call_user_func_array( 'array_merge', $statementArrays ); |
|
226 | + return call_user_func_array('array_merge', $statementArrays); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -235,10 +235,10 @@ discard block |
||
235 | 235 | * |
236 | 236 | * @return ViolationMessage |
237 | 237 | */ |
238 | - public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) { |
|
238 | + public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) { |
|
239 | 239 | $classes = array_map( |
240 | - function( $itemIdSerialization ) { |
|
241 | - return new ItemId( $itemIdSerialization ); |
|
240 | + function($itemIdSerialization) { |
|
241 | + return new ItemId($itemIdSerialization); |
|
242 | 242 | }, |
243 | 243 | $classes |
244 | 244 | ); |
@@ -250,10 +250,10 @@ discard block |
||
250 | 250 | // wbqc-violation-message-valueType-instance |
251 | 251 | // wbqc-violation-message-valueType-subclass |
252 | 252 | // wbqc-violation-message-valueType-instanceOrSubclass |
253 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
254 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
255 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
256 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
253 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
254 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
255 | + ->withEntityId($entityId, Role::SUBJECT) |
|
256 | + ->withEntityIdList($classes, Role::OBJECT); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | } |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | // no parent::__construct() call |
23 | 23 | } |
24 | 24 | |
25 | - public function hasType( $id, array $classes, $withInstance ) { |
|
26 | - throw new LogicException( 'methods of this class should never be called' ); |
|
25 | + public function hasType($id, array $classes, $withInstance) { |
|
26 | + throw new LogicException('methods of this class should never be called'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public function findEntitiesWithSameStatement( |
30 | 30 | Statement $statement, |
31 | 31 | $ignoreDeprecatedStatements |
32 | 32 | ) { |
33 | - throw new LogicException( 'methods of this class should never be called' ); |
|
33 | + throw new LogicException('methods of this class should never be called'); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | public function findEntitiesWithSameQualifierOrReference( |
@@ -39,15 +39,15 @@ discard block |
||
39 | 39 | $type, |
40 | 40 | $ignoreDeprecatedStatements |
41 | 41 | ) { |
42 | - throw new LogicException( 'methods of this class should never be called' ); |
|
42 | + throw new LogicException('methods of this class should never be called'); |
|
43 | 43 | } |
44 | 44 | |
45 | - public function matchesRegularExpression( $text, $regex ) { |
|
46 | - throw new LogicException( 'methods of this class should never be called' ); |
|
45 | + public function matchesRegularExpression($text, $regex) { |
|
46 | + throw new LogicException('methods of this class should never be called'); |
|
47 | 47 | } |
48 | 48 | |
49 | - public function runQuery( $query ) { |
|
50 | - throw new LogicException( 'methods of this class should never be called' ); |
|
49 | + public function runQuery($query) { |
|
50 | + throw new LogicException('methods of this class should never be called'); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | } |
@@ -64,22 +64,22 @@ discard block |
||
64 | 64 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
65 | 65 | * @return CheckResult |
66 | 66 | */ |
67 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
68 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
69 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
67 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
68 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
69 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $parameters = []; |
73 | 73 | |
74 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
75 | - if ( $context->getType() === 'statement' ) { |
|
74 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
75 | + if ($context->getType() === 'statement') { |
|
76 | 76 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
77 | 77 | $context->getSnakStatement(), |
78 | 78 | true // ignore deprecated statements |
79 | 79 | ); |
80 | 80 | } else { |
81 | - if ( $context->getSnak()->getType() !== 'value' ) { |
|
82 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
81 | + if ($context->getSnak()->getType() !== 'value') { |
|
82 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
83 | 83 | } |
84 | 84 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
85 | 85 | $context->getEntity()->getId(), |
@@ -92,27 +92,27 @@ discard block |
||
92 | 92 | $otherEntities = $result->getArray(); |
93 | 93 | $metadata = $result->getMetadata(); |
94 | 94 | |
95 | - if ( $otherEntities === [] ) { |
|
95 | + if ($otherEntities === []) { |
|
96 | 96 | $status = CheckResult::STATUS_COMPLIANCE; |
97 | 97 | $message = null; |
98 | 98 | } else { |
99 | - $otherEntities = array_values( array_filter( $otherEntities ) ); // remove nulls |
|
99 | + $otherEntities = array_values(array_filter($otherEntities)); // remove nulls |
|
100 | 100 | $status = CheckResult::STATUS_VIOLATION; |
101 | - $message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) ) |
|
102 | - ->withEntityIdList( $otherEntities, Role::SUBJECT ); |
|
101 | + $message = (new ViolationMessage('wbqc-violation-message-unique-value')) |
|
102 | + ->withEntityIdList($otherEntities, Role::SUBJECT); |
|
103 | 103 | } |
104 | 104 | } else { |
105 | 105 | $status = CheckResult::STATUS_TODO; |
106 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
107 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
106 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
107 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
108 | 108 | $metadata = Metadata::blank(); |
109 | 109 | } |
110 | 110 | |
111 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
112 | - ->withMetadata( $metadata ); |
|
111 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
112 | + ->withMetadata($metadata); |
|
113 | 113 | } |
114 | 114 | |
115 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
115 | + public function checkConstraintParameters(Constraint $constraint) { |
|
116 | 116 | // no parameters |
117 | 117 | return []; |
118 | 118 | } |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | * @throws ConstraintParameterException |
86 | 86 | * @return CheckResult |
87 | 87 | */ |
88 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
88 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
89 | 89 | $parameters = []; |
90 | 90 | $constraintParameters = $constraint->getConstraintParameters(); |
91 | 91 | |
92 | - $format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
93 | - $parameters['pattern'] = [ $format ]; |
|
92 | + $format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
93 | + $parameters['pattern'] = [$format]; |
|
94 | 94 | |
95 | 95 | $syntaxClarifications = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
96 | 96 | $constraintParameters |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | |
99 | 99 | $snak = $context->getSnak(); |
100 | 100 | |
101 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
101 | + if (!$snak instanceof PropertyValueSnak) { |
|
102 | 102 | // nothing to check |
103 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
103 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | $dataValue = $snak->getDataValue(); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * error handling: |
110 | 110 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
111 | 111 | */ |
112 | - switch ( $dataValue->getType() ) { |
|
112 | + switch ($dataValue->getType()) { |
|
113 | 113 | case 'string': |
114 | 114 | $text = $dataValue->getValue(); |
115 | 115 | break; |
@@ -118,49 +118,49 @@ discard block |
||
118 | 118 | $text = $dataValue->getText(); |
119 | 119 | break; |
120 | 120 | default: |
121 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) ) |
|
122 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
123 | - ->withDataValueType( 'string' ) |
|
124 | - ->withDataValueType( 'monolingualtext' ); |
|
125 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
121 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2')) |
|
122 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
123 | + ->withDataValueType('string') |
|
124 | + ->withDataValueType('monolingualtext'); |
|
125 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | if ( |
129 | - !( $this->sparqlHelper instanceof DummySparqlHelper ) && |
|
130 | - $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) |
|
129 | + !($this->sparqlHelper instanceof DummySparqlHelper) && |
|
130 | + $this->config->get('WBQualityConstraintsCheckFormatConstraint') |
|
131 | 131 | ) { |
132 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
132 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
133 | 133 | $message = null; |
134 | 134 | $status = CheckResult::STATUS_COMPLIANCE; |
135 | 135 | } else { |
136 | - $message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) ) |
|
137 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
138 | - ->withDataValue( new StringValue( $text ), Role::OBJECT ) |
|
139 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
140 | - ->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE ); |
|
136 | + $message = (new ViolationMessage('wbqc-violation-message-format-clarification')) |
|
137 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
138 | + ->withDataValue(new StringValue($text), Role::OBJECT) |
|
139 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
140 | + ->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE); |
|
141 | 141 | $status = CheckResult::STATUS_VIOLATION; |
142 | 142 | } |
143 | 143 | } else { |
144 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
145 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
144 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
145 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
146 | 146 | $status = CheckResult::STATUS_TODO; |
147 | 147 | } |
148 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
148 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
149 | 149 | } |
150 | 150 | |
151 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
151 | + public function checkConstraintParameters(Constraint $constraint) { |
|
152 | 152 | $constraintParameters = $constraint->getConstraintParameters(); |
153 | 153 | $exceptions = []; |
154 | 154 | try { |
155 | - $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
156 | - } catch ( ConstraintParameterException $e ) { |
|
155 | + $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
156 | + } catch (ConstraintParameterException $e) { |
|
157 | 157 | $exceptions[] = $e; |
158 | 158 | } |
159 | 159 | try { |
160 | 160 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
161 | 161 | $constraintParameters |
162 | 162 | ); |
163 | - } catch ( ConstraintParameterException $e ) { |
|
163 | + } catch (ConstraintParameterException $e) { |
|
164 | 164 | $exceptions[] = $e; |
165 | 165 | } |
166 | 166 | return $exceptions; |