@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | private $constraintParameterParser; |
24 | 24 | |
25 | - public function __construct( ConstraintParameterParser $constraintParameterParser ) { |
|
25 | + public function __construct(ConstraintParameterParser $constraintParameterParser) { |
|
26 | 26 | $this->constraintParameterParser = $constraintParameterParser; |
27 | 27 | } |
28 | 28 | |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * @throws ConstraintParameterException |
69 | 69 | * @return CheckResult |
70 | 70 | */ |
71 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
72 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
73 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
71 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
72 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
73 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | $parameters = []; |
@@ -83,26 +83,26 @@ discard block |
||
83 | 83 | $parameters['language'] = $languages; |
84 | 84 | |
85 | 85 | $status = CheckResult::STATUS_VIOLATION; |
86 | - $message = ( new ViolationMessage( 'wbqc-violation-message-label-lacking' ) ) |
|
87 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
88 | - ->withLanguages( $languages ); |
|
86 | + $message = (new ViolationMessage('wbqc-violation-message-label-lacking')) |
|
87 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
88 | + ->withLanguages($languages); |
|
89 | 89 | |
90 | 90 | /** @var LabelsProvider $entity */ |
91 | 91 | $entity = $context->getEntity(); |
92 | 92 | '@phan-var LabelsProvider $entity'; |
93 | 93 | |
94 | - foreach ( $languages as $language ) { |
|
95 | - if ( $entity->getLabels()->hasTermForLanguage( $language ) ) { |
|
94 | + foreach ($languages as $language) { |
|
95 | + if ($entity->getLabels()->hasTermForLanguage($language)) { |
|
96 | 96 | $message = null; |
97 | 97 | $status = CheckResult::STATUS_COMPLIANCE; |
98 | 98 | break; |
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
102 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
103 | 103 | } |
104 | 104 | |
105 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
105 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
106 | 106 | $constraintParameters = $constraint->getConstraintParameters(); |
107 | 107 | $exceptions = []; |
108 | 108 | try { |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $constraintParameters, |
111 | 111 | $constraint->getConstraintTypeItemId() |
112 | 112 | ); |
113 | - } catch ( ConstraintParameterException $e ) { |
|
113 | + } catch (ConstraintParameterException $e) { |
|
114 | 114 | $exceptions[] = $e; |
115 | 115 | } |
116 | 116 | return $exceptions; |
@@ -72,7 +72,7 @@ |
||
72 | 72 | * @return never |
73 | 73 | */ |
74 | 74 | private function __construct() { |
75 | - throw new LogicException( 'This class should never be instantiated.' ); |
|
75 | + throw new LogicException('This class should never be instantiated.'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | } |
@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | use WikiMap; |
19 | 19 | |
20 | 20 | // @codeCoverageIgnoreStart |
21 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
22 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
21 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
22 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
23 | 23 | |
24 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
24 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
25 | 25 | // @codeCoverageIgnoreEnd |
26 | 26 | |
27 | 27 | /** |
@@ -60,20 +60,20 @@ discard block |
||
60 | 60 | parent::__construct(); |
61 | 61 | |
62 | 62 | $this->addDescription( |
63 | - 'Import entities needed for constraint checks ' . |
|
63 | + 'Import entities needed for constraint checks '. |
|
64 | 64 | 'from Wikidata into the local repository.' |
65 | 65 | ); |
66 | 66 | $this->addOption( |
67 | 67 | 'config-format', |
68 | - 'The format in which the resulting configuration will be omitted: ' . |
|
69 | - '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' . |
|
68 | + 'The format in which the resulting configuration will be omitted: '. |
|
69 | + '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '. |
|
70 | 70 | 'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.' |
71 | 71 | ); |
72 | 72 | $this->addOption( |
73 | 73 | 'dry-run', |
74 | 74 | 'Don’t actually import entities, just print which ones would be imported.' |
75 | 75 | ); |
76 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
76 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | */ |
82 | 82 | private function setupServices() { |
83 | 83 | $services = MediaWikiServices::getInstance(); |
84 | - $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer( $services ); |
|
85 | - $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer( $services ); |
|
86 | - $this->entityStore = WikibaseRepo::getEntityStore( $services ); |
|
84 | + $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer($services); |
|
85 | + $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer($services); |
|
86 | + $this->entityStore = WikibaseRepo::getEntityStore($services); |
|
87 | 87 | $this->httpRequestFactory = $services->getHttpRequestFactory(); |
88 | - if ( !$this->getOption( 'dry-run', false ) ) { |
|
89 | - $this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' ); |
|
88 | + if (!$this->getOption('dry-run', false)) { |
|
89 | + $this->user = User::newSystemUser('WikibaseQualityConstraints importer'); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -95,21 +95,21 @@ discard block |
||
95 | 95 | |
96 | 96 | $configUpdates = []; |
97 | 97 | |
98 | - $extensionJsonFile = __DIR__ . '/../extension.json'; |
|
99 | - $extensionJsonText = file_get_contents( $extensionJsonFile ); |
|
100 | - $extensionJson = json_decode( $extensionJsonText, /* assoc = */ true ); |
|
98 | + $extensionJsonFile = __DIR__.'/../extension.json'; |
|
99 | + $extensionJsonText = file_get_contents($extensionJsonFile); |
|
100 | + $extensionJson = json_decode($extensionJsonText, /* assoc = */ true); |
|
101 | 101 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
102 | - $wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() ); |
|
102 | + $wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig()); |
|
103 | 103 | |
104 | - foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) { |
|
105 | - $localEntityId = $this->importEntityFromWikidata( $wikidataEntityId ); |
|
104 | + foreach ($wikidataEntityIds as $key => $wikidataEntityId) { |
|
105 | + $localEntityId = $this->importEntityFromWikidata($wikidataEntityId); |
|
106 | 106 | $configUpdates[$key] = [ |
107 | 107 | 'wikidata' => $wikidataEntityId, |
108 | 108 | 'local' => $localEntityId, |
109 | 109 | ]; |
110 | 110 | } |
111 | 111 | |
112 | - $this->outputConfigUpdates( $configUpdates ); |
|
112 | + $this->outputConfigUpdates($configUpdates); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | * @param Config $wikiConfig |
118 | 118 | * @return string[] |
119 | 119 | */ |
120 | - private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) { |
|
120 | + private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) { |
|
121 | 121 | $wikidataEntityIds = []; |
122 | 122 | |
123 | - foreach ( $extensionJsonConfig as $key => $value ) { |
|
124 | - if ( !preg_match( '/Id$/', $key ) ) { |
|
123 | + foreach ($extensionJsonConfig as $key => $value) { |
|
124 | + if (!preg_match('/Id$/', $key)) { |
|
125 | 125 | continue; |
126 | 126 | } |
127 | 127 | |
128 | 128 | $wikidataEntityId = $value['value']; |
129 | - $localEntityId = $wikiConfig->get( $key ); |
|
129 | + $localEntityId = $wikiConfig->get($key); |
|
130 | 130 | |
131 | - if ( $localEntityId === $wikidataEntityId ) { |
|
131 | + if ($localEntityId === $wikidataEntityId) { |
|
132 | 132 | $wikidataEntityIds[$key] = $wikidataEntityId; |
133 | 133 | } |
134 | 134 | } |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | * @param string $wikidataEntityId |
141 | 141 | * @return string local entity ID |
142 | 142 | */ |
143 | - private function importEntityFromWikidata( $wikidataEntityId ) { |
|
143 | + private function importEntityFromWikidata($wikidataEntityId) { |
|
144 | 144 | $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json"; |
145 | - $wikidataEntitiesJson = $this->httpRequestFactory->get( $wikidataEntityUrl, [], __METHOD__ ); |
|
146 | - return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ); |
|
145 | + $wikidataEntitiesJson = $this->httpRequestFactory->get($wikidataEntityUrl, [], __METHOD__); |
|
146 | + return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,24 +151,24 @@ discard block |
||
151 | 151 | * @param string $wikidataEntitiesJson |
152 | 152 | * @return string local entity ID |
153 | 153 | */ |
154 | - private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) { |
|
154 | + private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) { |
|
155 | 155 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
156 | - $wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId]; |
|
157 | - $wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray ); |
|
156 | + $wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId]; |
|
157 | + $wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray); |
|
158 | 158 | |
159 | - $wikidataEntity->setId( null ); |
|
159 | + $wikidataEntity->setId(null); |
|
160 | 160 | |
161 | - if ( $wikidataEntity instanceof StatementListProvider ) { |
|
161 | + if ($wikidataEntity instanceof StatementListProvider) { |
|
162 | 162 | $wikidataEntity->getStatements()->clear(); |
163 | 163 | } |
164 | 164 | |
165 | - if ( $wikidataEntity instanceof Item ) { |
|
166 | - $wikidataEntity->setSiteLinkList( new SiteLinkList() ); |
|
165 | + if ($wikidataEntity instanceof Item) { |
|
166 | + $wikidataEntity->setSiteLinkList(new SiteLinkList()); |
|
167 | 167 | } |
168 | 168 | |
169 | - if ( $this->getOption( 'dry-run', false ) ) { |
|
170 | - $wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) ); |
|
171 | - $this->output( $wikidataEntityJson . "\n" ); |
|
169 | + if ($this->getOption('dry-run', false)) { |
|
170 | + $wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity)); |
|
171 | + $this->output($wikidataEntityJson."\n"); |
|
172 | 172 | return "-$wikidataEntityId"; |
173 | 173 | } |
174 | 174 | |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | )->getEntity(); |
182 | 182 | |
183 | 183 | return $localEntity->getId()->getSerialization(); |
184 | - } catch ( StorageException $storageException ) { |
|
185 | - return $this->storageExceptionToEntityId( $storageException ); |
|
184 | + } catch (StorageException $storageException) { |
|
185 | + return $this->storageExceptionToEntityId($storageException); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
189 | - private function storageExceptionToEntityId( StorageException $storageException ) { |
|
189 | + private function storageExceptionToEntityId(StorageException $storageException) { |
|
190 | 190 | $message = $storageException->getMessage(); |
191 | 191 | // example messages: |
192 | 192 | // * Item [[Item:Q475|Q475]] already has label "as references" |
@@ -196,25 +196,25 @@ discard block |
||
196 | 196 | // * Property [[Property:P694|P694]] already has label "instance of" |
197 | 197 | // associated with language code en. |
198 | 198 | $pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/'; |
199 | - if ( preg_match( $pattern, $message, $matches ) ) { |
|
199 | + if (preg_match($pattern, $message, $matches)) { |
|
200 | 200 | return $matches[1]; |
201 | 201 | } else { |
202 | 202 | throw $storageException; |
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | - private function outputConfigUpdates( array $configUpdates ) { |
|
207 | - $configFormat = $this->getOption( 'config-format', 'globals' ); |
|
208 | - switch ( $configFormat ) { |
|
206 | + private function outputConfigUpdates(array $configUpdates) { |
|
207 | + $configFormat = $this->getOption('config-format', 'globals'); |
|
208 | + switch ($configFormat) { |
|
209 | 209 | case 'globals': |
210 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
210 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
211 | 211 | break; |
212 | 212 | case 'wgConf': |
213 | - $this->outputConfigUpdatesWgConf( $configUpdates ); |
|
213 | + $this->outputConfigUpdatesWgConf($configUpdates); |
|
214 | 214 | break; |
215 | 215 | default: |
216 | - $this->error( "Invalid config format \"$configFormat\", using \"globals\"" ); |
|
217 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
216 | + $this->error("Invalid config format \"$configFormat\", using \"globals\""); |
|
217 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
218 | 218 | break; |
219 | 219 | } |
220 | 220 | } |
@@ -222,22 +222,22 @@ discard block |
||
222 | 222 | /** |
223 | 223 | * @param array[] $configUpdates |
224 | 224 | */ |
225 | - private function outputConfigUpdatesGlobals( array $configUpdates ) { |
|
226 | - foreach ( $configUpdates as $key => $value ) { |
|
227 | - $localValueCode = var_export( $value['local'], true ); |
|
228 | - $this->output( "\$wg$key = $localValueCode;\n" ); |
|
225 | + private function outputConfigUpdatesGlobals(array $configUpdates) { |
|
226 | + foreach ($configUpdates as $key => $value) { |
|
227 | + $localValueCode = var_export($value['local'], true); |
|
228 | + $this->output("\$wg$key = $localValueCode;\n"); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
233 | 233 | * @param array[] $configUpdates |
234 | 234 | */ |
235 | - private function outputConfigUpdatesWgConf( array $configUpdates ) { |
|
236 | - $wikiIdCode = var_export( WikiMap::getCurrentWikiId(), true ); |
|
237 | - foreach ( $configUpdates as $key => $value ) { |
|
238 | - $keyCode = var_export( "wg$key", true ); |
|
239 | - $wikidataValueCode = var_export( $value['wikidata'], true ); |
|
240 | - $localValueCode = var_export( $value['local'], true ); |
|
235 | + private function outputConfigUpdatesWgConf(array $configUpdates) { |
|
236 | + $wikiIdCode = var_export(WikiMap::getCurrentWikiId(), true); |
|
237 | + foreach ($configUpdates as $key => $value) { |
|
238 | + $keyCode = var_export("wg$key", true); |
|
239 | + $wikidataValueCode = var_export($value['wikidata'], true); |
|
240 | + $localValueCode = var_export($value['local'], true); |
|
241 | 241 | $block = <<< EOF |
242 | 242 | $keyCode => [ |
243 | 243 | 'default' => $wikidataValueCode, |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | |
247 | 247 | |
248 | 248 | EOF; |
249 | - $this->output( $block ); |
|
249 | + $this->output($block); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 |
@@ -38,206 +38,206 @@ |
||
38 | 38 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker; |
39 | 39 | |
40 | 40 | return [ |
41 | - ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function ( MediaWikiServices $services ) { |
|
41 | + ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function(MediaWikiServices $services) { |
|
42 | 42 | return new ConflictsWithChecker( |
43 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
44 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
43 | + ConstraintsServices::getConstraintParameterParser($services), |
|
44 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
45 | 45 | ); |
46 | 46 | }, |
47 | 47 | |
48 | - ConstraintCheckerServices::ITEM_CHECKER => static function ( MediaWikiServices $services ) { |
|
48 | + ConstraintCheckerServices::ITEM_CHECKER => static function(MediaWikiServices $services) { |
|
49 | 49 | return new ItemChecker( |
50 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
51 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
50 | + ConstraintsServices::getConstraintParameterParser($services), |
|
51 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
52 | 52 | ); |
53 | 53 | }, |
54 | 54 | |
55 | - ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function ( MediaWikiServices $services ) { |
|
55 | + ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function(MediaWikiServices $services) { |
|
56 | 56 | return new TargetRequiredClaimChecker( |
57 | - WikibaseServices::getEntityLookup( $services ), |
|
58 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
59 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
57 | + WikibaseServices::getEntityLookup($services), |
|
58 | + ConstraintsServices::getConstraintParameterParser($services), |
|
59 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
60 | 60 | ); |
61 | 61 | }, |
62 | 62 | |
63 | - ConstraintCheckerServices::SYMMETRIC_CHECKER => static function ( MediaWikiServices $services ) { |
|
63 | + ConstraintCheckerServices::SYMMETRIC_CHECKER => static function(MediaWikiServices $services) { |
|
64 | 64 | return new SymmetricChecker( |
65 | - WikibaseServices::getEntityLookupWithoutCache( $services ), |
|
66 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
65 | + WikibaseServices::getEntityLookupWithoutCache($services), |
|
66 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
67 | 67 | ); |
68 | 68 | }, |
69 | 69 | |
70 | - ConstraintCheckerServices::INVERSE_CHECKER => static function ( MediaWikiServices $services ) { |
|
70 | + ConstraintCheckerServices::INVERSE_CHECKER => static function(MediaWikiServices $services) { |
|
71 | 71 | return new InverseChecker( |
72 | - WikibaseServices::getEntityLookup( $services ), |
|
73 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
74 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
72 | + WikibaseServices::getEntityLookup($services), |
|
73 | + ConstraintsServices::getConstraintParameterParser($services), |
|
74 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
75 | 75 | ); |
76 | 76 | }, |
77 | 77 | |
78 | - ConstraintCheckerServices::QUALIFIER_CHECKER => static function ( MediaWikiServices $services ) { |
|
78 | + ConstraintCheckerServices::QUALIFIER_CHECKER => static function(MediaWikiServices $services) { |
|
79 | 79 | return new QualifierChecker(); |
80 | 80 | }, |
81 | 81 | |
82 | - ConstraintCheckerServices::QUALIFIERS_CHECKER => static function ( MediaWikiServices $services ) { |
|
82 | + ConstraintCheckerServices::QUALIFIERS_CHECKER => static function(MediaWikiServices $services) { |
|
83 | 83 | return new QualifiersChecker( |
84 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
84 | + ConstraintsServices::getConstraintParameterParser($services) |
|
85 | 85 | ); |
86 | 86 | }, |
87 | 87 | |
88 | - ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function ( MediaWikiServices $services ) { |
|
88 | + ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function(MediaWikiServices $services) { |
|
89 | 89 | return new MandatoryQualifiersChecker( |
90 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
90 | + ConstraintsServices::getConstraintParameterParser($services) |
|
91 | 91 | ); |
92 | 92 | }, |
93 | 93 | |
94 | - ConstraintCheckerServices::RANGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
94 | + ConstraintCheckerServices::RANGE_CHECKER => static function(MediaWikiServices $services) { |
|
95 | 95 | return new RangeChecker( |
96 | - WikibaseServices::getPropertyDataTypeLookup( $services ), |
|
97 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
98 | - ConstraintsServices::getRangeCheckerHelper( $services ) |
|
96 | + WikibaseServices::getPropertyDataTypeLookup($services), |
|
97 | + ConstraintsServices::getConstraintParameterParser($services), |
|
98 | + ConstraintsServices::getRangeCheckerHelper($services) |
|
99 | 99 | ); |
100 | 100 | }, |
101 | 101 | |
102 | - ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
102 | + ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function(MediaWikiServices $services) { |
|
103 | 103 | return new DiffWithinRangeChecker( |
104 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
105 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
104 | + ConstraintsServices::getConstraintParameterParser($services), |
|
105 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
106 | 106 | $services->getMainConfig() |
107 | 107 | ); |
108 | 108 | }, |
109 | 109 | |
110 | - ConstraintCheckerServices::TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
110 | + ConstraintCheckerServices::TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
111 | 111 | return new TypeChecker( |
112 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
113 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
112 | + ConstraintsServices::getConstraintParameterParser($services), |
|
113 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
114 | 114 | $services->getMainConfig() |
115 | 115 | ); |
116 | 116 | }, |
117 | 117 | |
118 | - ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
118 | + ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
119 | 119 | return new ValueTypeChecker( |
120 | - WikibaseServices::getEntityLookup( $services ), |
|
121 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
122 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
120 | + WikibaseServices::getEntityLookup($services), |
|
121 | + ConstraintsServices::getConstraintParameterParser($services), |
|
122 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
123 | 123 | $services->getMainConfig() |
124 | 124 | ); |
125 | 125 | }, |
126 | 126 | |
127 | - ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
127 | + ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
128 | 128 | return new SingleValueChecker( |
129 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
129 | + ConstraintsServices::getConstraintParameterParser($services) |
|
130 | 130 | ); |
131 | 131 | }, |
132 | 132 | |
133 | - ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
133 | + ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
134 | 134 | return new MultiValueChecker( |
135 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
135 | + ConstraintsServices::getConstraintParameterParser($services) |
|
136 | 136 | ); |
137 | 137 | }, |
138 | 138 | |
139 | - ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
139 | + ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
140 | 140 | // TODO return a different, dummy implementation if SPARQL is not available |
141 | 141 | return new UniqueValueChecker( |
142 | - ConstraintsServices::getSparqlHelper( $services ), |
|
143 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
142 | + ConstraintsServices::getSparqlHelper($services), |
|
143 | + ConstraintsServices::getConstraintParameterParser($services) |
|
144 | 144 | ); |
145 | 145 | }, |
146 | 146 | |
147 | - ConstraintCheckerServices::FORMAT_CHECKER => static function ( MediaWikiServices $services ) { |
|
147 | + ConstraintCheckerServices::FORMAT_CHECKER => static function(MediaWikiServices $services) { |
|
148 | 148 | // TODO return a different, dummy implementation if SPARQL is not available |
149 | 149 | return new FormatChecker( |
150 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
150 | + ConstraintsServices::getConstraintParameterParser($services), |
|
151 | 151 | $services->getMainConfig(), |
152 | - ConstraintsServices::getSparqlHelper( $services ), |
|
152 | + ConstraintsServices::getSparqlHelper($services), |
|
153 | 153 | $services->getShellboxClientFactory() |
154 | 154 | ); |
155 | 155 | }, |
156 | 156 | |
157 | - ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function ( MediaWikiServices $services ) { |
|
157 | + ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function(MediaWikiServices $services) { |
|
158 | 158 | $pageNameNormalizer = new MediaWikiPageNameNormalizer(); |
159 | 159 | return new CommonsLinkChecker( |
160 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
160 | + ConstraintsServices::getConstraintParameterParser($services), |
|
161 | 161 | $pageNameNormalizer, |
162 | - WikibaseRepo::getPropertyDataTypeLookup( $services ) |
|
162 | + WikibaseRepo::getPropertyDataTypeLookup($services) |
|
163 | 163 | ); |
164 | 164 | }, |
165 | 165 | |
166 | - ConstraintCheckerServices::ONE_OF_CHECKER => static function ( MediaWikiServices $services ) { |
|
166 | + ConstraintCheckerServices::ONE_OF_CHECKER => static function(MediaWikiServices $services) { |
|
167 | 167 | return new OneOfChecker( |
168 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
168 | + ConstraintsServices::getConstraintParameterParser($services) |
|
169 | 169 | ); |
170 | 170 | }, |
171 | 171 | |
172 | - ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function ( MediaWikiServices $services ) { |
|
172 | + ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function(MediaWikiServices $services) { |
|
173 | 173 | return new ValueOnlyChecker(); |
174 | 174 | }, |
175 | 175 | |
176 | - ConstraintCheckerServices::REFERENCE_CHECKER => static function ( MediaWikiServices $services ) { |
|
176 | + ConstraintCheckerServices::REFERENCE_CHECKER => static function(MediaWikiServices $services) { |
|
177 | 177 | return new ReferenceChecker(); |
178 | 178 | }, |
179 | 179 | |
180 | - ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function ( MediaWikiServices $services ) { |
|
180 | + ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function(MediaWikiServices $services) { |
|
181 | 181 | return new NoBoundsChecker(); |
182 | 182 | }, |
183 | 183 | |
184 | - ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function ( MediaWikiServices $services ) { |
|
184 | + ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function(MediaWikiServices $services) { |
|
185 | 185 | return new AllowedUnitsChecker( |
186 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
187 | - WikibaseRepo::getUnitConverter( $services ) |
|
186 | + ConstraintsServices::getConstraintParameterParser($services), |
|
187 | + WikibaseRepo::getUnitConverter($services) |
|
188 | 188 | ); |
189 | 189 | }, |
190 | 190 | |
191 | - ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
191 | + ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
192 | 192 | return new SingleBestValueChecker( |
193 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
193 | + ConstraintsServices::getConstraintParameterParser($services) |
|
194 | 194 | ); |
195 | 195 | }, |
196 | 196 | |
197 | - ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
197 | + ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
198 | 198 | return new EntityTypeChecker( |
199 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
199 | + ConstraintsServices::getConstraintParameterParser($services) |
|
200 | 200 | ); |
201 | 201 | }, |
202 | 202 | |
203 | - ConstraintCheckerServices::NONE_OF_CHECKER => static function ( MediaWikiServices $services ) { |
|
203 | + ConstraintCheckerServices::NONE_OF_CHECKER => static function(MediaWikiServices $services) { |
|
204 | 204 | return new NoneOfChecker( |
205 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
205 | + ConstraintsServices::getConstraintParameterParser($services) |
|
206 | 206 | ); |
207 | 207 | }, |
208 | 208 | |
209 | - ConstraintCheckerServices::INTEGER_CHECKER => static function ( MediaWikiServices $services ) { |
|
209 | + ConstraintCheckerServices::INTEGER_CHECKER => static function(MediaWikiServices $services) { |
|
210 | 210 | return new IntegerChecker(); |
211 | 211 | }, |
212 | 212 | |
213 | - ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function ( MediaWikiServices $services ) { |
|
213 | + ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function(MediaWikiServices $services) { |
|
214 | 214 | return new CitationNeededChecker(); |
215 | 215 | }, |
216 | 216 | |
217 | - ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
217 | + ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function(MediaWikiServices $services) { |
|
218 | 218 | return new PropertyScopeChecker( |
219 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
219 | + ConstraintsServices::getConstraintParameterParser($services) |
|
220 | 220 | ); |
221 | 221 | }, |
222 | 222 | |
223 | - ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function ( MediaWikiServices $services ) { |
|
223 | + ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function(MediaWikiServices $services) { |
|
224 | 224 | return new ContemporaryChecker( |
225 | - WikibaseServices::getEntityLookup( $services ), |
|
226 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
225 | + WikibaseServices::getEntityLookup($services), |
|
226 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
227 | 227 | $services->getMainConfig() |
228 | 228 | ); |
229 | 229 | }, |
230 | 230 | |
231 | - ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
231 | + ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function(MediaWikiServices $services) { |
|
232 | 232 | return new LanguageChecker( |
233 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
234 | - WikibaseServices::getEntityLookup( $services ) |
|
233 | + ConstraintsServices::getConstraintParameterParser($services), |
|
234 | + WikibaseServices::getEntityLookup($services) |
|
235 | 235 | ); |
236 | 236 | }, |
237 | 237 | |
238 | - ConstraintCheckerServices::LABEL_IN_LANGUAGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
238 | + ConstraintCheckerServices::LABEL_IN_LANGUAGE_CHECKER => static function(MediaWikiServices $services) { |
|
239 | 239 | return new LabelInLanguageChecker( |
240 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
240 | + ConstraintsServices::getConstraintParameterParser($services) |
|
241 | 241 | ); |
242 | 242 | }, |
243 | 243 | ]; |
@@ -23,15 +23,15 @@ discard block |
||
23 | 23 | // no parent::__construct() call |
24 | 24 | } |
25 | 25 | |
26 | - public function hasType( $id, array $classes ) { |
|
27 | - throw new LogicException( 'methods of this class should never be called' ); |
|
26 | + public function hasType($id, array $classes) { |
|
27 | + throw new LogicException('methods of this class should never be called'); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | public function findEntitiesWithSameStatement( |
31 | 31 | Statement $statement, |
32 | 32 | array $separators |
33 | 33 | ) { |
34 | - throw new LogicException( 'methods of this class should never be called' ); |
|
34 | + throw new LogicException('methods of this class should never be called'); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function findEntitiesWithSameQualifierOrReference( |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | $type, |
41 | 41 | $ignoreDeprecatedStatements |
42 | 42 | ) { |
43 | - throw new LogicException( 'methods of this class should never be called' ); |
|
43 | + throw new LogicException('methods of this class should never be called'); |
|
44 | 44 | } |
45 | 45 | |
46 | - public function matchesRegularExpression( $text, $regex ) { |
|
47 | - throw new LogicException( 'methods of this class should never be called' ); |
|
46 | + public function matchesRegularExpression($text, $regex) { |
|
47 | + throw new LogicException('methods of this class should never be called'); |
|
48 | 48 | } |
49 | 49 | |
50 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
51 | - throw new LogicException( 'methods of this class should never be called' ); |
|
50 | + public function runQuery($query, $needsPrefixes = true) { |
|
51 | + throw new LogicException('methods of this class should never be called'); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
@@ -81,26 +81,26 @@ discard block |
||
81 | 81 | * @return bool |
82 | 82 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
83 | 83 | */ |
84 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
85 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
84 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
85 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
86 | 86 | if ( ++$entitiesChecked > $maxEntities ) { |
87 | - throw new OverflowException( 'Too many entities to check' ); |
|
87 | + throw new OverflowException('Too many entities to check'); |
|
88 | 88 | } |
89 | 89 | |
90 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
91 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
90 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
91 | + if (!($item instanceof StatementListProvider)) { |
|
92 | 92 | return false; // lookup failed, probably because item doesn't exist |
93 | 93 | } |
94 | 94 | |
95 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
95 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
96 | 96 | $statements = $item->getStatements() |
97 | - ->getByPropertyId( new NumericPropertyId( $subclassId ) ) |
|
97 | + ->getByPropertyId(new NumericPropertyId($subclassId)) |
|
98 | 98 | ->getBestStatements(); |
99 | 99 | /** @var Statement $statement */ |
100 | - foreach ( $statements as $statement ) { |
|
100 | + foreach ($statements as $statement) { |
|
101 | 101 | $mainSnak = $statement->getMainSnak(); |
102 | 102 | |
103 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
103 | + if (!$this->hasCorrectType($mainSnak)) { |
|
104 | 104 | continue; |
105 | 105 | } |
106 | 106 | /** @var PropertyValueSnak $mainSnak */ |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | '@phan-var EntityIdValue $dataValue'; |
111 | 111 | $comparativeClass = $dataValue->getEntityId(); |
112 | 112 | |
113 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
113 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
114 | 114 | return true; |
115 | 115 | } |
116 | 116 | |
117 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
117 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
118 | 118 | return true; |
119 | 119 | } |
120 | 120 | } |
@@ -135,48 +135,48 @@ discard block |
||
135 | 135 | * @return CachedBool |
136 | 136 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
137 | 137 | */ |
138 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
138 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
139 | 139 | try { |
140 | 140 | $entitiesChecked = 0; |
141 | - $start1 = microtime( true ); |
|
142 | - $isSubclass = $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ); |
|
143 | - $end1 = microtime( true ); |
|
141 | + $start1 = microtime(true); |
|
142 | + $isSubclass = $this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked); |
|
143 | + $end1 = microtime(true); |
|
144 | 144 | $this->dataFactory->timing( |
145 | 145 | 'wikibase.quality.constraints.type.php.success.timing', |
146 | - ( $end1 - $start1 ) * 1000 |
|
146 | + ($end1 - $start1) * 1000 |
|
147 | 147 | ); |
148 | 148 | $this->dataFactory->timing( // not really a timing, but works like one (we want percentiles etc.) |
149 | 149 | 'wikibase.quality.constraints.type.php.success.entities', |
150 | 150 | $entitiesChecked |
151 | 151 | ); |
152 | 152 | |
153 | - return new CachedBool( $isSubclass, Metadata::blank() ); |
|
154 | - } catch ( OverflowException $e ) { |
|
155 | - $end1 = microtime( true ); |
|
153 | + return new CachedBool($isSubclass, Metadata::blank()); |
|
154 | + } catch (OverflowException $e) { |
|
155 | + $end1 = microtime(true); |
|
156 | 156 | $this->dataFactory->timing( |
157 | 157 | 'wikibase.quality.constraints.type.php.overflow.timing', |
158 | - ( $end1 - $start1 ) * 1000 |
|
158 | + ($end1 - $start1) * 1000 |
|
159 | 159 | ); |
160 | 160 | |
161 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
161 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
162 | 162 | $this->dataFactory->increment( |
163 | 163 | 'wikibase.quality.constraints.sparql.typeFallback' |
164 | 164 | ); |
165 | 165 | |
166 | - $start2 = microtime( true ); |
|
166 | + $start2 = microtime(true); |
|
167 | 167 | $hasType = $this->sparqlHelper->hasType( |
168 | 168 | $comparativeClass->getSerialization(), |
169 | 169 | $classesToCheck |
170 | 170 | ); |
171 | - $end2 = microtime( true ); |
|
171 | + $end2 = microtime(true); |
|
172 | 172 | $this->dataFactory->timing( |
173 | 173 | 'wikibase.quality.constraints.type.sparql.success.timing', |
174 | - ( $end2 - $start2 ) * 1000 |
|
174 | + ($end2 - $start2) * 1000 |
|
175 | 175 | ); |
176 | 176 | |
177 | 177 | return $hasType; |
178 | 178 | } else { |
179 | - return new CachedBool( false, Metadata::blank() ); |
|
179 | + return new CachedBool(false, Metadata::blank()); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | } |
@@ -194,13 +194,13 @@ discard block |
||
194 | 194 | * @return CachedBool |
195 | 195 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
196 | 196 | */ |
197 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
197 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
198 | 198 | $metadatas = []; |
199 | 199 | |
200 | - foreach ( $this->getBestStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
200 | + foreach ($this->getBestStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
201 | 201 | $mainSnak = $statement->getMainSnak(); |
202 | 202 | |
203 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
203 | + if (!$this->hasCorrectType($mainSnak)) { |
|
204 | 204 | continue; |
205 | 205 | } |
206 | 206 | /** @var PropertyValueSnak $mainSnak */ |
@@ -210,24 +210,24 @@ discard block |
||
210 | 210 | '@phan-var EntityIdValue $dataValue'; |
211 | 211 | $comparativeClass = $dataValue->getEntityId(); |
212 | 212 | |
213 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
213 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
214 | 214 | // discard $metadatas, we know this is fresh |
215 | - return new CachedBool( true, Metadata::blank() ); |
|
215 | + return new CachedBool(true, Metadata::blank()); |
|
216 | 216 | } |
217 | 217 | |
218 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
218 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
219 | 219 | $metadatas[] = $result->getMetadata(); |
220 | - if ( $result->getBool() ) { |
|
220 | + if ($result->getBool()) { |
|
221 | 221 | return new CachedBool( |
222 | 222 | true, |
223 | - Metadata::merge( $metadatas ) |
|
223 | + Metadata::merge($metadatas) |
|
224 | 224 | ); |
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
228 | 228 | return new CachedBool( |
229 | 229 | false, |
230 | - Metadata::merge( $metadatas ) |
|
230 | + Metadata::merge($metadatas) |
|
231 | 231 | ); |
232 | 232 | } |
233 | 233 | |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * @return bool |
237 | 237 | * @phan-assert PropertyValueSnak $mainSnak |
238 | 238 | */ |
239 | - private function hasCorrectType( Snak $mainSnak ) { |
|
239 | + private function hasCorrectType(Snak $mainSnak) { |
|
240 | 240 | return $mainSnak instanceof PropertyValueSnak |
241 | 241 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
242 | 242 | } |
@@ -253,15 +253,15 @@ discard block |
||
253 | 253 | ) { |
254 | 254 | $statementArrays = []; |
255 | 255 | |
256 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
257 | - $propertyId = new NumericPropertyId( $propertyIdSerialization ); |
|
256 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
257 | + $propertyId = new NumericPropertyId($propertyIdSerialization); |
|
258 | 258 | $statementArrays[] = $statements |
259 | - ->getByPropertyId( $propertyId ) |
|
259 | + ->getByPropertyId($propertyId) |
|
260 | 260 | ->getBestStatements() |
261 | 261 | ->toArray(); |
262 | 262 | } |
263 | 263 | |
264 | - return call_user_func_array( 'array_merge', $statementArrays ); |
|
264 | + return call_user_func_array('array_merge', $statementArrays); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | $relation |
282 | 282 | ) { |
283 | 283 | $classes = array_map( |
284 | - static function ( $itemIdSerialization ) { |
|
285 | - return new ItemId( $itemIdSerialization ); |
|
284 | + static function($itemIdSerialization) { |
|
285 | + return new ItemId($itemIdSerialization); |
|
286 | 286 | }, |
287 | 287 | $classes |
288 | 288 | ); |
@@ -294,10 +294,10 @@ discard block |
||
294 | 294 | // wbqc-violation-message-valueType-instance |
295 | 295 | // wbqc-violation-message-valueType-subclass |
296 | 296 | // wbqc-violation-message-valueType-instanceOrSubclass |
297 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
298 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
299 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
300 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
297 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
298 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
299 | + ->withEntityId($entityId, Role::SUBJECT) |
|
300 | + ->withEntityIdList($classes, Role::OBJECT); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | } |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | * @param array $parameters |
79 | 79 | * @throws ConstraintParameterException |
80 | 80 | */ |
81 | - public function checkError( array $parameters ) { |
|
82 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
81 | + public function checkError(array $parameters) { |
|
82 | + if (array_key_exists('@error', $parameters)) { |
|
83 | 83 | $error = $parameters['@error']; |
84 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
84 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
85 | 85 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
86 | 86 | } else { |
87 | 87 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
88 | 88 | } |
89 | - throw new ConstraintParameterException( new ViolationMessage( $msg ) ); |
|
89 | + throw new ConstraintParameterException(new ViolationMessage($msg)); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | * @param string $parameterId |
97 | 97 | * @throws ConstraintParameterException |
98 | 98 | */ |
99 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
100 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
99 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
100 | + if (count($parameters[$parameterId]) !== 1) { |
|
101 | 101 | throw new ConstraintParameterException( |
102 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) ) |
|
103 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
102 | + (new ViolationMessage('wbqc-violation-message-parameter-single')) |
|
103 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
104 | 104 | ); |
105 | 105 | } |
106 | 106 | } |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * @return void |
113 | 113 | * @throws ConstraintParameterException |
114 | 114 | */ |
115 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
116 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
115 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
116 | + if (!($snak instanceof PropertyValueSnak)) { |
|
117 | 117 | throw new ConstraintParameterException( |
118 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
119 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
118 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
119 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
120 | 120 | ); |
121 | 121 | } |
122 | 122 | } |
@@ -128,17 +128,17 @@ discard block |
||
128 | 128 | * @throws ConstraintParameterException |
129 | 129 | * @return EntityId |
130 | 130 | */ |
131 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
132 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
133 | - $this->requireValueParameter( $snak, $parameterId ); |
|
131 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
132 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
133 | + $this->requireValueParameter($snak, $parameterId); |
|
134 | 134 | $value = $snak->getDataValue(); |
135 | - if ( $value instanceof EntityIdValue ) { |
|
135 | + if ($value instanceof EntityIdValue) { |
|
136 | 136 | return $value->getEntityId(); |
137 | 137 | } else { |
138 | 138 | throw new ConstraintParameterException( |
139 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) ) |
|
140 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
141 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
139 | + (new ViolationMessage('wbqc-violation-message-parameter-entity')) |
|
140 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
141 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
142 | 142 | ); |
143 | 143 | } |
144 | 144 | } |
@@ -149,20 +149,20 @@ discard block |
||
149 | 149 | * @throws ConstraintParameterException if the parameter is invalid or missing |
150 | 150 | * @return string[] class entity ID serializations |
151 | 151 | */ |
152 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
153 | - $this->checkError( $constraintParameters ); |
|
154 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
155 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
152 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
153 | + $this->checkError($constraintParameters); |
|
154 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
155 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
156 | 156 | throw new ConstraintParameterException( |
157 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
158 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
159 | - ->withEntityId( new NumericPropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
157 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
158 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
159 | + ->withEntityId(new NumericPropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
160 | 160 | ); |
161 | 161 | } |
162 | 162 | |
163 | 163 | $classes = []; |
164 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
165 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
164 | + foreach ($constraintParameters[$classId] as $class) { |
|
165 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
166 | 166 | } |
167 | 167 | return $classes; |
168 | 168 | } |
@@ -173,31 +173,31 @@ discard block |
||
173 | 173 | * @throws ConstraintParameterException if the parameter is invalid or missing |
174 | 174 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
175 | 175 | */ |
176 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
177 | - $this->checkError( $constraintParameters ); |
|
178 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
179 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
176 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
177 | + $this->checkError($constraintParameters); |
|
178 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
179 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
180 | 180 | throw new ConstraintParameterException( |
181 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
182 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
183 | - ->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
181 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
182 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
183 | + ->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
184 | 184 | ); |
185 | 185 | } |
186 | 186 | |
187 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
188 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
189 | - if ( !( $relationEntityId instanceof ItemId ) ) { |
|
187 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
188 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
189 | + if (!($relationEntityId instanceof ItemId)) { |
|
190 | 190 | throw new ConstraintParameterException( |
191 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
192 | - ->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
193 | - ->withDataValue( new EntityIdValue( $relationEntityId ), Role::CONSTRAINT_PARAMETER_VALUE ) |
|
191 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
192 | + ->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
193 | + ->withDataValue(new EntityIdValue($relationEntityId), Role::CONSTRAINT_PARAMETER_VALUE) |
|
194 | 194 | ); |
195 | 195 | } |
196 | - return $this->mapItemId( $relationEntityId, [ |
|
197 | - $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ) => 'instance', |
|
198 | - $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ) => 'subclass', |
|
199 | - $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ) => 'instanceOrSubclass', |
|
200 | - ], $relationId ); |
|
196 | + return $this->mapItemId($relationEntityId, [ |
|
197 | + $this->config->get('WBQualityConstraintsInstanceOfRelationId') => 'instance', |
|
198 | + $this->config->get('WBQualityConstraintsSubclassOfRelationId') => 'subclass', |
|
199 | + $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId') => 'instanceOrSubclass', |
|
200 | + ], $relationId); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,20 +207,20 @@ discard block |
||
207 | 207 | * @throws ConstraintParameterException |
208 | 208 | * @return PropertyId |
209 | 209 | */ |
210 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
211 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
212 | - $this->requireValueParameter( $snak, $parameterId ); |
|
210 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
211 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
212 | + $this->requireValueParameter($snak, $parameterId); |
|
213 | 213 | $value = $snak->getDataValue(); |
214 | - if ( $value instanceof EntityIdValue ) { |
|
214 | + if ($value instanceof EntityIdValue) { |
|
215 | 215 | $id = $value->getEntityId(); |
216 | - if ( $id instanceof PropertyId ) { |
|
216 | + if ($id instanceof PropertyId) { |
|
217 | 217 | return $id; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | throw new ConstraintParameterException( |
221 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) ) |
|
222 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
223 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
221 | + (new ViolationMessage('wbqc-violation-message-parameter-property')) |
|
222 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
223 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
224 | 224 | ); |
225 | 225 | } |
226 | 226 | |
@@ -231,33 +231,33 @@ discard block |
||
231 | 231 | * @throws ConstraintParameterException if the parameter is invalid or missing |
232 | 232 | * @return PropertyId |
233 | 233 | */ |
234 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
235 | - $this->checkError( $constraintParameters ); |
|
236 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
237 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
234 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
235 | + $this->checkError($constraintParameters); |
|
236 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
237 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
238 | 238 | throw new ConstraintParameterException( |
239 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
240 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
241 | - ->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
239 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
240 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
241 | + ->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
242 | 242 | ); |
243 | 243 | } |
244 | 244 | |
245 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
246 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
245 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
246 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
247 | 247 | } |
248 | 248 | |
249 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
249 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
250 | 250 | $dataValue = $snak->getDataValue(); |
251 | - if ( $dataValue instanceof EntityIdValue ) { |
|
251 | + if ($dataValue instanceof EntityIdValue) { |
|
252 | 252 | $entityId = $dataValue->getEntityId(); |
253 | - if ( $entityId instanceof ItemId ) { |
|
254 | - return ItemIdSnakValue::fromItemId( $entityId ); |
|
253 | + if ($entityId instanceof ItemId) { |
|
254 | + return ItemIdSnakValue::fromItemId($entityId); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | throw new ConstraintParameterException( |
258 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
259 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
260 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
258 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
259 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
260 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
261 | 261 | ); |
262 | 262 | } |
263 | 263 | |
@@ -275,16 +275,16 @@ discard block |
||
275 | 275 | $required, |
276 | 276 | $parameterId = null |
277 | 277 | ) { |
278 | - $this->checkError( $constraintParameters ); |
|
279 | - if ( $parameterId === null ) { |
|
280 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
278 | + $this->checkError($constraintParameters); |
|
279 | + if ($parameterId === null) { |
|
280 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
281 | 281 | } |
282 | - if ( !array_key_exists( $parameterId, $constraintParameters ) ) { |
|
283 | - if ( $required ) { |
|
282 | + if (!array_key_exists($parameterId, $constraintParameters)) { |
|
283 | + if ($required) { |
|
284 | 284 | throw new ConstraintParameterException( |
285 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
286 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
287 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
285 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
286 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
287 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
288 | 288 | ); |
289 | 289 | } else { |
290 | 290 | return []; |
@@ -292,11 +292,11 @@ discard block |
||
292 | 292 | } |
293 | 293 | |
294 | 294 | $values = []; |
295 | - foreach ( $constraintParameters[$parameterId] as $parameter ) { |
|
296 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
297 | - switch ( true ) { |
|
295 | + foreach ($constraintParameters[$parameterId] as $parameter) { |
|
296 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
297 | + switch (true) { |
|
298 | 298 | case $snak instanceof PropertyValueSnak: |
299 | - $values[] = $this->parseItemIdParameter( $snak, $parameterId ); |
|
299 | + $values[] = $this->parseItemIdParameter($snak, $parameterId); |
|
300 | 300 | break; |
301 | 301 | case $snak instanceof PropertySomeValueSnak: |
302 | 302 | $values[] = ItemIdSnakValue::someValue(); |
@@ -324,13 +324,13 @@ discard block |
||
324 | 324 | bool $required, |
325 | 325 | string $parameterId |
326 | 326 | ): array { |
327 | - return array_map( static function ( ItemIdSnakValue $value ) use ( $parameterId ): ItemId { |
|
328 | - if ( $value->isValue() ) { |
|
327 | + return array_map(static function(ItemIdSnakValue $value) use ($parameterId): ItemId { |
|
328 | + if ($value->isValue()) { |
|
329 | 329 | return $value->getItemId(); |
330 | 330 | } else { |
331 | 331 | throw new ConstraintParameterException( |
332 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
333 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
332 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
333 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
334 | 334 | ); |
335 | 335 | } |
336 | 336 | }, $this->parseItemsParameter( |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | $constraintTypeItemId, |
339 | 339 | $required, |
340 | 340 | $parameterId |
341 | - ) ); |
|
341 | + )); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -346,18 +346,18 @@ discard block |
||
346 | 346 | * @throws ConstraintParameterException |
347 | 347 | * @return mixed elements of $mapping |
348 | 348 | */ |
349 | - private function mapItemId( ItemId $itemId, array $mapping, string $parameterId ) { |
|
349 | + private function mapItemId(ItemId $itemId, array $mapping, string $parameterId) { |
|
350 | 350 | $serialization = $itemId->getSerialization(); |
351 | - if ( array_key_exists( $serialization, $mapping ) ) { |
|
351 | + if (array_key_exists($serialization, $mapping)) { |
|
352 | 352 | return $mapping[$serialization]; |
353 | 353 | } else { |
354 | - $allowed = array_map( static function ( $id ) { |
|
355 | - return new ItemId( $id ); |
|
356 | - }, array_keys( $mapping ) ); |
|
354 | + $allowed = array_map(static function($id) { |
|
355 | + return new ItemId($id); |
|
356 | + }, array_keys($mapping)); |
|
357 | 357 | throw new ConstraintParameterException( |
358 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
359 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
360 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
358 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
359 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
360 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
361 | 361 | ); |
362 | 362 | } |
363 | 363 | } |
@@ -368,27 +368,27 @@ discard block |
||
368 | 368 | * @throws ConstraintParameterException if the parameter is invalid or missing |
369 | 369 | * @return PropertyId[] |
370 | 370 | */ |
371 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
372 | - $this->checkError( $constraintParameters ); |
|
373 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
374 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
371 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
372 | + $this->checkError($constraintParameters); |
|
373 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
374 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
375 | 375 | throw new ConstraintParameterException( |
376 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
377 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
378 | - ->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
376 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
377 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
378 | + ->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
379 | 379 | ); |
380 | 380 | } |
381 | 381 | |
382 | 382 | $parameters = $constraintParameters[$propertyId]; |
383 | - if ( count( $parameters ) === 1 && |
|
384 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
383 | + if (count($parameters) === 1 && |
|
384 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
385 | 385 | ) { |
386 | 386 | return []; |
387 | 387 | } |
388 | 388 | |
389 | 389 | $properties = []; |
390 | - foreach ( $parameters as $parameter ) { |
|
391 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
390 | + foreach ($parameters as $parameter) { |
|
391 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
392 | 392 | } |
393 | 393 | return $properties; |
394 | 394 | } |
@@ -399,16 +399,16 @@ discard block |
||
399 | 399 | * @throws ConstraintParameterException |
400 | 400 | * @return DataValue|null |
401 | 401 | */ |
402 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
403 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
404 | - if ( $snak instanceof PropertyValueSnak ) { |
|
402 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
403 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
404 | + if ($snak instanceof PropertyValueSnak) { |
|
405 | 405 | return $snak->getDataValue(); |
406 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
406 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
407 | 407 | return null; |
408 | 408 | } else { |
409 | 409 | throw new ConstraintParameterException( |
410 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
411 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
410 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
411 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
412 | 412 | ); |
413 | 413 | } |
414 | 414 | } |
@@ -418,10 +418,10 @@ discard block |
||
418 | 418 | * @param string $parameterId |
419 | 419 | * @return DataValue|null |
420 | 420 | */ |
421 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
421 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
422 | 422 | try { |
423 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
424 | - } catch ( ConstraintParameterException $e ) { |
|
423 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
424 | + } catch (ConstraintParameterException $e) { |
|
425 | 425 | // unknown value means “now” |
426 | 426 | return new NowValue(); |
427 | 427 | } |
@@ -434,14 +434,14 @@ discard block |
||
434 | 434 | * @param string $unit |
435 | 435 | * @return bool |
436 | 436 | */ |
437 | - private function exactlyOneQuantityWithUnit( ?DataValue $min, ?DataValue $max, $unit ) { |
|
438 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
439 | - !( $max instanceof UnboundedQuantityValue ) |
|
437 | + private function exactlyOneQuantityWithUnit(?DataValue $min, ?DataValue $max, $unit) { |
|
438 | + if (!($min instanceof UnboundedQuantityValue) || |
|
439 | + !($max instanceof UnboundedQuantityValue) |
|
440 | 440 | ) { |
441 | 441 | return false; |
442 | 442 | } |
443 | 443 | |
444 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
444 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -454,42 +454,42 @@ discard block |
||
454 | 454 | * @throws ConstraintParameterException if the parameter is invalid or missing |
455 | 455 | * @return DataValue[] if the parameter is invalid or missing |
456 | 456 | */ |
457 | - private function parseRangeParameter( array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type ) { |
|
458 | - $this->checkError( $constraintParameters ); |
|
459 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
460 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
457 | + private function parseRangeParameter(array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type) { |
|
458 | + $this->checkError($constraintParameters); |
|
459 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
460 | + !array_key_exists($maximumId, $constraintParameters) |
|
461 | 461 | ) { |
462 | 462 | throw new ConstraintParameterException( |
463 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) ) |
|
464 | - ->withDataValueType( $type ) |
|
465 | - ->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
466 | - ->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
467 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
463 | + (new ViolationMessage('wbqc-violation-message-range-parameters-needed')) |
|
464 | + ->withDataValueType($type) |
|
465 | + ->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
466 | + ->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
467 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
468 | 468 | ); |
469 | 469 | } |
470 | 470 | |
471 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
472 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
471 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
472 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
473 | 473 | $parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
474 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
475 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
474 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
475 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
476 | 476 | |
477 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
478 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
477 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
478 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
479 | 479 | throw new ConstraintParameterException( |
480 | - new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
480 | + new ViolationMessage('wbqc-violation-message-range-parameters-one-year') |
|
481 | 481 | ); |
482 | 482 | } |
483 | - if ( $min === null && $max === null || |
|
484 | - $min !== null && $max !== null && $min->equals( $max ) ) { |
|
483 | + if ($min === null && $max === null || |
|
484 | + $min !== null && $max !== null && $min->equals($max)) { |
|
485 | 485 | throw new ConstraintParameterException( |
486 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) ) |
|
487 | - ->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
488 | - ->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
486 | + (new ViolationMessage('wbqc-violation-message-range-parameters-same')) |
|
487 | + ->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
488 | + ->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
489 | 489 | ); |
490 | 490 | } |
491 | 491 | |
492 | - return [ $min, $max ]; |
|
492 | + return [$min, $max]; |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | /** |
@@ -499,11 +499,11 @@ discard block |
||
499 | 499 | * @throws ConstraintParameterException if the parameter is invalid or missing |
500 | 500 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
501 | 501 | */ |
502 | - public function parseQuantityRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
502 | + public function parseQuantityRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
503 | 503 | return $this->parseRangeParameter( |
504 | 504 | $constraintParameters, |
505 | - $this->config->get( 'WBQualityConstraintsMinimumQuantityId' ), |
|
506 | - $this->config->get( 'WBQualityConstraintsMaximumQuantityId' ), |
|
505 | + $this->config->get('WBQualityConstraintsMinimumQuantityId'), |
|
506 | + $this->config->get('WBQualityConstraintsMaximumQuantityId'), |
|
507 | 507 | $constraintTypeItemId, |
508 | 508 | 'quantity' |
509 | 509 | ); |
@@ -516,11 +516,11 @@ discard block |
||
516 | 516 | * @throws ConstraintParameterException if the parameter is invalid or missing |
517 | 517 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
518 | 518 | */ |
519 | - public function parseTimeRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
519 | + public function parseTimeRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
520 | 520 | return $this->parseRangeParameter( |
521 | 521 | $constraintParameters, |
522 | - $this->config->get( 'WBQualityConstraintsMinimumDateId' ), |
|
523 | - $this->config->get( 'WBQualityConstraintsMaximumDateId' ), |
|
522 | + $this->config->get('WBQualityConstraintsMinimumDateId'), |
|
523 | + $this->config->get('WBQualityConstraintsMaximumDateId'), |
|
524 | 524 | $constraintTypeItemId, |
525 | 525 | 'time' |
526 | 526 | ); |
@@ -532,20 +532,20 @@ discard block |
||
532 | 532 | * @throws ConstraintParameterException |
533 | 533 | * @return string[] |
534 | 534 | */ |
535 | - public function parseLanguageParameter( array $constraintParameters, $constraintTypeItemId ): array { |
|
536 | - $this->checkError( $constraintParameters ); |
|
537 | - $languagePropertyId = $this->config->get( 'WBQualityConstraintsLanguagePropertyId' ); |
|
538 | - if ( !array_key_exists( $languagePropertyId, $constraintParameters ) ) { |
|
535 | + public function parseLanguageParameter(array $constraintParameters, $constraintTypeItemId): array { |
|
536 | + $this->checkError($constraintParameters); |
|
537 | + $languagePropertyId = $this->config->get('WBQualityConstraintsLanguagePropertyId'); |
|
538 | + if (!array_key_exists($languagePropertyId, $constraintParameters)) { |
|
539 | 539 | throw new ConstraintParameterException( |
540 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
541 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
542 | - ->withEntityId( new NumericPropertyId( $languagePropertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
540 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
541 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
542 | + ->withEntityId(new NumericPropertyId($languagePropertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
543 | 543 | ); |
544 | 544 | } |
545 | 545 | |
546 | 546 | $languages = []; |
547 | - foreach ( $constraintParameters[$languagePropertyId] as $snak ) { |
|
548 | - $languages[] = $this->parseStringParameter( $snak, $languagePropertyId ); |
|
547 | + foreach ($constraintParameters[$languagePropertyId] as $snak) { |
|
548 | + $languages[] = $this->parseStringParameter($snak, $languagePropertyId); |
|
549 | 549 | } |
550 | 550 | return $languages; |
551 | 551 | } |
@@ -557,17 +557,17 @@ discard block |
||
557 | 557 | * @throws ConstraintParameterException |
558 | 558 | * @return string |
559 | 559 | */ |
560 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
561 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
562 | - $this->requireValueParameter( $snak, $parameterId ); |
|
560 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
561 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
562 | + $this->requireValueParameter($snak, $parameterId); |
|
563 | 563 | $value = $snak->getDataValue(); |
564 | - if ( $value instanceof StringValue ) { |
|
564 | + if ($value instanceof StringValue) { |
|
565 | 565 | return $value->getValue(); |
566 | 566 | } else { |
567 | 567 | throw new ConstraintParameterException( |
568 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) ) |
|
569 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
570 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
568 | + (new ViolationMessage('wbqc-violation-message-parameter-string')) |
|
569 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
570 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
571 | 571 | ); |
572 | 572 | } |
573 | 573 | } |
@@ -578,15 +578,15 @@ discard block |
||
578 | 578 | * @throws ConstraintParameterException if the parameter is invalid or missing |
579 | 579 | * @return string |
580 | 580 | */ |
581 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
582 | - $this->checkError( $constraintParameters ); |
|
583 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
584 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
581 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
582 | + $this->checkError($constraintParameters); |
|
583 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
584 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
585 | 585 | return ''; |
586 | 586 | } |
587 | 587 | |
588 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
589 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
588 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
589 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | /** |
@@ -595,19 +595,19 @@ discard block |
||
595 | 595 | * @throws ConstraintParameterException if the parameter is invalid or missing |
596 | 596 | * @return string |
597 | 597 | */ |
598 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
599 | - $this->checkError( $constraintParameters ); |
|
600 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
601 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
598 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
599 | + $this->checkError($constraintParameters); |
|
600 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
601 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
602 | 602 | throw new ConstraintParameterException( |
603 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
604 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
605 | - ->withEntityId( new NumericPropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
603 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
604 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
605 | + ->withEntityId(new NumericPropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
606 | 606 | ); |
607 | 607 | } |
608 | 608 | |
609 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
610 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
609 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
610 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | /** |
@@ -615,16 +615,16 @@ discard block |
||
615 | 615 | * @throws ConstraintParameterException if the parameter is invalid |
616 | 616 | * @return EntityId[] |
617 | 617 | */ |
618 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
619 | - $this->checkError( $constraintParameters ); |
|
620 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
621 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
618 | + public function parseExceptionParameter(array $constraintParameters) { |
|
619 | + $this->checkError($constraintParameters); |
|
620 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
621 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
622 | 622 | return []; |
623 | 623 | } |
624 | 624 | |
625 | 625 | return array_map( |
626 | - function ( $snakSerialization ) use ( $exceptionId ) { |
|
627 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
626 | + function($snakSerialization) use ($exceptionId) { |
|
627 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
628 | 628 | }, |
629 | 629 | $constraintParameters[$exceptionId] |
630 | 630 | ); |
@@ -635,39 +635,39 @@ discard block |
||
635 | 635 | * @throws ConstraintParameterException if the parameter is invalid |
636 | 636 | * @return string|null 'mandatory', 'suggestion' or null |
637 | 637 | */ |
638 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
639 | - $this->checkError( $constraintParameters ); |
|
640 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
641 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
638 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
639 | + $this->checkError($constraintParameters); |
|
640 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
641 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
642 | 642 | return null; |
643 | 643 | } |
644 | 644 | |
645 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
646 | - $supportedStatuses = [ new ItemId( $mandatoryId ) ]; |
|
647 | - if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) { |
|
648 | - $suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' ); |
|
649 | - $supportedStatuses[] = new ItemId( $suggestionId ); |
|
645 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
646 | + $supportedStatuses = [new ItemId($mandatoryId)]; |
|
647 | + if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) { |
|
648 | + $suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId'); |
|
649 | + $supportedStatuses[] = new ItemId($suggestionId); |
|
650 | 650 | } else { |
651 | 651 | $suggestionId = null; |
652 | 652 | } |
653 | 653 | |
654 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
655 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
656 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
654 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
655 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
656 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
657 | 657 | '@phan-var \Wikibase\DataModel\Snak\PropertyValueSnak $snak'; |
658 | 658 | $dataValue = $snak->getDataValue(); |
659 | 659 | '@phan-var EntityIdValue $dataValue'; |
660 | 660 | $entityId = $dataValue->getEntityId(); |
661 | 661 | $statusId = $entityId->getSerialization(); |
662 | 662 | |
663 | - if ( $statusId === $mandatoryId ) { |
|
663 | + if ($statusId === $mandatoryId) { |
|
664 | 664 | return 'mandatory'; |
665 | - } elseif ( $statusId === $suggestionId ) { |
|
665 | + } elseif ($statusId === $suggestionId) { |
|
666 | 666 | return 'suggestion'; |
667 | 667 | } else { |
668 | 668 | throw new ConstraintParameterException( |
669 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
670 | - ->withEntityId( new NumericPropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
669 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
670 | + ->withEntityId(new NumericPropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
671 | 671 | ->withEntityIdList( |
672 | 672 | $supportedStatuses, |
673 | 673 | Role::CONSTRAINT_PARAMETER_VALUE |
@@ -683,12 +683,12 @@ discard block |
||
683 | 683 | * @return void |
684 | 684 | * @throws ConstraintParameterException |
685 | 685 | */ |
686 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
687 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
686 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
687 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
688 | 688 | throw new ConstraintParameterException( |
689 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) ) |
|
690 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
691 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
689 | + (new ViolationMessage('wbqc-violation-message-parameter-monolingualtext')) |
|
690 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
691 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
692 | 692 | ); |
693 | 693 | } |
694 | 694 | } |
@@ -701,31 +701,31 @@ discard block |
||
701 | 701 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
702 | 702 | * @return MultilingualTextValue |
703 | 703 | */ |
704 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
704 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
705 | 705 | $result = []; |
706 | 706 | |
707 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
708 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
709 | - $this->requireValueParameter( $snak, $parameterId ); |
|
707 | + foreach ($snakSerializations as $snakSerialization) { |
|
708 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
709 | + $this->requireValueParameter($snak, $parameterId); |
|
710 | 710 | |
711 | 711 | $value = $snak->getDataValue(); |
712 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
712 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
713 | 713 | /** @var MonolingualTextValue $value */ |
714 | 714 | '@phan-var MonolingualTextValue $value'; |
715 | 715 | |
716 | 716 | $code = $value->getLanguageCode(); |
717 | - if ( array_key_exists( $code, $result ) ) { |
|
717 | + if (array_key_exists($code, $result)) { |
|
718 | 718 | throw new ConstraintParameterException( |
719 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) ) |
|
720 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
721 | - ->withLanguage( $code ) |
|
719 | + (new ViolationMessage('wbqc-violation-message-parameter-single-per-language')) |
|
720 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
721 | + ->withLanguage($code) |
|
722 | 722 | ); |
723 | 723 | } |
724 | 724 | |
725 | 725 | $result[$code] = $value; |
726 | 726 | } |
727 | 727 | |
728 | - return new MultilingualTextValue( $result ); |
|
728 | + return new MultilingualTextValue($result); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | /** |
@@ -733,11 +733,11 @@ discard block |
||
733 | 733 | * @throws ConstraintParameterException if the parameter is invalid |
734 | 734 | * @return MultilingualTextValue |
735 | 735 | */ |
736 | - public function parseSyntaxClarificationParameter( array $constraintParameters ) { |
|
737 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
736 | + public function parseSyntaxClarificationParameter(array $constraintParameters) { |
|
737 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
738 | 738 | |
739 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
740 | - return new MultilingualTextValue( [] ); |
|
739 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
740 | + return new MultilingualTextValue([]); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -770,14 +770,14 @@ discard block |
||
770 | 770 | array $validContextTypes, |
771 | 771 | array $validEntityTypes |
772 | 772 | ): array { |
773 | - $contextTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
773 | + $contextTypeParameterId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
774 | 774 | $contextTypeItemIds = $this->parseItemIdsParameter( |
775 | 775 | $constraintParameters, |
776 | 776 | $constraintTypeItemId, |
777 | 777 | false, |
778 | 778 | $contextTypeParameterId |
779 | 779 | ); |
780 | - $entityTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintEntityTypesId' ); |
|
780 | + $entityTypeParameterId = $this->config->get('WBQualityConstraintsConstraintEntityTypesId'); |
|
781 | 781 | $entityTypeItemIds = $this->parseItemIdsParameter( |
782 | 782 | $constraintParameters, |
783 | 783 | $constraintTypeItemId, |
@@ -793,26 +793,26 @@ discard block |
||
793 | 793 | $contextTypes = null; |
794 | 794 | $entityTypes = null; |
795 | 795 | |
796 | - if ( $contextTypeParameterId === $entityTypeParameterId ) { |
|
796 | + if ($contextTypeParameterId === $entityTypeParameterId) { |
|
797 | 797 | $itemIds = $contextTypeItemIds; |
798 | 798 | $mapping = $contextTypeMapping + $entityTypeMapping; |
799 | - foreach ( $itemIds as $itemId ) { |
|
800 | - $mapped = $this->mapItemId( $itemId, $mapping, $contextTypeParameterId ); |
|
801 | - if ( in_array( $mapped, $contextTypeMapping, true ) ) { |
|
799 | + foreach ($itemIds as $itemId) { |
|
800 | + $mapped = $this->mapItemId($itemId, $mapping, $contextTypeParameterId); |
|
801 | + if (in_array($mapped, $contextTypeMapping, true)) { |
|
802 | 802 | $contextTypes[] = $mapped; |
803 | 803 | } else { |
804 | 804 | $entityTypes[] = $mapped; |
805 | 805 | } |
806 | 806 | } |
807 | 807 | } else { |
808 | - foreach ( $contextTypeItemIds as $contextTypeItemId ) { |
|
808 | + foreach ($contextTypeItemIds as $contextTypeItemId) { |
|
809 | 809 | $contextTypes[] = $this->mapItemId( |
810 | 810 | $contextTypeItemId, |
811 | 811 | $contextTypeMapping, |
812 | 812 | $contextTypeParameterId |
813 | 813 | ); |
814 | 814 | } |
815 | - foreach ( $entityTypeItemIds as $entityTypeItemId ) { |
|
815 | + foreach ($entityTypeItemIds as $entityTypeItemId) { |
|
816 | 816 | $entityTypes[] = $this->mapItemId( |
817 | 817 | $entityTypeItemId, |
818 | 818 | $entityTypeMapping, |
@@ -821,21 +821,21 @@ discard block |
||
821 | 821 | } |
822 | 822 | } |
823 | 823 | |
824 | - $this->checkValidScope( $constraintTypeItemId, $contextTypes, $validContextTypes ); |
|
825 | - $this->checkValidScope( $constraintTypeItemId, $entityTypes, $validEntityTypes ); |
|
824 | + $this->checkValidScope($constraintTypeItemId, $contextTypes, $validContextTypes); |
|
825 | + $this->checkValidScope($constraintTypeItemId, $entityTypes, $validEntityTypes); |
|
826 | 826 | |
827 | - return [ $contextTypes, $entityTypes ]; |
|
827 | + return [$contextTypes, $entityTypes]; |
|
828 | 828 | } |
829 | 829 | |
830 | - private function checkValidScope( string $constraintTypeItemId, ?array $types, array $validTypes ): void { |
|
831 | - $invalidTypes = array_diff( $types ?: [], $validTypes ); |
|
832 | - if ( $invalidTypes !== [] ) { |
|
833 | - $invalidType = array_pop( $invalidTypes ); |
|
830 | + private function checkValidScope(string $constraintTypeItemId, ?array $types, array $validTypes): void { |
|
831 | + $invalidTypes = array_diff($types ?: [], $validTypes); |
|
832 | + if ($invalidTypes !== []) { |
|
833 | + $invalidType = array_pop($invalidTypes); |
|
834 | 834 | throw new ConstraintParameterException( |
835 | - ( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) ) |
|
836 | - ->withConstraintScope( $invalidType, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
837 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
838 | - ->withConstraintScopeList( $validTypes, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
835 | + (new ViolationMessage('wbqc-violation-message-invalid-scope')) |
|
836 | + ->withConstraintScope($invalidType, Role::CONSTRAINT_PARAMETER_VALUE) |
|
837 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
838 | + ->withConstraintScopeList($validTypes, Role::CONSTRAINT_PARAMETER_VALUE) |
|
839 | 839 | ); |
840 | 840 | } |
841 | 841 | } |
@@ -846,8 +846,8 @@ discard block |
||
846 | 846 | * @param ItemId $unitId |
847 | 847 | * @return string unit |
848 | 848 | */ |
849 | - private function parseUnitParameter( ItemId $unitId ) { |
|
850 | - return $this->unitItemConceptBaseUri . $unitId->getSerialization(); |
|
849 | + private function parseUnitParameter(ItemId $unitId) { |
|
850 | + return $this->unitItemConceptBaseUri.$unitId->getSerialization(); |
|
851 | 851 | } |
852 | 852 | |
853 | 853 | /** |
@@ -857,23 +857,23 @@ discard block |
||
857 | 857 | * @return UnitsParameter |
858 | 858 | * @throws ConstraintParameterException |
859 | 859 | */ |
860 | - private function parseUnitItem( ItemIdSnakValue $item ) { |
|
861 | - switch ( true ) { |
|
860 | + private function parseUnitItem(ItemIdSnakValue $item) { |
|
861 | + switch (true) { |
|
862 | 862 | case $item->isValue(): |
863 | - $unit = $this->parseUnitParameter( $item->getItemId() ); |
|
863 | + $unit = $this->parseUnitParameter($item->getItemId()); |
|
864 | 864 | return new UnitsParameter( |
865 | - [ $item->getItemId() ], |
|
866 | - [ UnboundedQuantityValue::newFromNumber( 1, $unit ) ], |
|
865 | + [$item->getItemId()], |
|
866 | + [UnboundedQuantityValue::newFromNumber(1, $unit)], |
|
867 | 867 | false |
868 | 868 | ); |
869 | 869 | case $item->isSomeValue(): |
870 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
870 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
871 | 871 | throw new ConstraintParameterException( |
872 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
873 | - ->withEntityId( new NumericPropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
872 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
873 | + ->withEntityId(new NumericPropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
874 | 874 | ); |
875 | 875 | case $item->isNoValue(): |
876 | - return new UnitsParameter( [], [], true ); |
|
876 | + return new UnitsParameter([], [], true); |
|
877 | 877 | } |
878 | 878 | } |
879 | 879 | |
@@ -883,36 +883,36 @@ discard block |
||
883 | 883 | * @throws ConstraintParameterException if the parameter is invalid or missing |
884 | 884 | * @return UnitsParameter |
885 | 885 | */ |
886 | - public function parseUnitsParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
887 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
886 | + public function parseUnitsParameter(array $constraintParameters, $constraintTypeItemId) { |
|
887 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
888 | 888 | $unitItems = []; |
889 | 889 | $unitQuantities = []; |
890 | 890 | $unitlessAllowed = false; |
891 | 891 | |
892 | - foreach ( $items as $item ) { |
|
893 | - $unit = $this->parseUnitItem( $item ); |
|
894 | - $unitItems = array_merge( $unitItems, $unit->getUnitItemIds() ); |
|
895 | - $unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() ); |
|
892 | + foreach ($items as $item) { |
|
893 | + $unit = $this->parseUnitItem($item); |
|
894 | + $unitItems = array_merge($unitItems, $unit->getUnitItemIds()); |
|
895 | + $unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities()); |
|
896 | 896 | $unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed(); |
897 | 897 | } |
898 | 898 | |
899 | - if ( $unitQuantities === [] && !$unitlessAllowed ) { |
|
899 | + if ($unitQuantities === [] && !$unitlessAllowed) { |
|
900 | 900 | throw new LogicException( |
901 | 901 | 'The "units" parameter is required, and yet we seem to be missing any allowed unit' |
902 | 902 | ); |
903 | 903 | } |
904 | 904 | |
905 | - return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed ); |
|
905 | + return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | private function getEntityTypeMapping(): array { |
909 | 909 | return [ |
910 | - $this->config->get( 'WBQualityConstraintsWikibaseItemId' ) => 'item', |
|
911 | - $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) => 'property', |
|
912 | - $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) => 'lexeme', |
|
913 | - $this->config->get( 'WBQualityConstraintsWikibaseFormId' ) => 'form', |
|
914 | - $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) => 'sense', |
|
915 | - $this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ) => 'mediainfo', |
|
910 | + $this->config->get('WBQualityConstraintsWikibaseItemId') => 'item', |
|
911 | + $this->config->get('WBQualityConstraintsWikibasePropertyId') => 'property', |
|
912 | + $this->config->get('WBQualityConstraintsWikibaseLexemeId') => 'lexeme', |
|
913 | + $this->config->get('WBQualityConstraintsWikibaseFormId') => 'form', |
|
914 | + $this->config->get('WBQualityConstraintsWikibaseSenseId') => 'sense', |
|
915 | + $this->config->get('WBQualityConstraintsWikibaseMediaInfoId') => 'mediainfo', |
|
916 | 916 | ]; |
917 | 917 | } |
918 | 918 | |
@@ -922,10 +922,10 @@ discard block |
||
922 | 922 | * @throws ConstraintParameterException if the parameter is invalid or missing |
923 | 923 | * @return EntityTypesParameter |
924 | 924 | */ |
925 | - public function parseEntityTypesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
925 | + public function parseEntityTypesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
926 | 926 | $entityTypes = []; |
927 | 927 | $entityTypeItemIds = []; |
928 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
928 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
929 | 929 | $itemIds = $this->parseItemIdsParameter( |
930 | 930 | $constraintParameters, |
931 | 931 | $constraintTypeItemId, |
@@ -934,22 +934,22 @@ discard block |
||
934 | 934 | ); |
935 | 935 | |
936 | 936 | $mapping = $this->getEntityTypeMapping(); |
937 | - foreach ( $itemIds as $itemId ) { |
|
938 | - $entityType = $this->mapItemId( $itemId, $mapping, $parameterId ); |
|
937 | + foreach ($itemIds as $itemId) { |
|
938 | + $entityType = $this->mapItemId($itemId, $mapping, $parameterId); |
|
939 | 939 | $entityTypes[] = $entityType; |
940 | 940 | $entityTypeItemIds[] = $itemId; |
941 | 941 | } |
942 | 942 | |
943 | - if ( empty( $entityTypes ) ) { |
|
943 | + if (empty($entityTypes)) { |
|
944 | 944 | // @codeCoverageIgnoreStart |
945 | 945 | throw new LogicException( |
946 | - 'The "entity types" parameter is required, ' . |
|
946 | + 'The "entity types" parameter is required, '. |
|
947 | 947 | 'and yet we seem to be missing any allowed entity type' |
948 | 948 | ); |
949 | 949 | // @codeCoverageIgnoreEnd |
950 | 950 | } |
951 | 951 | |
952 | - return new EntityTypesParameter( $entityTypes, $entityTypeItemIds ); |
|
952 | + return new EntityTypesParameter($entityTypes, $entityTypeItemIds); |
|
953 | 953 | } |
954 | 954 | |
955 | 955 | /** |
@@ -957,18 +957,18 @@ discard block |
||
957 | 957 | * @throws ConstraintParameterException if the parameter is invalid |
958 | 958 | * @return PropertyId[] |
959 | 959 | */ |
960 | - public function parseSeparatorsParameter( array $constraintParameters ) { |
|
961 | - $separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' ); |
|
960 | + public function parseSeparatorsParameter(array $constraintParameters) { |
|
961 | + $separatorId = $this->config->get('WBQualityConstraintsSeparatorId'); |
|
962 | 962 | |
963 | - if ( !array_key_exists( $separatorId, $constraintParameters ) ) { |
|
963 | + if (!array_key_exists($separatorId, $constraintParameters)) { |
|
964 | 964 | return []; |
965 | 965 | } |
966 | 966 | |
967 | 967 | $parameters = $constraintParameters[$separatorId]; |
968 | 968 | $separators = []; |
969 | 969 | |
970 | - foreach ( $parameters as $parameter ) { |
|
971 | - $separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId ); |
|
970 | + foreach ($parameters as $parameter) { |
|
971 | + $separators[] = $this->parsePropertyIdParameter($parameter, $separatorId); |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | return $separators; |
@@ -976,17 +976,17 @@ discard block |
||
976 | 976 | |
977 | 977 | private function getConstraintScopeContextTypeMapping(): array { |
978 | 978 | return [ |
979 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ) => Context::TYPE_STATEMENT, |
|
980 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ) => Context::TYPE_QUALIFIER, |
|
981 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ) => Context::TYPE_REFERENCE, |
|
979 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId') => Context::TYPE_STATEMENT, |
|
980 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId') => Context::TYPE_QUALIFIER, |
|
981 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId') => Context::TYPE_REFERENCE, |
|
982 | 982 | ]; |
983 | 983 | } |
984 | 984 | |
985 | 985 | private function getPropertyScopeContextTypeMapping(): array { |
986 | 986 | return [ |
987 | - $this->config->get( 'WBQualityConstraintsAsMainValueId' ) => Context::TYPE_STATEMENT, |
|
988 | - $this->config->get( 'WBQualityConstraintsAsQualifiersId' ) => Context::TYPE_QUALIFIER, |
|
989 | - $this->config->get( 'WBQualityConstraintsAsReferencesId' ) => Context::TYPE_REFERENCE, |
|
987 | + $this->config->get('WBQualityConstraintsAsMainValueId') => Context::TYPE_STATEMENT, |
|
988 | + $this->config->get('WBQualityConstraintsAsQualifiersId') => Context::TYPE_QUALIFIER, |
|
989 | + $this->config->get('WBQualityConstraintsAsReferencesId') => Context::TYPE_REFERENCE, |
|
990 | 990 | ]; |
991 | 991 | } |
992 | 992 | |
@@ -996,9 +996,9 @@ discard block |
||
996 | 996 | * @throws ConstraintParameterException if the parameter is invalid or missing |
997 | 997 | * @return string[] list of Context::TYPE_* constants |
998 | 998 | */ |
999 | - public function parsePropertyScopeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
999 | + public function parsePropertyScopeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
1000 | 1000 | $contextTypes = []; |
1001 | - $parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' ); |
|
1001 | + $parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId'); |
|
1002 | 1002 | $itemIds = $this->parseItemIdsParameter( |
1003 | 1003 | $constraintParameters, |
1004 | 1004 | $constraintTypeItemId, |
@@ -1007,14 +1007,14 @@ discard block |
||
1007 | 1007 | ); |
1008 | 1008 | |
1009 | 1009 | $mapping = $this->getPropertyScopeContextTypeMapping(); |
1010 | - foreach ( $itemIds as $itemId ) { |
|
1011 | - $contextTypes[] = $this->mapItemId( $itemId, $mapping, $parameterId ); |
|
1010 | + foreach ($itemIds as $itemId) { |
|
1011 | + $contextTypes[] = $this->mapItemId($itemId, $mapping, $parameterId); |
|
1012 | 1012 | } |
1013 | 1013 | |
1014 | - if ( empty( $contextTypes ) ) { |
|
1014 | + if (empty($contextTypes)) { |
|
1015 | 1015 | // @codeCoverageIgnoreStart |
1016 | 1016 | throw new LogicException( |
1017 | - 'The "property scope" parameter is required, ' . |
|
1017 | + 'The "property scope" parameter is required, '. |
|
1018 | 1018 | 'and yet we seem to be missing any allowed scope' |
1019 | 1019 | ); |
1020 | 1020 | // @codeCoverageIgnoreEnd |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | * @throws ConstraintParameterException |
74 | 74 | * @return array [ DataValue|null $min, DataValue|null $max, NumericPropertyId $property, array $parameters ] |
75 | 75 | */ |
76 | - private function parseConstraintParameters( Constraint $constraint ) { |
|
77 | - list( $min, $max ) = $this->constraintParameterParser->parseQuantityRangeParameter( |
|
76 | + private function parseConstraintParameters(Constraint $constraint) { |
|
77 | + list($min, $max) = $this->constraintParameterParser->parseQuantityRangeParameter( |
|
78 | 78 | $constraint->getConstraintParameters(), |
79 | 79 | $constraint->getConstraintTypeItemId() |
80 | 80 | ); |
@@ -84,15 +84,15 @@ discard block |
||
84 | 84 | ); |
85 | 85 | |
86 | 86 | $parameters = []; |
87 | - if ( $min !== null ) { |
|
88 | - $parameters['minimum_quantity'] = [ $min ]; |
|
87 | + if ($min !== null) { |
|
88 | + $parameters['minimum_quantity'] = [$min]; |
|
89 | 89 | } |
90 | - if ( $max !== null ) { |
|
91 | - $parameters['maximum_quantity'] = [ $max ]; |
|
90 | + if ($max !== null) { |
|
91 | + $parameters['maximum_quantity'] = [$max]; |
|
92 | 92 | } |
93 | - $parameters['property'] = [ $property ]; |
|
93 | + $parameters['property'] = [$property]; |
|
94 | 94 | |
95 | - return [ $min, $max, $property, $parameters ]; |
|
95 | + return [$min, $max, $property, $parameters]; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @return bool |
104 | 104 | */ |
105 | - private function rangeInYears( $min, $max ) { |
|
106 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
105 | + private function rangeInYears($min, $max) { |
|
106 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
107 | 107 | |
108 | - if ( $min !== null && $min->getUnit() === $yearUnit ) { |
|
108 | + if ($min !== null && $min->getUnit() === $yearUnit) { |
|
109 | 109 | return true; |
110 | 110 | } |
111 | - if ( $max !== null && $max->getUnit() === $yearUnit ) { |
|
111 | + if ($max !== null && $max->getUnit() === $yearUnit) { |
|
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | |
@@ -124,30 +124,30 @@ discard block |
||
124 | 124 | * @throws ConstraintParameterException |
125 | 125 | * @return CheckResult |
126 | 126 | */ |
127 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
128 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
129 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
127 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
128 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
129 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | $parameters = []; |
133 | 133 | |
134 | 134 | $snak = $context->getSnak(); |
135 | 135 | |
136 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
136 | + if (!$snak instanceof PropertyValueSnak) { |
|
137 | 137 | // nothing to check |
138 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
138 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $minuend = $snak->getDataValue(); |
142 | 142 | '@phan-var \DataValues\TimeValue|\DataValues\QuantityValue|\DataValues\UnboundedQuantityValue $minuend'; |
143 | 143 | |
144 | 144 | /** @var NumericPropertyId $property */ |
145 | - list( $min, $max, $property, $parameters ) = $this->parseConstraintParameters( $constraint ); |
|
145 | + list($min, $max, $property, $parameters) = $this->parseConstraintParameters($constraint); |
|
146 | 146 | |
147 | 147 | // checks only the first occurrence of the referenced property |
148 | - foreach ( $context->getSnakGroup( Context::GROUP_NON_DEPRECATED ) as $otherSnak ) { |
|
148 | + foreach ($context->getSnakGroup(Context::GROUP_NON_DEPRECATED) as $otherSnak) { |
|
149 | 149 | if ( |
150 | - !$property->equals( $otherSnak->getPropertyId() ) || |
|
150 | + !$property->equals($otherSnak->getPropertyId()) || |
|
151 | 151 | !$otherSnak instanceof PropertyValueSnak |
152 | 152 | ) { |
153 | 153 | continue; |
@@ -155,30 +155,29 @@ discard block |
||
155 | 155 | |
156 | 156 | $subtrahend = $otherSnak->getDataValue(); |
157 | 157 | '@phan-var \DataValues\TimeValue|\DataValues\QuantityValue|\DataValues\UnboundedQuantityValue $subtrahend'; |
158 | - if ( $subtrahend->getType() === $minuend->getType() ) { |
|
159 | - $diff = $this->rangeInYears( $min, $max ) && $minuend->getType() === 'time' ? |
|
160 | - $this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) : |
|
161 | - $this->rangeCheckerHelper->getDifference( $minuend, $subtrahend ); |
|
158 | + if ($subtrahend->getType() === $minuend->getType()) { |
|
159 | + $diff = $this->rangeInYears($min, $max) && $minuend->getType() === 'time' ? |
|
160 | + $this->rangeCheckerHelper->getDifferenceInYears($minuend, $subtrahend) : $this->rangeCheckerHelper->getDifference($minuend, $subtrahend); |
|
162 | 161 | |
163 | - if ( $this->rangeCheckerHelper->getComparison( $min, $diff ) > 0 || |
|
164 | - $this->rangeCheckerHelper->getComparison( $diff, $max ) > 0 |
|
162 | + if ($this->rangeCheckerHelper->getComparison($min, $diff) > 0 || |
|
163 | + $this->rangeCheckerHelper->getComparison($diff, $max) > 0 |
|
165 | 164 | ) { |
166 | 165 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
167 | - $openness = $min !== null ? ( $max !== null ? '' : '-rightopen' ) : '-leftopen'; |
|
166 | + $openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen'; |
|
168 | 167 | // possible message keys: |
169 | 168 | // wbqc-violation-message-diff-within-range |
170 | 169 | // wbqc-violation-message-diff-within-range-leftopen |
171 | 170 | // wbqc-violation-message-diff-within-range-rightopen |
172 | - $message = ( new ViolationMessage( "wbqc-violation-message-diff-within-range$openness" ) ) |
|
173 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
174 | - ->withDataValue( $minuend, Role::OBJECT ) |
|
175 | - ->withEntityId( $otherSnak->getPropertyId(), Role::PREDICATE ) |
|
176 | - ->withDataValue( $subtrahend, Role::OBJECT ); |
|
177 | - if ( $min !== null ) { |
|
178 | - $message = $message->withDataValue( $min, Role::OBJECT ); |
|
171 | + $message = (new ViolationMessage("wbqc-violation-message-diff-within-range$openness")) |
|
172 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
173 | + ->withDataValue($minuend, Role::OBJECT) |
|
174 | + ->withEntityId($otherSnak->getPropertyId(), Role::PREDICATE) |
|
175 | + ->withDataValue($subtrahend, Role::OBJECT); |
|
176 | + if ($min !== null) { |
|
177 | + $message = $message->withDataValue($min, Role::OBJECT); |
|
179 | 178 | } |
180 | - if ( $max !== null ) { |
|
181 | - $message = $message->withDataValue( $max, Role::OBJECT ); |
|
179 | + if ($max !== null) { |
|
180 | + $message = $message->withDataValue($max, Role::OBJECT); |
|
182 | 181 | } |
183 | 182 | $status = CheckResult::STATUS_VIOLATION; |
184 | 183 | } else { |
@@ -186,17 +185,17 @@ discard block |
||
186 | 185 | $status = CheckResult::STATUS_COMPLIANCE; |
187 | 186 | } |
188 | 187 | } else { |
189 | - $message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-must-have-equal-types' ); |
|
188 | + $message = new ViolationMessage('wbqc-violation-message-diff-within-range-must-have-equal-types'); |
|
190 | 189 | $status = CheckResult::STATUS_VIOLATION; |
191 | 190 | } |
192 | 191 | |
193 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
192 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
194 | 193 | } |
195 | 194 | |
196 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
195 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
197 | 196 | } |
198 | 197 | |
199 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
198 | + public function checkConstraintParameters(Constraint $constraint) { |
|
200 | 199 | $constraintParameters = $constraint->getConstraintParameters(); |
201 | 200 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
202 | 201 | $exceptions = []; |
@@ -205,7 +204,7 @@ discard block |
||
205 | 204 | $constraintParameters, |
206 | 205 | $constraintTypeItemId |
207 | 206 | ); |
208 | - } catch ( ConstraintParameterException $e ) { |
|
207 | + } catch (ConstraintParameterException $e) { |
|
209 | 208 | $exceptions[] = $e; |
210 | 209 | } |
211 | 210 | try { |
@@ -213,7 +212,7 @@ discard block |
||
213 | 212 | $constraintParameters, |
214 | 213 | $constraintTypeItemId |
215 | 214 | ); |
216 | - } catch ( ConstraintParameterException $e ) { |
|
215 | + } catch (ConstraintParameterException $e) { |
|
217 | 216 | $exceptions[] = $e; |
218 | 217 | } |
219 | 218 | return $exceptions; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @codeCoverageIgnore This method is purely declarative. |
80 | 80 | */ |
81 | 81 | public function getDefaultContextTypes() { |
82 | - return [ Context::TYPE_STATEMENT ]; |
|
82 | + return [Context::TYPE_STATEMENT]; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** @codeCoverageIgnore This method is purely declarative. */ |
@@ -96,31 +96,31 @@ discard block |
||
96 | 96 | * @return CheckResult |
97 | 97 | * @throws \ConfigException |
98 | 98 | */ |
99 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
100 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
101 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
99 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
100 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
101 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
102 | 102 | } |
103 | 103 | $snak = $context->getSnak(); |
104 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
104 | + if (!$snak instanceof PropertyValueSnak) { |
|
105 | 105 | // nothing to check |
106 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
106 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | $dataValue = $snak->getDataValue(); |
110 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
110 | + if (!$dataValue instanceof EntityIdValue) { |
|
111 | 111 | // wrong data type |
112 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
113 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
114 | - ->withDataValueType( 'wikibase-entityid' ); |
|
115 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
112 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
113 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
114 | + ->withDataValueType('wikibase-entityid'); |
|
115 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $objectId = $dataValue->getEntityId(); |
119 | - $objectItem = $this->entityLookup->getEntity( $objectId ); |
|
120 | - if ( !( $objectItem instanceof StatementListProvider ) ) { |
|
119 | + $objectItem = $this->entityLookup->getEntity($objectId); |
|
120 | + if (!($objectItem instanceof StatementListProvider)) { |
|
121 | 121 | // object was deleted/doesn't exist |
122 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
123 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
122 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
123 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
124 | 124 | } |
125 | 125 | /** @var Statement[] $objectStatements */ |
126 | 126 | $objectStatements = $objectItem->getStatements()->toArray(); |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | $subjectId = $context->getEntity()->getId(); |
129 | 129 | $subjectStatements = $context->getEntity()->getStatements()->toArray(); |
130 | 130 | /** @var String[] $startPropertyIds */ |
131 | - $startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS ); |
|
131 | + $startPropertyIds = $this->config->get(self::CONFIG_VARIABLE_START_PROPERTY_IDS); |
|
132 | 132 | /** @var String[] $endPropertyIds */ |
133 | - $endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS ); |
|
133 | + $endPropertyIds = $this->config->get(self::CONFIG_VARIABLE_END_PROPERTY_IDS); |
|
134 | 134 | $subjectStartValue = $this->getExtremeValue( |
135 | 135 | $startPropertyIds, |
136 | 136 | $subjectStatements, |
@@ -152,15 +152,15 @@ discard block |
||
152 | 152 | 'end' |
153 | 153 | ); |
154 | 154 | if ( |
155 | - $this->rangeCheckerHelper->getComparison( $subjectStartValue, $subjectEndValue ) <= 0 && |
|
156 | - $this->rangeCheckerHelper->getComparison( $objectStartValue, $objectEndValue ) <= 0 && ( |
|
157 | - $this->rangeCheckerHelper->getComparison( $subjectEndValue, $objectStartValue ) < 0 || |
|
158 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectStartValue ) < 0 |
|
155 | + $this->rangeCheckerHelper->getComparison($subjectStartValue, $subjectEndValue) <= 0 && |
|
156 | + $this->rangeCheckerHelper->getComparison($objectStartValue, $objectEndValue) <= 0 && ( |
|
157 | + $this->rangeCheckerHelper->getComparison($subjectEndValue, $objectStartValue) < 0 || |
|
158 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectStartValue) < 0 |
|
159 | 159 | ) |
160 | 160 | ) { |
161 | 161 | if ( |
162 | 162 | $subjectEndValue == null || |
163 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectEndValue ) < 0 |
|
163 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectEndValue) < 0 |
|
164 | 164 | ) { |
165 | 165 | $earlierEntityId = $objectId; |
166 | 166 | $minEndValue = $objectEndValue; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $message = null; |
184 | 184 | $status = CheckResult::STATUS_COMPLIANCE; |
185 | 185 | } |
186 | - return new CheckResult( $context, $constraint, [], $status, $message ); |
|
186 | + return new CheckResult($context, $constraint, [], $status, $message); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @return DataValue|null |
195 | 195 | */ |
196 | - private function getExtremeValue( $extremePropertyIds, $statements, $startOrEnd ) { |
|
197 | - if ( $startOrEnd !== 'start' && $startOrEnd !== 'end' ) { |
|
198 | - throw new \InvalidArgumentException( '$startOrEnd must be \'start\' or \'end\'.' ); |
|
196 | + private function getExtremeValue($extremePropertyIds, $statements, $startOrEnd) { |
|
197 | + if ($startOrEnd !== 'start' && $startOrEnd !== 'end') { |
|
198 | + throw new \InvalidArgumentException('$startOrEnd must be \'start\' or \'end\'.'); |
|
199 | 199 | } |
200 | 200 | $extremeValue = null; |
201 | - foreach ( $extremePropertyIds as $extremePropertyId ) { |
|
202 | - $statementList = new StatementList( ...$statements ); |
|
203 | - $extremeStatements = $statementList->getByPropertyId( new NumericPropertyId( $extremePropertyId ) ); |
|
201 | + foreach ($extremePropertyIds as $extremePropertyId) { |
|
202 | + $statementList = new StatementList(...$statements); |
|
203 | + $extremeStatements = $statementList->getByPropertyId(new NumericPropertyId($extremePropertyId)); |
|
204 | 204 | /** @var Statement $extremeStatement */ |
205 | - foreach ( $extremeStatements as $extremeStatement ) { |
|
206 | - if ( $extremeStatement->getRank() !== Statement::RANK_DEPRECATED ) { |
|
205 | + foreach ($extremeStatements as $extremeStatement) { |
|
206 | + if ($extremeStatement->getRank() !== Statement::RANK_DEPRECATED) { |
|
207 | 207 | $snak = $extremeStatement->getMainSnak(); |
208 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
208 | + if (!$snak instanceof PropertyValueSnak) { |
|
209 | 209 | return null; |
210 | 210 | } else { |
211 | 211 | $comparison = $this->rangeCheckerHelper->getComparison( |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | ); |
215 | 215 | if ( |
216 | 216 | $extremeValue === null || |
217 | - ( $startOrEnd === 'start' && $comparison < 0 ) || |
|
218 | - ( $startOrEnd === 'end' && $comparison > 0 ) |
|
217 | + ($startOrEnd === 'start' && $comparison < 0) || |
|
218 | + ($startOrEnd === 'end' && $comparison > 0) |
|
219 | 219 | ) { |
220 | 220 | $extremeValue = $snak->getDataValue(); |
221 | 221 | } |
@@ -245,17 +245,16 @@ discard block |
||
245 | 245 | DataValue $maxStartValue |
246 | 246 | ) { |
247 | 247 | $messageKey = $earlierEntityId === $subjectId ? |
248 | - 'wbqc-violation-message-contemporary-subject-earlier' : |
|
249 | - 'wbqc-violation-message-contemporary-value-earlier'; |
|
250 | - return ( new ViolationMessage( $messageKey ) ) |
|
251 | - ->withEntityId( $subjectId, Role::SUBJECT ) |
|
252 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
253 | - ->withEntityId( $objectId, Role::OBJECT ) |
|
254 | - ->withDataValue( $minEndValue, Role::OBJECT ) |
|
255 | - ->withDataValue( $maxStartValue, Role::OBJECT ); |
|
248 | + 'wbqc-violation-message-contemporary-subject-earlier' : 'wbqc-violation-message-contemporary-value-earlier'; |
|
249 | + return (new ViolationMessage($messageKey)) |
|
250 | + ->withEntityId($subjectId, Role::SUBJECT) |
|
251 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
252 | + ->withEntityId($objectId, Role::OBJECT) |
|
253 | + ->withDataValue($minEndValue, Role::OBJECT) |
|
254 | + ->withDataValue($maxStartValue, Role::OBJECT); |
|
256 | 255 | } |
257 | 256 | |
258 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
257 | + public function checkConstraintParameters(Constraint $constraint) { |
|
259 | 258 | // no parameters |
260 | 259 | return []; |
261 | 260 | } |