@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | StatementList $statementList, |
31 | 31 | PropertyId $propertyId |
32 | 32 | ) { |
33 | - $statementListByPropertyId = $statementList->getByPropertyId( $propertyId ); |
|
34 | - if ( $statementListByPropertyId->isEmpty() ) { |
|
33 | + $statementListByPropertyId = $statementList->getByPropertyId($propertyId); |
|
34 | + if ($statementListByPropertyId->isEmpty()) { |
|
35 | 35 | return null; |
36 | 36 | } else { |
37 | 37 | return $statementListByPropertyId->toArray()[0]; |
@@ -52,14 +52,14 @@ discard block |
||
52 | 52 | PropertyId $propertyId, |
53 | 53 | EntityId $value |
54 | 54 | ) { |
55 | - $statementListByPropertyId = $statementList->getByPropertyId( $propertyId ); |
|
55 | + $statementListByPropertyId = $statementList->getByPropertyId($propertyId); |
|
56 | 56 | /** @var Statement $statement */ |
57 | - foreach ( $statementListByPropertyId as $statement ) { |
|
57 | + foreach ($statementListByPropertyId as $statement) { |
|
58 | 58 | $snak = $statement->getMainSnak(); |
59 | - if ( $snak instanceof PropertyValueSnak ) { |
|
59 | + if ($snak instanceof PropertyValueSnak) { |
|
60 | 60 | $dataValue = $snak->getDataValue(); |
61 | - if ( $dataValue instanceof EntityIdValue && |
|
62 | - $dataValue->getEntityId()->equals( $value ) |
|
61 | + if ($dataValue instanceof EntityIdValue && |
|
62 | + $dataValue->getEntityId()->equals($value) |
|
63 | 63 | ) { |
64 | 64 | return $statement; |
65 | 65 | } |
@@ -82,12 +82,12 @@ discard block |
||
82 | 82 | PropertyId $propertyId, |
83 | 83 | array $values |
84 | 84 | ) { |
85 | - $statementListByPropertyId = $statementList->getByPropertyId( $propertyId ); |
|
85 | + $statementListByPropertyId = $statementList->getByPropertyId($propertyId); |
|
86 | 86 | /** @var Statement $statement */ |
87 | - foreach ( $statementListByPropertyId as $statement ) { |
|
87 | + foreach ($statementListByPropertyId as $statement) { |
|
88 | 88 | $snak = $statement->getMainSnak(); |
89 | - foreach ( $values as $value ) { |
|
90 | - if ( $value->matchesSnak( $snak ) ) { |
|
89 | + foreach ($values as $value) { |
|
90 | + if ($value->matchesSnak($snak)) { |
|
91 | 91 | return $statement; |
92 | 92 | } |
93 | 93 | } |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | |
27 | 27 | const BATCH_SIZE = 10; |
28 | 28 | |
29 | - public static function newFromGlobalState( Title $title, array $params ) { |
|
30 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
29 | + public static function newFromGlobalState(Title $title, array $params) { |
|
30 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
31 | 31 | $repo = WikibaseRepo::getDefaultInstance(); |
32 | 32 | return new UpdateConstraintsTableJob( |
33 | 33 | $title, |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | EntityLookup $entityLookup, |
84 | 84 | Serializer $snakSerializer |
85 | 85 | ) { |
86 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
86 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
87 | 87 | |
88 | 88 | $this->propertyId = $propertyId; |
89 | 89 | $this->config = $config; |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | $this->snakSerializer = $snakSerializer; |
93 | 93 | } |
94 | 94 | |
95 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
95 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
96 | 96 | $parameters = []; |
97 | - foreach ( $qualifiers as $qualifier ) { |
|
97 | + foreach ($qualifiers as $qualifier) { |
|
98 | 98 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
99 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
99 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
100 | 100 | $parameters[$qualifierId][] = $paramSerialization; |
101 | 101 | } |
102 | 102 | return $parameters; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | ) { |
109 | 109 | $constraintId = $constraintStatement->getGuid(); |
110 | 110 | $constraintTypeQid = $constraintStatement->getMainSnak()->getDataValue()->getEntityId()->getSerialization(); |
111 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
111 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
112 | 112 | return new Constraint( |
113 | 113 | $constraintId, |
114 | 114 | $propertyId, |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | PropertyId $propertyConstraintPropertyId |
124 | 124 | ) { |
125 | 125 | $constraintsStatements = $property->getStatements() |
126 | - ->getByPropertyId( $propertyConstraintPropertyId ) |
|
127 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
126 | + ->getByPropertyId($propertyConstraintPropertyId) |
|
127 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
128 | 128 | $constraints = []; |
129 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
130 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
131 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
132 | - $constraintRepo->insertBatch( $constraints ); |
|
129 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
130 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
131 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
132 | + $constraintRepo->insertBatch($constraints); |
|
133 | 133 | $constraints = []; |
134 | 134 | } |
135 | 135 | } |
136 | - $constraintRepo->insertBatch( $constraints ); |
|
136 | + $constraintRepo->insertBatch($constraints); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -144,15 +144,15 @@ discard block |
||
144 | 144 | public function run() { |
145 | 145 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
146 | 146 | |
147 | - $propertyId = new PropertyId( $this->propertyId ); |
|
148 | - $this->constraintRepo->deleteForPropertyWhereConstraintIdIsStatementId( $propertyId ); |
|
147 | + $propertyId = new PropertyId($this->propertyId); |
|
148 | + $this->constraintRepo->deleteForPropertyWhereConstraintIdIsStatementId($propertyId); |
|
149 | 149 | |
150 | 150 | /** @var Property $property */ |
151 | - $property = $this->entityLookup->getEntity( $propertyId ); |
|
151 | + $property = $this->entityLookup->getEntity($propertyId); |
|
152 | 152 | $this->importConstraintsForProperty( |
153 | 153 | $property, |
154 | 154 | $this->constraintRepo, |
155 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
155 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
156 | 156 | ); |
157 | 157 | |
158 | 158 | return true; |
@@ -23,7 +23,7 @@ |
||
23 | 23 | */ |
24 | 24 | protected $snak; |
25 | 25 | |
26 | - public function __construct( EntityDocument $entity, Snak $snak ) { |
|
26 | + public function __construct(EntityDocument $entity, Snak $snak) { |
|
27 | 27 | $this->entity = $entity; |
28 | 28 | $this->snak = $snak; |
29 | 29 | } |
@@ -20,13 +20,13 @@ |
||
20 | 20 | * @param PropertyId $propertyId |
21 | 21 | * @return int |
22 | 22 | */ |
23 | - public function getPropertyCount( array $snaks, PropertyId $propertyId ) { |
|
24 | - return count( array_filter( |
|
23 | + public function getPropertyCount(array $snaks, PropertyId $propertyId) { |
|
24 | + return count(array_filter( |
|
25 | 25 | $snaks, |
26 | - function ( Snak $snak ) use ( $propertyId ) { |
|
27 | - return $snak->getPropertyId()->equals( $propertyId ); |
|
26 | + function(Snak $snak) use ($propertyId) { |
|
27 | + return $snak->getPropertyId()->equals($propertyId); |
|
28 | 28 | } |
29 | - ) ); |
|
29 | + )); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | } |
@@ -83,34 +83,34 @@ discard block |
||
83 | 83 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
84 | 84 | * @return CheckResult |
85 | 85 | */ |
86 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
87 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
88 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
86 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
87 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
88 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
89 | 89 | } |
90 | - if ( $context->getType() === Context::TYPE_REFERENCE ) { |
|
91 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE ); |
|
90 | + if ($context->getType() === Context::TYPE_REFERENCE) { |
|
91 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | $parameters = []; |
95 | 95 | $constraintParameters = $constraint->getConstraintParameters(); |
96 | 96 | |
97 | - $classes = $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
97 | + $classes = $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
98 | 98 | $parameters['class'] = array_map( |
99 | - function( $id ) { |
|
100 | - return new ItemId( $id ); |
|
99 | + function($id) { |
|
100 | + return new ItemId($id); |
|
101 | 101 | }, |
102 | 102 | $classes |
103 | 103 | ); |
104 | 104 | |
105 | - $relation = $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
105 | + $relation = $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
106 | 106 | $relationIds = []; |
107 | - if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) { |
|
108 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
107 | + if ($relation === 'instance' || $relation === 'instanceOrSubclass') { |
|
108 | + $relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
109 | 109 | } |
110 | - if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) { |
|
111 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
110 | + if ($relation === 'subclass' || $relation === 'instanceOrSubclass') { |
|
111 | + $relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
112 | 112 | } |
113 | - $parameters['relation'] = [ $relation ]; |
|
113 | + $parameters['relation'] = [$relation]; |
|
114 | 114 | |
115 | 115 | $result = $this->typeCheckerHelper->hasClassInRelation( |
116 | 116 | $context->getEntity()->getStatements(), |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $classes |
119 | 119 | ); |
120 | 120 | |
121 | - if ( $result->getBool() ) { |
|
121 | + if ($result->getBool()) { |
|
122 | 122 | $message = null; |
123 | 123 | $status = CheckResult::STATUS_COMPLIANCE; |
124 | 124 | } else { |
@@ -132,21 +132,21 @@ discard block |
||
132 | 132 | $status = CheckResult::STATUS_VIOLATION; |
133 | 133 | } |
134 | 134 | |
135 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
136 | - ->withMetadata( $result->getMetadata() ); |
|
135 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
136 | + ->withMetadata($result->getMetadata()); |
|
137 | 137 | } |
138 | 138 | |
139 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
139 | + public function checkConstraintParameters(Constraint $constraint) { |
|
140 | 140 | $constraintParameters = $constraint->getConstraintParameters(); |
141 | 141 | $exceptions = []; |
142 | 142 | try { |
143 | - $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
144 | - } catch ( ConstraintParameterException $e ) { |
|
143 | + $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
144 | + } catch (ConstraintParameterException $e) { |
|
145 | 145 | $exceptions[] = $e; |
146 | 146 | } |
147 | 147 | try { |
148 | - $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
149 | - } catch ( ConstraintParameterException $e ) { |
|
148 | + $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
149 | + } catch (ConstraintParameterException $e) { |
|
150 | 150 | $exceptions[] = $e; |
151 | 151 | } |
152 | 152 | return $exceptions; |
@@ -47,16 +47,16 @@ |
||
47 | 47 | * |
48 | 48 | * @return CheckResult |
49 | 49 | */ |
50 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
51 | - if ( $context->getType() === Context::TYPE_QUALIFIER ) { |
|
52 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
50 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
51 | + if ($context->getType() === Context::TYPE_QUALIFIER) { |
|
52 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
53 | 53 | } else { |
54 | - $message = new ViolationMessage( 'wbqc-violation-message-qualifier' ); |
|
55 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
54 | + $message = new ViolationMessage('wbqc-violation-message-qualifier'); |
|
55 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
59 | + public function checkConstraintParameters(Constraint $constraint) { |
|
60 | 60 | // no parameters |
61 | 61 | return []; |
62 | 62 | } |
@@ -36,16 +36,16 @@ |
||
36 | 36 | ]; |
37 | 37 | } |
38 | 38 | |
39 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
40 | - if ( $context->getType() === Context::TYPE_STATEMENT ) { |
|
41 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
39 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
40 | + if ($context->getType() === Context::TYPE_STATEMENT) { |
|
41 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
42 | 42 | } else { |
43 | - $message = new ViolationMessage( 'wbqc-violation-message-valueOnly' ); |
|
44 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
43 | + $message = new ViolationMessage('wbqc-violation-message-valueOnly'); |
|
44 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | |
48 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
48 | + public function checkConstraintParameters(Constraint $constraint) { |
|
49 | 49 | // no parameters |
50 | 50 | return []; |
51 | 51 | } |
@@ -36,16 +36,16 @@ |
||
36 | 36 | ]; |
37 | 37 | } |
38 | 38 | |
39 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
40 | - if ( $context->getType() === Context::TYPE_REFERENCE ) { |
|
41 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
39 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
40 | + if ($context->getType() === Context::TYPE_REFERENCE) { |
|
41 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
42 | 42 | } else { |
43 | - $message = new ViolationMessage( 'wbqc-violation-message-reference' ); |
|
44 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
43 | + $message = new ViolationMessage('wbqc-violation-message-reference'); |
|
44 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | |
48 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
48 | + public function checkConstraintParameters(Constraint $constraint) { |
|
49 | 49 | // no parameters |
50 | 50 | return []; |
51 | 51 | } |
@@ -71,40 +71,40 @@ |
||
71 | 71 | * @throws ConstraintParameterException |
72 | 72 | * @return CheckResult |
73 | 73 | */ |
74 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
75 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
76 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
74 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
75 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
76 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | $parameters = []; |
80 | 80 | $constraintParameters = $constraint->getConstraintParameters(); |
81 | 81 | |
82 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
83 | - $parameters['property'] = [ $propertyId ]; |
|
82 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
83 | + $parameters['property'] = [$propertyId]; |
|
84 | 84 | |
85 | - $message = ( new ViolationMessage( 'wbqc-violation-message-mandatory-qualifier' ) ) |
|
86 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
87 | - ->withEntityId( $propertyId, Role::QUALIFIER_PREDICATE ); |
|
85 | + $message = (new ViolationMessage('wbqc-violation-message-mandatory-qualifier')) |
|
86 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
87 | + ->withEntityId($propertyId, Role::QUALIFIER_PREDICATE); |
|
88 | 88 | $status = CheckResult::STATUS_VIOLATION; |
89 | 89 | |
90 | 90 | /** @var Snak $qualifier */ |
91 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
92 | - if ( $propertyId->equals( $qualifier->getPropertyId() ) ) { |
|
91 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
92 | + if ($propertyId->equals($qualifier->getPropertyId())) { |
|
93 | 93 | $message = null; |
94 | 94 | $status = CheckResult::STATUS_COMPLIANCE; |
95 | 95 | break; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
99 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
100 | 100 | } |
101 | 101 | |
102 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
102 | + public function checkConstraintParameters(Constraint $constraint) { |
|
103 | 103 | $constraintParameters = $constraint->getConstraintParameters(); |
104 | 104 | $exceptions = []; |
105 | 105 | try { |
106 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
107 | - } catch ( ConstraintParameterException $e ) { |
|
106 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
107 | + } catch (ConstraintParameterException $e) { |
|
108 | 108 | $exceptions[] = $e; |
109 | 109 | } |
110 | 110 | return $exceptions; |