@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | * @param CachedCheckResults $checkResults |
52 | 52 | * @return CachedCheckConstraintsResponse |
53 | 53 | */ |
54 | - public function render( CachedCheckResults $checkResults ) { |
|
54 | + public function render(CachedCheckResults $checkResults) { |
|
55 | 55 | $response = []; |
56 | - foreach ( $checkResults->getArray() as $checkResult ) { |
|
57 | - $resultArray = $this->checkResultToArray( $checkResult ); |
|
58 | - $checkResult->getContextCursor()->storeCheckResultInArray( $resultArray, $response ); |
|
56 | + foreach ($checkResults->getArray() as $checkResult) { |
|
57 | + $resultArray = $this->checkResultToArray($checkResult); |
|
58 | + $checkResult->getContextCursor()->storeCheckResultInArray($resultArray, $response); |
|
59 | 59 | } |
60 | 60 | return new CachedCheckConstraintsResponse( |
61 | 61 | $response, |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | ); |
64 | 64 | } |
65 | 65 | |
66 | - public function checkResultToArray( CheckResult $checkResult ) { |
|
67 | - if ( $checkResult instanceof NullResult ) { |
|
66 | + public function checkResultToArray(CheckResult $checkResult) { |
|
67 | + if ($checkResult instanceof NullResult) { |
|
68 | 68 | return null; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $constraintId = $checkResult->getConstraint()->getConstraintId(); |
72 | 72 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
73 | - $constraintPropertyId = new PropertyId( $checkResult->getContextCursor()->getSnakPropertyId() ); |
|
73 | + $constraintPropertyId = new PropertyId($checkResult->getContextCursor()->getSnakPropertyId()); |
|
74 | 74 | |
75 | - $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
75 | + $title = $this->entityTitleLookup->getTitleForId($constraintPropertyId); |
|
76 | 76 | $talkTitle = $title->getTalkPageIfDefined(); |
77 | - $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
78 | - $link = $title->getFullURL() . '#' . $constraintId; |
|
77 | + $typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId)); |
|
78 | + $link = $title->getFullURL().'#'.$constraintId; |
|
79 | 79 | |
80 | 80 | $constraint = [ |
81 | 81 | 'id' => $constraintId, |
@@ -91,14 +91,14 @@ discard block |
||
91 | 91 | 'constraint' => $constraint |
92 | 92 | ]; |
93 | 93 | $message = $checkResult->getMessage(); |
94 | - if ( $message ) { |
|
95 | - $result['message-html'] = $this->violationMessageRenderer->render( $message ); |
|
94 | + if ($message) { |
|
95 | + $result['message-html'] = $this->violationMessageRenderer->render($message); |
|
96 | 96 | } |
97 | - if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) { |
|
97 | + if ($checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT) { |
|
98 | 98 | $result['claim'] = $checkResult->getContextCursor()->getStatementGuid(); |
99 | 99 | } |
100 | 100 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
101 | - if ( $cachingMetadataArray !== null ) { |
|
101 | + if ($cachingMetadataArray !== null) { |
|
102 | 102 | $result['cached'] = $cachingMetadataArray; |
103 | 103 | } |
104 | 104 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @return bool |
17 | 17 | * @throws DBUnexpectedError |
18 | 18 | */ |
19 | - public function insertBatch( array $constraints ); |
|
19 | + public function insertBatch(array $constraints); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Delete all constraints for the property ID. |
@@ -25,6 +25,6 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @throws DBUnexpectedError |
27 | 27 | */ |
28 | - public function deleteForProperty( PropertyId $propertyId ); |
|
28 | + public function deleteForProperty(PropertyId $propertyId); |
|
29 | 29 | |
30 | 30 | } |
@@ -24,16 +24,16 @@ discard block |
||
24 | 24 | * then using the main DBLoadBalancer service may be incorrect. |
25 | 25 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
26 | 26 | */ |
27 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
27 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
28 | 28 | $this->lb = $lb; |
29 | 29 | $this->dbName = $dbName; |
30 | 30 | } |
31 | 31 | |
32 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
33 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
32 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
33 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
34 | 34 | |
35 | - if ( strlen( $json ) > 50000 ) { |
|
36 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
35 | + if (strlen($json) > 50000) { |
|
36 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | return $json; |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | * @throws DBUnexpectedError |
46 | 46 | * @return bool |
47 | 47 | */ |
48 | - public function insertBatch( array $constraints ) { |
|
48 | + public function insertBatch(array $constraints) { |
|
49 | 49 | $accumulator = array_map( |
50 | - function ( Constraint $constraint ) { |
|
50 | + function(Constraint $constraint) { |
|
51 | 51 | return [ |
52 | 52 | 'constraint_guid' => $constraint->getConstraintId(), |
53 | 53 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
54 | 54 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
55 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
55 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
56 | 56 | ]; |
57 | 57 | }, |
58 | 58 | $constraints |
59 | 59 | ); |
60 | 60 | |
61 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_MASTER, [], $this->dbName ); |
|
62 | - return $dbw->insert( 'wbqc_constraints', $accumulator, __METHOD__ ); |
|
61 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_MASTER, [], $this->dbName); |
|
62 | + return $dbw->insert('wbqc_constraints', $accumulator, __METHOD__); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @throws DBUnexpectedError |
71 | 71 | */ |
72 | - public function deleteForProperty( PropertyId $propertyId ) { |
|
73 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_MASTER, [], $this->dbName ); |
|
72 | + public function deleteForProperty(PropertyId $propertyId) { |
|
73 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_MASTER, [], $this->dbName); |
|
74 | 74 | $dbw->delete( |
75 | 75 | 'wbqc_constraints', |
76 | 76 | [ |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * then using the main DBLoadBalancer service may be incorrect. |
26 | 26 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
27 | 27 | */ |
28 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
28 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
29 | 29 | $this->lb = $lb; |
30 | 30 | $this->dbName = $dbName; |
31 | 31 | } |
@@ -35,17 +35,17 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return Constraint[] |
37 | 37 | */ |
38 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
39 | - $dbr = $this->lb->getConnectionRef( ILoadBalancer::DB_REPLICA, [], $this->dbName ); |
|
38 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
39 | + $dbr = $this->lb->getConnectionRef(ILoadBalancer::DB_REPLICA, [], $this->dbName); |
|
40 | 40 | |
41 | 41 | $results = $dbr->select( |
42 | 42 | 'wbqc_constraints', |
43 | 43 | '*', |
44 | - [ 'pid' => $propertyId->getNumericId() ], |
|
44 | + ['pid' => $propertyId->getNumericId()], |
|
45 | 45 | __METHOD__ |
46 | 46 | ); |
47 | 47 | |
48 | - return $this->convertToConstraints( $results ); |
|
48 | + return $this->convertToConstraints($results); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -53,26 +53,26 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return Constraint[] |
55 | 55 | */ |
56 | - private function convertToConstraints( IResultWrapper $results ) { |
|
56 | + private function convertToConstraints(IResultWrapper $results) { |
|
57 | 57 | $constraints = []; |
58 | - $logger = LoggerFactory::getInstance( 'WikibaseQualityConstraints' ); |
|
59 | - foreach ( $results as $result ) { |
|
58 | + $logger = LoggerFactory::getInstance('WikibaseQualityConstraints'); |
|
59 | + foreach ($results as $result) { |
|
60 | 60 | $constraintTypeItemId = $result->constraint_type_qid; |
61 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
61 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
62 | 62 | |
63 | - if ( $constraintParameters === null ) { |
|
63 | + if ($constraintParameters === null) { |
|
64 | 64 | // T171295 |
65 | - $logger->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
65 | + $logger->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
66 | 66 | 'method' => __METHOD__, |
67 | 67 | 'constraintId' => $result->constraint_guid, |
68 | 68 | 'constraintParameters' => $result->constraint_parameters, |
69 | - ] ); |
|
70 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
69 | + ]); |
|
70 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | $constraints[] = new Constraint( |
74 | 74 | $result->constraint_guid, |
75 | - PropertyId::newFromNumber( $result->pid ), |
|
75 | + PropertyId::newFromNumber($result->pid), |
|
76 | 76 | $constraintTypeItemId, |
77 | 77 | $constraintParameters |
78 | 78 | ); |
@@ -37,25 +37,25 @@ discard block |
||
37 | 37 | * @param Title $title |
38 | 38 | * @param string[] $params should contain 'entityId' => 'Q1234' |
39 | 39 | */ |
40 | - public function __construct( Title $title, array $params ) { |
|
41 | - parent::__construct( self::COMMAND, $title, $params ); |
|
40 | + public function __construct(Title $title, array $params) { |
|
41 | + parent::__construct(self::COMMAND, $title, $params); |
|
42 | 42 | $this->removeDuplicates = true; |
43 | 43 | |
44 | - Assert::parameterType( 'string', $params['entityId'], '$params[\'entityId\']' ); |
|
44 | + Assert::parameterType('string', $params['entityId'], '$params[\'entityId\']'); |
|
45 | 45 | |
46 | - $resultSource = ConstraintsServices::getResultsSource( MediaWikiServices::getInstance() ); |
|
46 | + $resultSource = ConstraintsServices::getResultsSource(MediaWikiServices::getInstance()); |
|
47 | 47 | '@phan-var CachingResultsSource $resultSource'; |
48 | 48 | // This job should only ever be used when caching result sources are used. |
49 | - $this->setResultsSource( $resultSource ); |
|
49 | + $this->setResultsSource($resultSource); |
|
50 | 50 | |
51 | - $this->setEntityIdParser( WikibaseRepo::getEntityIdParser() ); |
|
51 | + $this->setEntityIdParser(WikibaseRepo::getEntityIdParser()); |
|
52 | 52 | } |
53 | 53 | |
54 | - public function setResultsSource( CachingResultsSource $resultsSource ) { |
|
54 | + public function setResultsSource(CachingResultsSource $resultsSource) { |
|
55 | 55 | $this->resultsSource = $resultsSource; |
56 | 56 | } |
57 | 57 | |
58 | - public function setEntityIdParser( EntityIdParser $parser ) { |
|
58 | + public function setEntityIdParser(EntityIdParser $parser) { |
|
59 | 59 | $this->entityIdParser = $parser; |
60 | 60 | } |
61 | 61 | |
@@ -66,19 +66,19 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function run() { |
68 | 68 | try { |
69 | - $entityId = $this->entityIdParser->parse( $this->params['entityId'] ); |
|
70 | - } catch ( EntityIdParsingException $e ) { |
|
69 | + $entityId = $this->entityIdParser->parse($this->params['entityId']); |
|
70 | + } catch (EntityIdParsingException $e) { |
|
71 | 71 | return false; |
72 | 72 | } |
73 | 73 | |
74 | - $this->checkConstraints( $entityId ); |
|
74 | + $this->checkConstraints($entityId); |
|
75 | 75 | |
76 | 76 | return true; |
77 | 77 | } |
78 | 78 | |
79 | - private function checkConstraints( EntityId $entityId ) { |
|
79 | + private function checkConstraints(EntityId $entityId) { |
|
80 | 80 | $this->resultsSource->getResults( |
81 | - [ $entityId ], |
|
81 | + [$entityId], |
|
82 | 82 | [], |
83 | 83 | null, |
84 | 84 | [] |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | * @param array $parameters |
78 | 78 | * @throws ConstraintParameterException |
79 | 79 | */ |
80 | - public function checkError( array $parameters ) { |
|
81 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
80 | + public function checkError(array $parameters) { |
|
81 | + if (array_key_exists('@error', $parameters)) { |
|
82 | 82 | $error = $parameters['@error']; |
83 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
83 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
84 | 84 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
85 | 85 | } else { |
86 | 86 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
87 | 87 | } |
88 | - throw new ConstraintParameterException( new ViolationMessage( $msg ) ); |
|
88 | + throw new ConstraintParameterException(new ViolationMessage($msg)); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | * @param string $parameterId |
96 | 96 | * @throws ConstraintParameterException |
97 | 97 | */ |
98 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
99 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
98 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
99 | + if (count($parameters[$parameterId]) !== 1) { |
|
100 | 100 | throw new ConstraintParameterException( |
101 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) ) |
|
102 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
101 | + (new ViolationMessage('wbqc-violation-message-parameter-single')) |
|
102 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
103 | 103 | ); |
104 | 104 | } |
105 | 105 | } |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | * @return void |
112 | 112 | * @throws ConstraintParameterException |
113 | 113 | */ |
114 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
115 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
114 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
115 | + if (!($snak instanceof PropertyValueSnak)) { |
|
116 | 116 | throw new ConstraintParameterException( |
117 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
118 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
117 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
118 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
119 | 119 | ); |
120 | 120 | } |
121 | 121 | } |
@@ -127,17 +127,17 @@ discard block |
||
127 | 127 | * @throws ConstraintParameterException |
128 | 128 | * @return EntityId |
129 | 129 | */ |
130 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
131 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
132 | - $this->requireValueParameter( $snak, $parameterId ); |
|
130 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
131 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
132 | + $this->requireValueParameter($snak, $parameterId); |
|
133 | 133 | $value = $snak->getDataValue(); |
134 | - if ( $value instanceof EntityIdValue ) { |
|
134 | + if ($value instanceof EntityIdValue) { |
|
135 | 135 | return $value->getEntityId(); |
136 | 136 | } else { |
137 | 137 | throw new ConstraintParameterException( |
138 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) ) |
|
139 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
140 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
138 | + (new ViolationMessage('wbqc-violation-message-parameter-entity')) |
|
139 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
140 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
141 | 141 | ); |
142 | 142 | } |
143 | 143 | } |
@@ -148,20 +148,20 @@ discard block |
||
148 | 148 | * @throws ConstraintParameterException if the parameter is invalid or missing |
149 | 149 | * @return string[] class entity ID serializations |
150 | 150 | */ |
151 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
152 | - $this->checkError( $constraintParameters ); |
|
153 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
154 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
151 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
152 | + $this->checkError($constraintParameters); |
|
153 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
154 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
155 | 155 | throw new ConstraintParameterException( |
156 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
157 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
158 | - ->withEntityId( new PropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
156 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
157 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
158 | + ->withEntityId(new PropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
159 | 159 | ); |
160 | 160 | } |
161 | 161 | |
162 | 162 | $classes = []; |
163 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
164 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
163 | + foreach ($constraintParameters[$classId] as $class) { |
|
164 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
165 | 165 | } |
166 | 166 | return $classes; |
167 | 167 | } |
@@ -172,23 +172,23 @@ discard block |
||
172 | 172 | * @throws ConstraintParameterException if the parameter is invalid or missing |
173 | 173 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
174 | 174 | */ |
175 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
176 | - $this->checkError( $constraintParameters ); |
|
177 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
178 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
175 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
176 | + $this->checkError($constraintParameters); |
|
177 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
178 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
179 | 179 | throw new ConstraintParameterException( |
180 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
181 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
182 | - ->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
180 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
181 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
182 | + ->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
183 | 183 | ); |
184 | 184 | } |
185 | 185 | |
186 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
187 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
188 | - $instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ); |
|
189 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ); |
|
190 | - $instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ); |
|
191 | - switch ( $relationEntityId->getSerialization() ) { |
|
186 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
187 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
188 | + $instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId'); |
|
189 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId'); |
|
190 | + $instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId'); |
|
191 | + switch ($relationEntityId->getSerialization()) { |
|
192 | 192 | case $instanceId: |
193 | 193 | return 'instance'; |
194 | 194 | case $subclassId: |
@@ -197,13 +197,13 @@ discard block |
||
197 | 197 | return 'instanceOrSubclass'; |
198 | 198 | default: |
199 | 199 | throw new ConstraintParameterException( |
200 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
201 | - ->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
200 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
201 | + ->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
202 | 202 | ->withEntityIdList( |
203 | 203 | [ |
204 | - new ItemId( $instanceId ), |
|
205 | - new ItemId( $subclassId ), |
|
206 | - new ItemId( $instanceOrSubclassId ), |
|
204 | + new ItemId($instanceId), |
|
205 | + new ItemId($subclassId), |
|
206 | + new ItemId($instanceOrSubclassId), |
|
207 | 207 | ], |
208 | 208 | Role::CONSTRAINT_PARAMETER_VALUE |
209 | 209 | ) |
@@ -218,20 +218,20 @@ discard block |
||
218 | 218 | * @throws ConstraintParameterException |
219 | 219 | * @return PropertyId |
220 | 220 | */ |
221 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
222 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
223 | - $this->requireValueParameter( $snak, $parameterId ); |
|
221 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
222 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
223 | + $this->requireValueParameter($snak, $parameterId); |
|
224 | 224 | $value = $snak->getDataValue(); |
225 | - if ( $value instanceof EntityIdValue ) { |
|
225 | + if ($value instanceof EntityIdValue) { |
|
226 | 226 | $id = $value->getEntityId(); |
227 | - if ( $id instanceof PropertyId ) { |
|
227 | + if ($id instanceof PropertyId) { |
|
228 | 228 | return $id; |
229 | 229 | } |
230 | 230 | } |
231 | 231 | throw new ConstraintParameterException( |
232 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) ) |
|
233 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
234 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
232 | + (new ViolationMessage('wbqc-violation-message-parameter-property')) |
|
233 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
234 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
235 | 235 | ); |
236 | 236 | } |
237 | 237 | |
@@ -242,33 +242,33 @@ discard block |
||
242 | 242 | * @throws ConstraintParameterException if the parameter is invalid or missing |
243 | 243 | * @return PropertyId |
244 | 244 | */ |
245 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
246 | - $this->checkError( $constraintParameters ); |
|
247 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
248 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
245 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
246 | + $this->checkError($constraintParameters); |
|
247 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
248 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
249 | 249 | throw new ConstraintParameterException( |
250 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
251 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
252 | - ->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
250 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
251 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
252 | + ->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
253 | 253 | ); |
254 | 254 | } |
255 | 255 | |
256 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
257 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
256 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
257 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
258 | 258 | } |
259 | 259 | |
260 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
260 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
261 | 261 | $dataValue = $snak->getDataValue(); |
262 | - if ( $dataValue instanceof EntityIdValue ) { |
|
262 | + if ($dataValue instanceof EntityIdValue) { |
|
263 | 263 | $entityId = $dataValue->getEntityId(); |
264 | - if ( $entityId instanceof ItemId ) { |
|
265 | - return ItemIdSnakValue::fromItemId( $entityId ); |
|
264 | + if ($entityId instanceof ItemId) { |
|
265 | + return ItemIdSnakValue::fromItemId($entityId); |
|
266 | 266 | } |
267 | 267 | } |
268 | 268 | throw new ConstraintParameterException( |
269 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
270 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
271 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
269 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
270 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
271 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
272 | 272 | ); |
273 | 273 | } |
274 | 274 | |
@@ -286,16 +286,16 @@ discard block |
||
286 | 286 | $required, |
287 | 287 | $parameterId = null |
288 | 288 | ) { |
289 | - $this->checkError( $constraintParameters ); |
|
290 | - if ( $parameterId === null ) { |
|
291 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
289 | + $this->checkError($constraintParameters); |
|
290 | + if ($parameterId === null) { |
|
291 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
292 | 292 | } |
293 | - if ( !array_key_exists( $parameterId, $constraintParameters ) ) { |
|
294 | - if ( $required ) { |
|
293 | + if (!array_key_exists($parameterId, $constraintParameters)) { |
|
294 | + if ($required) { |
|
295 | 295 | throw new ConstraintParameterException( |
296 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
297 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
298 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
296 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
297 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
298 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
299 | 299 | ); |
300 | 300 | } else { |
301 | 301 | return []; |
@@ -303,11 +303,11 @@ discard block |
||
303 | 303 | } |
304 | 304 | |
305 | 305 | $values = []; |
306 | - foreach ( $constraintParameters[$parameterId] as $parameter ) { |
|
307 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
308 | - switch ( true ) { |
|
306 | + foreach ($constraintParameters[$parameterId] as $parameter) { |
|
307 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
308 | + switch (true) { |
|
309 | 309 | case $snak instanceof PropertyValueSnak: |
310 | - $values[] = $this->parseItemIdParameter( $snak, $parameterId ); |
|
310 | + $values[] = $this->parseItemIdParameter($snak, $parameterId); |
|
311 | 311 | break; |
312 | 312 | case $snak instanceof PropertySomeValueSnak: |
313 | 313 | $values[] = ItemIdSnakValue::someValue(); |
@@ -326,27 +326,27 @@ discard block |
||
326 | 326 | * @throws ConstraintParameterException if the parameter is invalid or missing |
327 | 327 | * @return PropertyId[] |
328 | 328 | */ |
329 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
330 | - $this->checkError( $constraintParameters ); |
|
331 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
332 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
329 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
330 | + $this->checkError($constraintParameters); |
|
331 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
332 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
333 | 333 | throw new ConstraintParameterException( |
334 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
335 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
336 | - ->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
334 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
335 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
336 | + ->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
337 | 337 | ); |
338 | 338 | } |
339 | 339 | |
340 | 340 | $parameters = $constraintParameters[$propertyId]; |
341 | - if ( count( $parameters ) === 1 && |
|
342 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
341 | + if (count($parameters) === 1 && |
|
342 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
343 | 343 | ) { |
344 | 344 | return []; |
345 | 345 | } |
346 | 346 | |
347 | 347 | $properties = []; |
348 | - foreach ( $parameters as $parameter ) { |
|
349 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
348 | + foreach ($parameters as $parameter) { |
|
349 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
350 | 350 | } |
351 | 351 | return $properties; |
352 | 352 | } |
@@ -357,16 +357,16 @@ discard block |
||
357 | 357 | * @throws ConstraintParameterException |
358 | 358 | * @return DataValue|null |
359 | 359 | */ |
360 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
361 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
362 | - if ( $snak instanceof PropertyValueSnak ) { |
|
360 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
361 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
362 | + if ($snak instanceof PropertyValueSnak) { |
|
363 | 363 | return $snak->getDataValue(); |
364 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
364 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
365 | 365 | return null; |
366 | 366 | } else { |
367 | 367 | throw new ConstraintParameterException( |
368 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
369 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
368 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
369 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
370 | 370 | ); |
371 | 371 | } |
372 | 372 | } |
@@ -376,10 +376,10 @@ discard block |
||
376 | 376 | * @param string $parameterId |
377 | 377 | * @return DataValue|null |
378 | 378 | */ |
379 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
379 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
380 | 380 | try { |
381 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
382 | - } catch ( ConstraintParameterException $e ) { |
|
381 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
382 | + } catch (ConstraintParameterException $e) { |
|
383 | 383 | // unknown value means “now” |
384 | 384 | return new NowValue(); |
385 | 385 | } |
@@ -392,14 +392,14 @@ discard block |
||
392 | 392 | * @param string $unit |
393 | 393 | * @return bool |
394 | 394 | */ |
395 | - private function exactlyOneQuantityWithUnit( ?DataValue $min, ?DataValue $max, $unit ) { |
|
396 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
397 | - !( $max instanceof UnboundedQuantityValue ) |
|
395 | + private function exactlyOneQuantityWithUnit(?DataValue $min, ?DataValue $max, $unit) { |
|
396 | + if (!($min instanceof UnboundedQuantityValue) || |
|
397 | + !($max instanceof UnboundedQuantityValue) |
|
398 | 398 | ) { |
399 | 399 | return false; |
400 | 400 | } |
401 | 401 | |
402 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
402 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -412,42 +412,42 @@ discard block |
||
412 | 412 | * @throws ConstraintParameterException if the parameter is invalid or missing |
413 | 413 | * @return DataValue[] if the parameter is invalid or missing |
414 | 414 | */ |
415 | - private function parseRangeParameter( array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type ) { |
|
416 | - $this->checkError( $constraintParameters ); |
|
417 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
418 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
415 | + private function parseRangeParameter(array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type) { |
|
416 | + $this->checkError($constraintParameters); |
|
417 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
418 | + !array_key_exists($maximumId, $constraintParameters) |
|
419 | 419 | ) { |
420 | 420 | throw new ConstraintParameterException( |
421 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) ) |
|
422 | - ->withDataValueType( $type ) |
|
423 | - ->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
424 | - ->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
425 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
421 | + (new ViolationMessage('wbqc-violation-message-range-parameters-needed')) |
|
422 | + ->withDataValueType($type) |
|
423 | + ->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
424 | + ->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
425 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
426 | 426 | ); |
427 | 427 | } |
428 | 428 | |
429 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
430 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
429 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
430 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
431 | 431 | $parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
432 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
433 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
432 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
433 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
434 | 434 | |
435 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
436 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
435 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
436 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
437 | 437 | throw new ConstraintParameterException( |
438 | - new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
438 | + new ViolationMessage('wbqc-violation-message-range-parameters-one-year') |
|
439 | 439 | ); |
440 | 440 | } |
441 | - if ( $min === null && $max === null || |
|
442 | - $min !== null && $max !== null && $min->equals( $max ) ) { |
|
441 | + if ($min === null && $max === null || |
|
442 | + $min !== null && $max !== null && $min->equals($max)) { |
|
443 | 443 | throw new ConstraintParameterException( |
444 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) ) |
|
445 | - ->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
446 | - ->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
444 | + (new ViolationMessage('wbqc-violation-message-range-parameters-same')) |
|
445 | + ->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
446 | + ->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
447 | 447 | ); |
448 | 448 | } |
449 | 449 | |
450 | - return [ $min, $max ]; |
|
450 | + return [$min, $max]; |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -457,11 +457,11 @@ discard block |
||
457 | 457 | * @throws ConstraintParameterException if the parameter is invalid or missing |
458 | 458 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
459 | 459 | */ |
460 | - public function parseQuantityRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
460 | + public function parseQuantityRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
461 | 461 | return $this->parseRangeParameter( |
462 | 462 | $constraintParameters, |
463 | - $this->config->get( 'WBQualityConstraintsMinimumQuantityId' ), |
|
464 | - $this->config->get( 'WBQualityConstraintsMaximumQuantityId' ), |
|
463 | + $this->config->get('WBQualityConstraintsMinimumQuantityId'), |
|
464 | + $this->config->get('WBQualityConstraintsMaximumQuantityId'), |
|
465 | 465 | $constraintTypeItemId, |
466 | 466 | 'quantity' |
467 | 467 | ); |
@@ -474,11 +474,11 @@ discard block |
||
474 | 474 | * @throws ConstraintParameterException if the parameter is invalid or missing |
475 | 475 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
476 | 476 | */ |
477 | - public function parseTimeRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
477 | + public function parseTimeRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
478 | 478 | return $this->parseRangeParameter( |
479 | 479 | $constraintParameters, |
480 | - $this->config->get( 'WBQualityConstraintsMinimumDateId' ), |
|
481 | - $this->config->get( 'WBQualityConstraintsMaximumDateId' ), |
|
480 | + $this->config->get('WBQualityConstraintsMinimumDateId'), |
|
481 | + $this->config->get('WBQualityConstraintsMaximumDateId'), |
|
482 | 482 | $constraintTypeItemId, |
483 | 483 | 'time' |
484 | 484 | ); |
@@ -491,17 +491,17 @@ discard block |
||
491 | 491 | * @throws ConstraintParameterException |
492 | 492 | * @return string |
493 | 493 | */ |
494 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
495 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
496 | - $this->requireValueParameter( $snak, $parameterId ); |
|
494 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
495 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
496 | + $this->requireValueParameter($snak, $parameterId); |
|
497 | 497 | $value = $snak->getDataValue(); |
498 | - if ( $value instanceof StringValue ) { |
|
498 | + if ($value instanceof StringValue) { |
|
499 | 499 | return $value->getValue(); |
500 | 500 | } else { |
501 | 501 | throw new ConstraintParameterException( |
502 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) ) |
|
503 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
504 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
502 | + (new ViolationMessage('wbqc-violation-message-parameter-string')) |
|
503 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
504 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
505 | 505 | ); |
506 | 506 | } |
507 | 507 | } |
@@ -512,15 +512,15 @@ discard block |
||
512 | 512 | * @throws ConstraintParameterException if the parameter is invalid or missing |
513 | 513 | * @return string |
514 | 514 | */ |
515 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
516 | - $this->checkError( $constraintParameters ); |
|
517 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
518 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
515 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
516 | + $this->checkError($constraintParameters); |
|
517 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
518 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
519 | 519 | return ''; |
520 | 520 | } |
521 | 521 | |
522 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
523 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
522 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
523 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -529,19 +529,19 @@ discard block |
||
529 | 529 | * @throws ConstraintParameterException if the parameter is invalid or missing |
530 | 530 | * @return string |
531 | 531 | */ |
532 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
533 | - $this->checkError( $constraintParameters ); |
|
534 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
535 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
532 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
533 | + $this->checkError($constraintParameters); |
|
534 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
535 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
536 | 536 | throw new ConstraintParameterException( |
537 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
538 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
539 | - ->withEntityId( new PropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
537 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
538 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
539 | + ->withEntityId(new PropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
540 | 540 | ); |
541 | 541 | } |
542 | 542 | |
543 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
544 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
543 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
544 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -549,16 +549,16 @@ discard block |
||
549 | 549 | * @throws ConstraintParameterException if the parameter is invalid |
550 | 550 | * @return EntityId[] |
551 | 551 | */ |
552 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
553 | - $this->checkError( $constraintParameters ); |
|
554 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
555 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
552 | + public function parseExceptionParameter(array $constraintParameters) { |
|
553 | + $this->checkError($constraintParameters); |
|
554 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
555 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
556 | 556 | return []; |
557 | 557 | } |
558 | 558 | |
559 | 559 | return array_map( |
560 | - function ( $snakSerialization ) use ( $exceptionId ) { |
|
561 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
560 | + function($snakSerialization) use ($exceptionId) { |
|
561 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
562 | 562 | }, |
563 | 563 | $constraintParameters[$exceptionId] |
564 | 564 | ); |
@@ -569,39 +569,39 @@ discard block |
||
569 | 569 | * @throws ConstraintParameterException if the parameter is invalid |
570 | 570 | * @return string|null 'mandatory', 'suggestion' or null |
571 | 571 | */ |
572 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
573 | - $this->checkError( $constraintParameters ); |
|
574 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
575 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
572 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
573 | + $this->checkError($constraintParameters); |
|
574 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
575 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
576 | 576 | return null; |
577 | 577 | } |
578 | 578 | |
579 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
580 | - $supportedStatuses = [ new ItemId( $mandatoryId ) ]; |
|
581 | - if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) { |
|
582 | - $suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' ); |
|
583 | - $supportedStatuses[] = new ItemId( $suggestionId ); |
|
579 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
580 | + $supportedStatuses = [new ItemId($mandatoryId)]; |
|
581 | + if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) { |
|
582 | + $suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId'); |
|
583 | + $supportedStatuses[] = new ItemId($suggestionId); |
|
584 | 584 | } else { |
585 | 585 | $suggestionId = null; |
586 | 586 | } |
587 | 587 | |
588 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
589 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
590 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
588 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
589 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
590 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
591 | 591 | '@phan-var \Wikibase\DataModel\Snak\PropertyValueSnak $snak'; |
592 | 592 | $dataValue = $snak->getDataValue(); |
593 | 593 | '@phan-var EntityIdValue $dataValue'; |
594 | 594 | $entityId = $dataValue->getEntityId(); |
595 | 595 | $statusId = $entityId->getSerialization(); |
596 | 596 | |
597 | - if ( $statusId === $mandatoryId ) { |
|
597 | + if ($statusId === $mandatoryId) { |
|
598 | 598 | return 'mandatory'; |
599 | - } elseif ( $statusId === $suggestionId ) { |
|
599 | + } elseif ($statusId === $suggestionId) { |
|
600 | 600 | return 'suggestion'; |
601 | 601 | } else { |
602 | 602 | throw new ConstraintParameterException( |
603 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
604 | - ->withEntityId( new PropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
603 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
604 | + ->withEntityId(new PropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
605 | 605 | ->withEntityIdList( |
606 | 606 | $supportedStatuses, |
607 | 607 | Role::CONSTRAINT_PARAMETER_VALUE |
@@ -617,12 +617,12 @@ discard block |
||
617 | 617 | * @return void |
618 | 618 | * @throws ConstraintParameterException |
619 | 619 | */ |
620 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
621 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
620 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
621 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
622 | 622 | throw new ConstraintParameterException( |
623 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) ) |
|
624 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
625 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
623 | + (new ViolationMessage('wbqc-violation-message-parameter-monolingualtext')) |
|
624 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
625 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
626 | 626 | ); |
627 | 627 | } |
628 | 628 | } |
@@ -635,31 +635,31 @@ discard block |
||
635 | 635 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
636 | 636 | * @return MultilingualTextValue |
637 | 637 | */ |
638 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
638 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
639 | 639 | $result = []; |
640 | 640 | |
641 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
642 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
643 | - $this->requireValueParameter( $snak, $parameterId ); |
|
641 | + foreach ($snakSerializations as $snakSerialization) { |
|
642 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
643 | + $this->requireValueParameter($snak, $parameterId); |
|
644 | 644 | |
645 | 645 | $value = $snak->getDataValue(); |
646 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
646 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
647 | 647 | /** @var MonolingualTextValue $value */ |
648 | 648 | '@phan-var MonolingualTextValue $value'; |
649 | 649 | |
650 | 650 | $code = $value->getLanguageCode(); |
651 | - if ( array_key_exists( $code, $result ) ) { |
|
651 | + if (array_key_exists($code, $result)) { |
|
652 | 652 | throw new ConstraintParameterException( |
653 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) ) |
|
654 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
655 | - ->withLanguage( $code ) |
|
653 | + (new ViolationMessage('wbqc-violation-message-parameter-single-per-language')) |
|
654 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
655 | + ->withLanguage($code) |
|
656 | 656 | ); |
657 | 657 | } |
658 | 658 | |
659 | 659 | $result[$code] = $value; |
660 | 660 | } |
661 | 661 | |
662 | - return new MultilingualTextValue( $result ); |
|
662 | + return new MultilingualTextValue($result); |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | /** |
@@ -667,11 +667,11 @@ discard block |
||
667 | 667 | * @throws ConstraintParameterException if the parameter is invalid |
668 | 668 | * @return MultilingualTextValue |
669 | 669 | */ |
670 | - public function parseSyntaxClarificationParameter( array $constraintParameters ) { |
|
671 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
670 | + public function parseSyntaxClarificationParameter(array $constraintParameters) { |
|
671 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
672 | 672 | |
673 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
674 | - return new MultilingualTextValue( [] ); |
|
673 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
674 | + return new MultilingualTextValue([]); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | array $validScopes = null |
697 | 697 | ) { |
698 | 698 | $contextTypes = []; |
699 | - $parameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
699 | + $parameterId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
700 | 700 | $items = $this->parseItemsParameter( |
701 | 701 | $constraintParameters, |
702 | 702 | $constraintTypeItemId, |
@@ -704,23 +704,23 @@ discard block |
||
704 | 704 | $parameterId |
705 | 705 | ); |
706 | 706 | |
707 | - if ( $items === [] ) { |
|
707 | + if ($items === []) { |
|
708 | 708 | return null; |
709 | 709 | } |
710 | 710 | |
711 | - foreach ( $items as $item ) { |
|
712 | - $contextTypes[] = $this->parseContextTypeItem( $item, 'constraint scope', $parameterId ); |
|
711 | + foreach ($items as $item) { |
|
712 | + $contextTypes[] = $this->parseContextTypeItem($item, 'constraint scope', $parameterId); |
|
713 | 713 | } |
714 | 714 | |
715 | - if ( $validScopes !== null ) { |
|
716 | - $invalidScopes = array_diff( $contextTypes, $validScopes ); |
|
717 | - if ( $invalidScopes !== [] ) { |
|
718 | - $invalidScope = array_pop( $invalidScopes ); |
|
715 | + if ($validScopes !== null) { |
|
716 | + $invalidScopes = array_diff($contextTypes, $validScopes); |
|
717 | + if ($invalidScopes !== []) { |
|
718 | + $invalidScope = array_pop($invalidScopes); |
|
719 | 719 | throw new ConstraintParameterException( |
720 | - ( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) ) |
|
721 | - ->withConstraintScope( $invalidScope, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
722 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
723 | - ->withConstraintScopeList( $validScopes, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
720 | + (new ViolationMessage('wbqc-violation-message-invalid-scope')) |
|
721 | + ->withConstraintScope($invalidScope, Role::CONSTRAINT_PARAMETER_VALUE) |
|
722 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
723 | + ->withConstraintScopeList($validScopes, Role::CONSTRAINT_PARAMETER_VALUE) |
|
724 | 724 | ); |
725 | 725 | } |
726 | 726 | } |
@@ -734,8 +734,8 @@ discard block |
||
734 | 734 | * @param ItemId $unitId |
735 | 735 | * @return string unit |
736 | 736 | */ |
737 | - private function parseUnitParameter( ItemId $unitId ) { |
|
738 | - return $this->unitItemConceptBaseUri . $unitId->getSerialization(); |
|
737 | + private function parseUnitParameter(ItemId $unitId) { |
|
738 | + return $this->unitItemConceptBaseUri.$unitId->getSerialization(); |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | /** |
@@ -745,23 +745,23 @@ discard block |
||
745 | 745 | * @return UnitsParameter |
746 | 746 | * @throws ConstraintParameterException |
747 | 747 | */ |
748 | - private function parseUnitItem( ItemIdSnakValue $item ) { |
|
749 | - switch ( true ) { |
|
748 | + private function parseUnitItem(ItemIdSnakValue $item) { |
|
749 | + switch (true) { |
|
750 | 750 | case $item->isValue(): |
751 | - $unit = $this->parseUnitParameter( $item->getItemId() ); |
|
751 | + $unit = $this->parseUnitParameter($item->getItemId()); |
|
752 | 752 | return new UnitsParameter( |
753 | - [ $item->getItemId() ], |
|
754 | - [ UnboundedQuantityValue::newFromNumber( 1, $unit ) ], |
|
753 | + [$item->getItemId()], |
|
754 | + [UnboundedQuantityValue::newFromNumber(1, $unit)], |
|
755 | 755 | false |
756 | 756 | ); |
757 | 757 | case $item->isSomeValue(): |
758 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
758 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
759 | 759 | throw new ConstraintParameterException( |
760 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
761 | - ->withEntityId( new PropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
760 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
761 | + ->withEntityId(new PropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
762 | 762 | ); |
763 | 763 | case $item->isNoValue(): |
764 | - return new UnitsParameter( [], [], true ); |
|
764 | + return new UnitsParameter([], [], true); |
|
765 | 765 | } |
766 | 766 | } |
767 | 767 | |
@@ -771,26 +771,26 @@ discard block |
||
771 | 771 | * @throws ConstraintParameterException if the parameter is invalid or missing |
772 | 772 | * @return UnitsParameter |
773 | 773 | */ |
774 | - public function parseUnitsParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
775 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
774 | + public function parseUnitsParameter(array $constraintParameters, $constraintTypeItemId) { |
|
775 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
776 | 776 | $unitItems = []; |
777 | 777 | $unitQuantities = []; |
778 | 778 | $unitlessAllowed = false; |
779 | 779 | |
780 | - foreach ( $items as $item ) { |
|
781 | - $unit = $this->parseUnitItem( $item ); |
|
782 | - $unitItems = array_merge( $unitItems, $unit->getUnitItemIds() ); |
|
783 | - $unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() ); |
|
780 | + foreach ($items as $item) { |
|
781 | + $unit = $this->parseUnitItem($item); |
|
782 | + $unitItems = array_merge($unitItems, $unit->getUnitItemIds()); |
|
783 | + $unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities()); |
|
784 | 784 | $unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed(); |
785 | 785 | } |
786 | 786 | |
787 | - if ( $unitQuantities === [] && !$unitlessAllowed ) { |
|
787 | + if ($unitQuantities === [] && !$unitlessAllowed) { |
|
788 | 788 | throw new LogicException( |
789 | 789 | 'The "units" parameter is required, and yet we seem to be missing any allowed unit' |
790 | 790 | ); |
791 | 791 | } |
792 | 792 | |
793 | - return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed ); |
|
793 | + return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed); |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | /** |
@@ -800,53 +800,53 @@ discard block |
||
800 | 800 | * @return EntityTypesParameter |
801 | 801 | * @throws ConstraintParameterException |
802 | 802 | */ |
803 | - private function parseEntityTypeItem( ItemIdSnakValue $item ) { |
|
804 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
803 | + private function parseEntityTypeItem(ItemIdSnakValue $item) { |
|
804 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
805 | 805 | |
806 | - if ( !$item->isValue() ) { |
|
806 | + if (!$item->isValue()) { |
|
807 | 807 | throw new ConstraintParameterException( |
808 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
809 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
808 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
809 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
810 | 810 | ); |
811 | 811 | } |
812 | 812 | |
813 | 813 | $itemId = $item->getItemId(); |
814 | - switch ( $itemId->getSerialization() ) { |
|
815 | - case $this->config->get( 'WBQualityConstraintsWikibaseItemId' ): |
|
814 | + switch ($itemId->getSerialization()) { |
|
815 | + case $this->config->get('WBQualityConstraintsWikibaseItemId'): |
|
816 | 816 | $entityType = 'item'; |
817 | 817 | break; |
818 | - case $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ): |
|
818 | + case $this->config->get('WBQualityConstraintsWikibasePropertyId'): |
|
819 | 819 | $entityType = 'property'; |
820 | 820 | break; |
821 | - case $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ): |
|
821 | + case $this->config->get('WBQualityConstraintsWikibaseLexemeId'): |
|
822 | 822 | $entityType = 'lexeme'; |
823 | 823 | break; |
824 | - case $this->config->get( 'WBQualityConstraintsWikibaseFormId' ): |
|
824 | + case $this->config->get('WBQualityConstraintsWikibaseFormId'): |
|
825 | 825 | $entityType = 'form'; |
826 | 826 | break; |
827 | - case $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ): |
|
827 | + case $this->config->get('WBQualityConstraintsWikibaseSenseId'): |
|
828 | 828 | $entityType = 'sense'; |
829 | 829 | break; |
830 | - case $this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ): |
|
830 | + case $this->config->get('WBQualityConstraintsWikibaseMediaInfoId'): |
|
831 | 831 | $entityType = 'mediainfo'; |
832 | 832 | break; |
833 | 833 | default: |
834 | 834 | $allowed = [ |
835 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseItemId' ) ), |
|
836 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) ), |
|
837 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) ), |
|
838 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseFormId' ) ), |
|
839 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) ), |
|
840 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ) ), |
|
835 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseItemId')), |
|
836 | + new ItemId($this->config->get('WBQualityConstraintsWikibasePropertyId')), |
|
837 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseLexemeId')), |
|
838 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseFormId')), |
|
839 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseSenseId')), |
|
840 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseMediaInfoId')), |
|
841 | 841 | ]; |
842 | 842 | throw new ConstraintParameterException( |
843 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
844 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
845 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
843 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
844 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
845 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
846 | 846 | ); |
847 | 847 | } |
848 | 848 | |
849 | - return new EntityTypesParameter( [ $entityType ], [ $itemId ] ); |
|
849 | + return new EntityTypesParameter([$entityType], [$itemId]); |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | /** |
@@ -855,27 +855,27 @@ discard block |
||
855 | 855 | * @throws ConstraintParameterException if the parameter is invalid or missing |
856 | 856 | * @return EntityTypesParameter |
857 | 857 | */ |
858 | - public function parseEntityTypesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
858 | + public function parseEntityTypesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
859 | 859 | $entityTypes = []; |
860 | 860 | $entityTypeItemIds = []; |
861 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
861 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
862 | 862 | |
863 | - foreach ( $items as $item ) { |
|
864 | - $entityType = $this->parseEntityTypeItem( $item ); |
|
865 | - $entityTypes = array_merge( $entityTypes, $entityType->getEntityTypes() ); |
|
866 | - $entityTypeItemIds = array_merge( $entityTypeItemIds, $entityType->getEntityTypeItemIds() ); |
|
863 | + foreach ($items as $item) { |
|
864 | + $entityType = $this->parseEntityTypeItem($item); |
|
865 | + $entityTypes = array_merge($entityTypes, $entityType->getEntityTypes()); |
|
866 | + $entityTypeItemIds = array_merge($entityTypeItemIds, $entityType->getEntityTypeItemIds()); |
|
867 | 867 | } |
868 | 868 | |
869 | - if ( empty( $entityTypes ) ) { |
|
869 | + if (empty($entityTypes)) { |
|
870 | 870 | // @codeCoverageIgnoreStart |
871 | 871 | throw new LogicException( |
872 | - 'The "entity types" parameter is required, ' . |
|
872 | + 'The "entity types" parameter is required, '. |
|
873 | 873 | 'and yet we seem to be missing any allowed entity type' |
874 | 874 | ); |
875 | 875 | // @codeCoverageIgnoreEnd |
876 | 876 | } |
877 | 877 | |
878 | - return new EntityTypesParameter( $entityTypes, $entityTypeItemIds ); |
|
878 | + return new EntityTypesParameter($entityTypes, $entityTypeItemIds); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | /** |
@@ -883,18 +883,18 @@ discard block |
||
883 | 883 | * @throws ConstraintParameterException if the parameter is invalid |
884 | 884 | * @return PropertyId[] |
885 | 885 | */ |
886 | - public function parseSeparatorsParameter( array $constraintParameters ) { |
|
887 | - $separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' ); |
|
886 | + public function parseSeparatorsParameter(array $constraintParameters) { |
|
887 | + $separatorId = $this->config->get('WBQualityConstraintsSeparatorId'); |
|
888 | 888 | |
889 | - if ( !array_key_exists( $separatorId, $constraintParameters ) ) { |
|
889 | + if (!array_key_exists($separatorId, $constraintParameters)) { |
|
890 | 890 | return []; |
891 | 891 | } |
892 | 892 | |
893 | 893 | $parameters = $constraintParameters[$separatorId]; |
894 | 894 | $separators = []; |
895 | 895 | |
896 | - foreach ( $parameters as $parameter ) { |
|
897 | - $separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId ); |
|
896 | + foreach ($parameters as $parameter) { |
|
897 | + $separators[] = $this->parsePropertyIdParameter($parameter, $separatorId); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | return $separators; |
@@ -909,26 +909,26 @@ discard block |
||
909 | 909 | * @return string one of the Context::TYPE_* constants |
910 | 910 | * @throws ConstraintParameterException |
911 | 911 | */ |
912 | - private function parseContextTypeItem( ItemIdSnakValue $item, $use, $parameterId ) { |
|
913 | - if ( !$item->isValue() ) { |
|
912 | + private function parseContextTypeItem(ItemIdSnakValue $item, $use, $parameterId) { |
|
913 | + if (!$item->isValue()) { |
|
914 | 914 | throw new ConstraintParameterException( |
915 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
916 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
915 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
916 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
917 | 917 | ); |
918 | 918 | } |
919 | 919 | |
920 | - if ( $use === 'constraint scope' ) { |
|
921 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ); |
|
922 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ); |
|
923 | - $referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ); |
|
920 | + if ($use === 'constraint scope') { |
|
921 | + $mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId'); |
|
922 | + $qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId'); |
|
923 | + $referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId'); |
|
924 | 924 | } else { |
925 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
926 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
927 | - $referencesId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
925 | + $mainSnakId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
926 | + $qualifiersId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
927 | + $referencesId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
928 | 928 | } |
929 | 929 | |
930 | 930 | $itemId = $item->getItemId(); |
931 | - switch ( $itemId->getSerialization() ) { |
|
931 | + switch ($itemId->getSerialization()) { |
|
932 | 932 | case $mainSnakId: |
933 | 933 | return Context::TYPE_STATEMENT; |
934 | 934 | case $qualifiersId: |
@@ -937,14 +937,14 @@ discard block |
||
937 | 937 | return Context::TYPE_REFERENCE; |
938 | 938 | default: |
939 | 939 | $allowed = [ |
940 | - new ItemId( $mainSnakId ), |
|
941 | - new ItemId( $qualifiersId ), |
|
942 | - new ItemId( $referencesId ), |
|
940 | + new ItemId($mainSnakId), |
|
941 | + new ItemId($qualifiersId), |
|
942 | + new ItemId($referencesId), |
|
943 | 943 | ]; |
944 | 944 | throw new ConstraintParameterException( |
945 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
946 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
947 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
945 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
946 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
947 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
948 | 948 | ); |
949 | 949 | } |
950 | 950 | } |
@@ -955,9 +955,9 @@ discard block |
||
955 | 955 | * @throws ConstraintParameterException if the parameter is invalid or missing |
956 | 956 | * @return string[] list of Context::TYPE_* constants |
957 | 957 | */ |
958 | - public function parsePropertyScopeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
958 | + public function parsePropertyScopeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
959 | 959 | $contextTypes = []; |
960 | - $parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' ); |
|
960 | + $parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId'); |
|
961 | 961 | $items = $this->parseItemsParameter( |
962 | 962 | $constraintParameters, |
963 | 963 | $constraintTypeItemId, |
@@ -965,14 +965,14 @@ discard block |
||
965 | 965 | $parameterId |
966 | 966 | ); |
967 | 967 | |
968 | - foreach ( $items as $item ) { |
|
969 | - $contextTypes[] = $this->parseContextTypeItem( $item, 'property scope', $parameterId ); |
|
968 | + foreach ($items as $item) { |
|
969 | + $contextTypes[] = $this->parseContextTypeItem($item, 'property scope', $parameterId); |
|
970 | 970 | } |
971 | 971 | |
972 | - if ( empty( $contextTypes ) ) { |
|
972 | + if (empty($contextTypes)) { |
|
973 | 973 | // @codeCoverageIgnoreStart |
974 | 974 | throw new LogicException( |
975 | - 'The "property scope" parameter is required, ' . |
|
975 | + 'The "property scope" parameter is required, '. |
|
976 | 976 | 'and yet we seem to be missing any allowed scope' |
977 | 977 | ); |
978 | 978 | // @codeCoverageIgnoreEnd |
@@ -38,87 +38,87 @@ |
||
38 | 38 | public const RESULTS_SOURCE = 'WBQC_ResultsSource'; |
39 | 39 | public const EXPIRY_LOCK = 'WBQC_ExpiryLock'; |
40 | 40 | |
41 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
42 | - if ( $services === null ) { |
|
41 | + private static function getService(?MediaWikiServices $services, $name) { |
|
42 | + if ($services === null) { |
|
43 | 43 | $services = MediaWikiServices::getInstance(); |
44 | 44 | } |
45 | - return $services->getService( $name ); |
|
45 | + return $services->getService($name); |
|
46 | 46 | } |
47 | 47 | |
48 | - public static function getLoggingHelper( MediaWikiServices $services = null ): LoggingHelper { |
|
49 | - return self::getService( $services, self::LOGGING_HELPER ); |
|
48 | + public static function getLoggingHelper(MediaWikiServices $services = null): LoggingHelper { |
|
49 | + return self::getService($services, self::LOGGING_HELPER); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public static function getConstraintStore( |
53 | 53 | MediaWikiServices $services = null |
54 | 54 | ): ConstraintStore { |
55 | - return self::getService( $services, self::CONSTRAINT_STORE ); |
|
55 | + return self::getService($services, self::CONSTRAINT_STORE); |
|
56 | 56 | } |
57 | 57 | |
58 | - public static function getConstraintLookup( MediaWikiServices $services = null ): ConstraintLookup { |
|
59 | - return self::getService( $services, self::CONSTRAINT_LOOKUP ); |
|
58 | + public static function getConstraintLookup(MediaWikiServices $services = null): ConstraintLookup { |
|
59 | + return self::getService($services, self::CONSTRAINT_LOOKUP); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | public static function getCheckResultSerializer( |
63 | 63 | MediaWikiServices $services = null |
64 | 64 | ): CheckResultSerializer { |
65 | - return self::getService( $services, self::CHECK_RESULT_SERIALIZER ); |
|
65 | + return self::getService($services, self::CHECK_RESULT_SERIALIZER); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | public static function getCheckResultDeserializer( |
69 | 69 | MediaWikiServices $services = null |
70 | 70 | ): CheckResultDeserializer { |
71 | - return self::getService( $services, self::CHECK_RESULT_DESERIALIZER ); |
|
71 | + return self::getService($services, self::CHECK_RESULT_DESERIALIZER); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | public static function getViolationMessageSerializer( |
75 | 75 | MediaWikiServices $services = null |
76 | 76 | ): ViolationMessageSerializer { |
77 | - return self::getService( $services, self::VIOLATION_MESSAGE_SERIALIZER ); |
|
77 | + return self::getService($services, self::VIOLATION_MESSAGE_SERIALIZER); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | public static function getViolationMessageDeserializer( |
81 | 81 | MediaWikiServices $services = null |
82 | 82 | ): ViolationMessageDeserializer { |
83 | - return self::getService( $services, self::VIOLATION_MESSAGE_DESERIALIZER ); |
|
83 | + return self::getService($services, self::VIOLATION_MESSAGE_DESERIALIZER); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | public static function getConstraintParameterParser( |
87 | 87 | MediaWikiServices $services = null |
88 | 88 | ): ConstraintParameterParser { |
89 | - return self::getService( $services, self::CONSTRAINT_PARAMETER_PARSER ); |
|
89 | + return self::getService($services, self::CONSTRAINT_PARAMETER_PARSER); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | public static function getConnectionCheckerHelper( |
93 | 93 | MediaWikiServices $services = null |
94 | 94 | ): ConnectionCheckerHelper { |
95 | - return self::getService( $services, self::CONNECTION_CHECKER_HELPER ); |
|
95 | + return self::getService($services, self::CONNECTION_CHECKER_HELPER); |
|
96 | 96 | } |
97 | 97 | |
98 | - public static function getRangeCheckerHelper( MediaWikiServices $services = null ): RangeCheckerHelper { |
|
99 | - return self::getService( $services, self::RANGE_CHECKER_HELPER ); |
|
98 | + public static function getRangeCheckerHelper(MediaWikiServices $services = null): RangeCheckerHelper { |
|
99 | + return self::getService($services, self::RANGE_CHECKER_HELPER); |
|
100 | 100 | } |
101 | 101 | |
102 | - public static function getSparqlHelper( MediaWikiServices $services = null ): SparqlHelper { |
|
103 | - return self::getService( $services, self::SPARQL_HELPER ); |
|
102 | + public static function getSparqlHelper(MediaWikiServices $services = null): SparqlHelper { |
|
103 | + return self::getService($services, self::SPARQL_HELPER); |
|
104 | 104 | } |
105 | 105 | |
106 | - public static function getTypeCheckerHelper( MediaWikiServices $services = null ): TypeCheckerHelper { |
|
107 | - return self::getService( $services, self::TYPE_CHECKER_HELPER ); |
|
106 | + public static function getTypeCheckerHelper(MediaWikiServices $services = null): TypeCheckerHelper { |
|
107 | + return self::getService($services, self::TYPE_CHECKER_HELPER); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | public static function getDelegatingConstraintChecker( |
111 | 111 | MediaWikiServices $services = null |
112 | 112 | ): DelegatingConstraintChecker { |
113 | - return self::getService( $services, self::DELEGATING_CONSTRAINT_CHECKER ); |
|
113 | + return self::getService($services, self::DELEGATING_CONSTRAINT_CHECKER); |
|
114 | 114 | } |
115 | 115 | |
116 | - public static function getResultsSource( MediaWikiServices $services = null ): ResultsSource { |
|
117 | - return self::getService( $services, self::RESULTS_SOURCE ); |
|
116 | + public static function getResultsSource(MediaWikiServices $services = null): ResultsSource { |
|
117 | + return self::getService($services, self::RESULTS_SOURCE); |
|
118 | 118 | } |
119 | 119 | |
120 | - public static function getExpiryLock( MediaWikiServices $services = null ): ExpiryLock { |
|
121 | - return self::getService( $services, self::EXPIRY_LOCK ); |
|
120 | + public static function getExpiryLock(MediaWikiServices $services = null): ExpiryLock { |
|
121 | + return self::getService($services, self::EXPIRY_LOCK); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | } |
@@ -24,22 +24,22 @@ |
||
24 | 24 | */ |
25 | 25 | private const NULL_PROPERTY_ID = 'P2147483647'; |
26 | 26 | |
27 | - public function __construct( ContextCursor $contextCursor ) { |
|
27 | + public function __construct(ContextCursor $contextCursor) { |
|
28 | 28 | $constraint = new Constraint( |
29 | 29 | 'null', |
30 | - new PropertyId( self::NULL_PROPERTY_ID ), |
|
30 | + new PropertyId(self::NULL_PROPERTY_ID), |
|
31 | 31 | 'none', |
32 | 32 | [] |
33 | 33 | ); |
34 | - parent::__construct( $contextCursor, $constraint ); |
|
34 | + parent::__construct($contextCursor, $constraint); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function getConstraint() { |
38 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
38 | + throw new DomainException('NullResult holds no constraint'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | public function getConstraintId() { |
42 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
42 | + throw new DomainException('NullResult holds no constraint'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | } |
@@ -20,35 +20,35 @@ |
||
20 | 20 | public const PROPERTY_DATA_TYPE_LOOKUP = 'WBQC_PropertyDataTypeLookup'; |
21 | 21 | public const ENTITY_LOOKUP_WITHOUT_CACHE = 'WBQC_EntityLookupWithoutCache'; |
22 | 22 | |
23 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
24 | - if ( $services === null ) { |
|
23 | + private static function getService(?MediaWikiServices $services, $name) { |
|
24 | + if ($services === null) { |
|
25 | 25 | $services = MediaWikiServices::getInstance(); |
26 | 26 | } |
27 | - return $services->getService( $name ); |
|
27 | + return $services->getService($name); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @param MediaWikiServices|null $services |
32 | 32 | * @return EntityLookup |
33 | 33 | */ |
34 | - public static function getEntityLookup( MediaWikiServices $services = null ) { |
|
35 | - return self::getService( $services, self::ENTITY_LOOKUP ); |
|
34 | + public static function getEntityLookup(MediaWikiServices $services = null) { |
|
35 | + return self::getService($services, self::ENTITY_LOOKUP); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @param MediaWikiServices|null $services |
40 | 40 | * @return PropertyDataTypeLookup |
41 | 41 | */ |
42 | - public static function getPropertyDataTypeLookup( MediaWikiServices $services = null ) { |
|
43 | - return self::getService( $services, self::PROPERTY_DATA_TYPE_LOOKUP ); |
|
42 | + public static function getPropertyDataTypeLookup(MediaWikiServices $services = null) { |
|
43 | + return self::getService($services, self::PROPERTY_DATA_TYPE_LOOKUP); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param MediaWikiServices|null $services |
48 | 48 | * @return EntityLookup |
49 | 49 | */ |
50 | - public static function getEntityLookupWithoutCache( MediaWikiServices $services = null ) { |
|
51 | - return self::getService( $services, self::ENTITY_LOOKUP_WITHOUT_CACHE ); |
|
50 | + public static function getEntityLookupWithoutCache(MediaWikiServices $services = null) { |
|
51 | + return self::getService($services, self::ENTITY_LOOKUP_WITHOUT_CACHE); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |