@@ -70,43 +70,43 @@ |
||
70 | 70 | * @throws ConstraintParameterException |
71 | 71 | * @return CheckResult |
72 | 72 | */ |
73 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
74 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
75 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
73 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
74 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
75 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | $parameters = []; |
79 | 79 | $constraintParameters = $constraint->getConstraintParameters(); |
80 | 80 | |
81 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
82 | - $parameters['property'] = [ $propertyId ]; |
|
81 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
82 | + $parameters['property'] = [$propertyId]; |
|
83 | 83 | |
84 | - $message = wfMessage( "wbqc-violation-message-mandatory-qualifier" ) |
|
84 | + $message = wfMessage("wbqc-violation-message-mandatory-qualifier") |
|
85 | 85 | ->rawParams( |
86 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
87 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::QUALIFIER_PREDICATE ) |
|
86 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
87 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::QUALIFIER_PREDICATE) |
|
88 | 88 | ) |
89 | 89 | ->escaped(); |
90 | 90 | $status = CheckResult::STATUS_VIOLATION; |
91 | 91 | |
92 | 92 | /** @var Snak $qualifier */ |
93 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
94 | - if ( $propertyId->equals( $qualifier->getPropertyId() ) ) { |
|
93 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
94 | + if ($propertyId->equals($qualifier->getPropertyId())) { |
|
95 | 95 | $message = ''; |
96 | 96 | $status = CheckResult::STATUS_COMPLIANCE; |
97 | 97 | break; |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
101 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
102 | 102 | } |
103 | 103 | |
104 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
104 | + public function checkConstraintParameters(Constraint $constraint) { |
|
105 | 105 | $constraintParameters = $constraint->getConstraintParameters(); |
106 | 106 | $exceptions = []; |
107 | 107 | try { |
108 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
109 | - } catch ( ConstraintParameterException $e ) { |
|
108 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
109 | + } catch (ConstraintParameterException $e) { |
|
110 | 110 | $exceptions[] = $e; |
111 | 111 | } |
112 | 112 | return $exceptions; |
@@ -30,36 +30,36 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return bool |
32 | 32 | */ |
33 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
34 | - $updater->addExtensionTable( 'wbqc_constraints', __DIR__ . '/../sql/create_wbqc_constraints.sql' ); |
|
33 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
34 | + $updater->addExtensionTable('wbqc_constraints', __DIR__.'/../sql/create_wbqc_constraints.sql'); |
|
35 | 35 | return true; |
36 | 36 | } |
37 | 37 | |
38 | - public static function onWikibaseChange( Change $change ) { |
|
38 | + public static function onWikibaseChange(Change $change) { |
|
39 | 39 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
40 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
41 | - self::isConstraintStatementsChange( $config, $change ) |
|
40 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
41 | + self::isConstraintStatementsChange($config, $change) |
|
42 | 42 | ) { |
43 | 43 | /** @var EntityChange $change */ |
44 | 44 | $title = Title::newMainPage(); |
45 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
45 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
46 | 46 | JobQueueGroup::singleton()->push( |
47 | - new JobSpecification( 'constraintsTableUpdate', $params, [], $title ) |
|
47 | + new JobSpecification('constraintsTableUpdate', $params, [], $title) |
|
48 | 48 | ); |
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
53 | - if ( !( $change instanceof EntityChange ) || |
|
52 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
53 | + if (!($change instanceof EntityChange) || |
|
54 | 54 | $change->getAction() !== EntityChange::UPDATE || |
55 | - !( $change->getEntityId() instanceof PropertyId ) |
|
55 | + !($change->getEntityId() instanceof PropertyId) |
|
56 | 56 | ) { |
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $info = $change->getInfo(); |
61 | 61 | |
62 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
62 | + if (!array_key_exists('compactDiff', $info)) { |
|
63 | 63 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
64 | 64 | // so we only know that the change *might* affect the constraint statements |
65 | 65 | return true; |
@@ -68,18 +68,18 @@ discard block |
||
68 | 68 | /** @var EntityDiffChangedAspects $aspects */ |
69 | 69 | $aspects = $info['compactDiff']; |
70 | 70 | |
71 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
72 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
71 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
72 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
73 | 73 | } |
74 | 74 | |
75 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
75 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
76 | 76 | $repo = WikibaseRepo::getDefaultInstance(); |
77 | 77 | |
78 | 78 | $entityContentFactory = $repo->getEntityContentFactory(); |
79 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
80 | - $entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
79 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
80 | + $entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle()); |
|
81 | 81 | $resultsCache = ResultsCache::getDefaultInstance(); |
82 | - $resultsCache->delete( $entityId ); |
|
82 | + $resultsCache->delete($entityId); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -88,18 +88,18 @@ discard block |
||
88 | 88 | * @param int $timestamp UTC timestamp (seconds since the Epoch) |
89 | 89 | * @return bool |
90 | 90 | */ |
91 | - public static function isGadgetEnabledForUserName( $userName, $timestamp ) { |
|
91 | + public static function isGadgetEnabledForUserName($userName, $timestamp) { |
|
92 | 92 | $initial = $userName[0]; |
93 | 93 | |
94 | - if ( $initial === 'Z' ) { |
|
94 | + if ($initial === 'Z') { |
|
95 | 95 | $firstWeek = 0; |
96 | - } elseif ( $initial >= 'W' && $initial < 'Z' ) { |
|
96 | + } elseif ($initial >= 'W' && $initial < 'Z') { |
|
97 | 97 | $firstWeek = 1; |
98 | - } elseif ( $initial >= 'T' && $initial < 'W' ) { |
|
98 | + } elseif ($initial >= 'T' && $initial < 'W') { |
|
99 | 99 | $firstWeek = 2; |
100 | - } elseif ( $initial >= 'N' && $initial < 'T' ) { |
|
100 | + } elseif ($initial >= 'N' && $initial < 'T') { |
|
101 | 101 | $firstWeek = 3; |
102 | - } elseif ( $initial >= 'E' && $initial < 'N' ) { |
|
102 | + } elseif ($initial >= 'E' && $initial < 'N') { |
|
103 | 103 | $firstWeek = 4; |
104 | 104 | } else { |
105 | 105 | $firstWeek = 5; |
@@ -117,24 +117,24 @@ discard block |
||
117 | 117 | return $timestamp >= $threshold; |
118 | 118 | } |
119 | 119 | |
120 | - public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) { |
|
120 | + public static function onBeforePageDisplay(OutputPage &$out, Skin &$skin) { |
|
121 | 121 | $repo = WikibaseRepo::getDefaultInstance(); |
122 | 122 | |
123 | 123 | $lookup = $repo->getEntityNamespaceLookup(); |
124 | 124 | $title = $out->getTitle(); |
125 | - if ( $title === null ) { |
|
125 | + if ($title === null) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | - if ( !$lookup->isEntityNamespace( $title->getNamespace() ) ) { |
|
129 | + if (!$lookup->isEntityNamespace($title->getNamespace())) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | - if ( !$out->getUser()->isLoggedIn() ) { |
|
132 | + if (!$out->getUser()->isLoggedIn()) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | - if ( self::isGadgetEnabledForUserName( $out->getUser()->getName(), time() ) ) { |
|
137 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
136 | + if (self::isGadgetEnabledForUserName($out->getUser()->getName(), time())) { |
|
137 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param ItemId $itemId |
45 | 45 | * @return self |
46 | 46 | */ |
47 | - public static function fromItemId( ItemId $itemId ) { |
|
47 | + public static function fromItemId(ItemId $itemId) { |
|
48 | 48 | $ret = new self; |
49 | 49 | $ret->itemId = $itemId; |
50 | 50 | return $ret; |
@@ -80,14 +80,14 @@ discard block |
||
80 | 80 | * @throws InvalidArgumentException |
81 | 81 | * @return self |
82 | 82 | */ |
83 | - public static function fromSnak( Snak $snak ) { |
|
84 | - switch ( true ) { |
|
83 | + public static function fromSnak(Snak $snak) { |
|
84 | + switch (true) { |
|
85 | 85 | case $snak instanceof PropertyValueSnak: |
86 | 86 | $dataValue = $snak->getDataValue(); |
87 | - if ( $dataValue instanceof EntityIdValue |
|
87 | + if ($dataValue instanceof EntityIdValue |
|
88 | 88 | && $dataValue->getEntityId() instanceof ItemId |
89 | 89 | ) { |
90 | - return self::fromItemId( $dataValue->getEntityId() ); |
|
90 | + return self::fromItemId($dataValue->getEntityId()); |
|
91 | 91 | } |
92 | 92 | break; |
93 | 93 | case $snak instanceof PropertySomeValueSnak: |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | return self::noValue(); |
97 | 97 | } |
98 | 98 | |
99 | - throw new InvalidArgumentException( 'Snak must contain item ID value or be a somevalue / novalue snak' ); |
|
99 | + throw new InvalidArgumentException('Snak must contain item ID value or be a somevalue / novalue snak'); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | * @return ItemId |
134 | 134 | */ |
135 | 135 | public function getItemId() { |
136 | - if ( ! $this->isValue() ) { |
|
137 | - throw new DomainException( 'This value does not contain an item ID.' ); |
|
136 | + if (!$this->isValue()) { |
|
137 | + throw new DomainException('This value does not contain an item ID.'); |
|
138 | 138 | } |
139 | 139 | return $this->itemId; |
140 | 140 | } |
@@ -146,13 +146,13 @@ discard block |
||
146 | 146 | * @param Snak $snak |
147 | 147 | * @return bool |
148 | 148 | */ |
149 | - public function matchesSnak( Snak $snak ) { |
|
150 | - switch ( true ) { |
|
149 | + public function matchesSnak(Snak $snak) { |
|
150 | + switch (true) { |
|
151 | 151 | case $snak instanceof PropertyValueSnak: |
152 | 152 | return $this->isValue() && |
153 | 153 | $snak->getDataValue() instanceof EntityIdValue && |
154 | 154 | $snak->getDataValue()->getEntityId() instanceof ItemId && |
155 | - $snak->getDataValue()->getEntityId()->equals( $this->getItemId() ); |
|
155 | + $snak->getDataValue()->getEntityId()->equals($this->getItemId()); |
|
156 | 156 | case $snak instanceof PropertySomeValueSnak: |
157 | 157 | return $this->isSomeValue(); |
158 | 158 | case $snak instanceof PropertyNoValueSnak: |
@@ -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; |
@@ -75,54 +75,53 @@ discard block |
||
75 | 75 | ) { |
76 | 76 | $response = []; |
77 | 77 | $metadatas = []; |
78 | - $statusesFlipped = array_flip( $statuses ); |
|
79 | - foreach ( $entityIds as $entityId ) { |
|
78 | + $statusesFlipped = array_flip($statuses); |
|
79 | + foreach ($entityIds as $entityId) { |
|
80 | 80 | $results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnEntityId( |
81 | 81 | $entityId, |
82 | 82 | $constraintIds, |
83 | - [ $this, 'defaultResults' ] |
|
83 | + [$this, 'defaultResults'] |
|
84 | 84 | ); |
85 | - $results = array_filter( $results, $this->statusSelected( $statusesFlipped ) ); |
|
86 | - foreach ( $results as $result ) { |
|
85 | + $results = array_filter($results, $this->statusSelected($statusesFlipped)); |
|
86 | + foreach ($results as $result) { |
|
87 | 87 | $metadatas[] = $result->getMetadata(); |
88 | - $resultArray = $this->checkResultToArray( $result ); |
|
89 | - $result->getContext()->storeCheckResultInArray( $resultArray, $response ); |
|
88 | + $resultArray = $this->checkResultToArray($result); |
|
89 | + $result->getContext()->storeCheckResultInArray($resultArray, $response); |
|
90 | 90 | } |
91 | 91 | } |
92 | - foreach ( $claimIds as $claimId ) { |
|
92 | + foreach ($claimIds as $claimId) { |
|
93 | 93 | $results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnClaimId( |
94 | 94 | $claimId, |
95 | 95 | $constraintIds, |
96 | - [ $this, 'defaultResults' ] |
|
96 | + [$this, 'defaultResults'] |
|
97 | 97 | ); |
98 | - $results = array_filter( $results, $this->statusSelected( $statusesFlipped ) ); |
|
99 | - foreach ( $results as $result ) { |
|
98 | + $results = array_filter($results, $this->statusSelected($statusesFlipped)); |
|
99 | + foreach ($results as $result) { |
|
100 | 100 | $metadatas[] = $result->getMetadata(); |
101 | - $resultArray = $this->checkResultToArray( $result ); |
|
102 | - $result->getContext()->storeCheckResultInArray( $resultArray, $response ); |
|
101 | + $resultArray = $this->checkResultToArray($result); |
|
102 | + $result->getContext()->storeCheckResultInArray($resultArray, $response); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | return new CachedCheckConstraintsResponse( |
106 | 106 | $response, |
107 | - Metadata::merge( $metadatas ) |
|
107 | + Metadata::merge($metadatas) |
|
108 | 108 | ); |
109 | 109 | } |
110 | 110 | |
111 | - public function defaultResults( Context $context ) { |
|
111 | + public function defaultResults(Context $context) { |
|
112 | 112 | return $context->getType() === Context::TYPE_STATEMENT ? |
113 | - [ new NullResult( $context ) ] : |
|
114 | - []; |
|
113 | + [new NullResult($context)] : []; |
|
115 | 114 | } |
116 | 115 | |
117 | - public function statusSelected( array $statusesFlipped ) { |
|
118 | - return function( CheckResult $result ) use ( $statusesFlipped ) { |
|
119 | - return array_key_exists( $result->getStatus(), $statusesFlipped ) || |
|
116 | + public function statusSelected(array $statusesFlipped) { |
|
117 | + return function(CheckResult $result) use ($statusesFlipped) { |
|
118 | + return array_key_exists($result->getStatus(), $statusesFlipped) || |
|
120 | 119 | $result instanceof NullResult; |
121 | 120 | }; |
122 | 121 | } |
123 | 122 | |
124 | - public function checkResultToArray( CheckResult $checkResult ) { |
|
125 | - if ( $checkResult instanceof NullResult ) { |
|
123 | + public function checkResultToArray(CheckResult $checkResult) { |
|
124 | + if ($checkResult instanceof NullResult) { |
|
126 | 125 | return null; |
127 | 126 | } |
128 | 127 | |
@@ -130,10 +129,10 @@ discard block |
||
130 | 129 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
131 | 130 | $constraintPropertyId = $checkResult->getContext()->getSnak()->getPropertyId(); |
132 | 131 | |
133 | - $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
134 | - $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
132 | + $title = $this->entityTitleLookup->getTitleForId($constraintPropertyId); |
|
133 | + $typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId)); |
|
135 | 134 | // TODO link to the statement when possible (T169224) |
136 | - $link = $title->getFullURL() . '#' . $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
135 | + $link = $title->getFullURL().'#'.$this->config->get('WBQualityConstraintsPropertyConstraintId'); |
|
137 | 136 | |
138 | 137 | $constraint = [ |
139 | 138 | 'id' => $constraintId, |
@@ -142,11 +141,11 @@ discard block |
||
142 | 141 | 'link' => $link, |
143 | 142 | 'discussLink' => $title->getTalkPage()->getFullURL(), |
144 | 143 | ]; |
145 | - if ( $this->config->get( 'WBQualityConstraintsIncludeDetailInApi' ) ) { |
|
144 | + if ($this->config->get('WBQualityConstraintsIncludeDetailInApi')) { |
|
146 | 145 | $parameters = $checkResult->getParameters(); |
147 | 146 | $constraint += [ |
148 | 147 | 'detail' => $parameters, |
149 | - 'detailHTML' => $this->constraintParameterRenderer->formatParameters( $parameters ), |
|
148 | + 'detailHTML' => $this->constraintParameterRenderer->formatParameters($parameters), |
|
150 | 149 | ]; |
151 | 150 | } |
152 | 151 | |
@@ -156,14 +155,14 @@ discard block |
||
156 | 155 | 'constraint' => $constraint |
157 | 156 | ]; |
158 | 157 | $message = $checkResult->getMessage(); |
159 | - if ( $message ) { |
|
158 | + if ($message) { |
|
160 | 159 | $result['message-html'] = $message; |
161 | 160 | } |
162 | - if ( $checkResult->getContext()->getType() === Context::TYPE_STATEMENT ) { |
|
161 | + if ($checkResult->getContext()->getType() === Context::TYPE_STATEMENT) { |
|
163 | 162 | $result['claim'] = $checkResult->getContext()->getSnakStatement()->getGuid(); |
164 | 163 | } |
165 | 164 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
166 | - if ( $cachingMetadataArray !== null ) { |
|
165 | + if ($cachingMetadataArray !== null) { |
|
167 | 166 | $result['cached'] = $cachingMetadataArray; |
168 | 167 | } |
169 | 168 |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | ) { |
135 | 135 | $results = []; |
136 | 136 | $metadatas = []; |
137 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
137 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
138 | 138 | $storedEntityIds = []; |
139 | - foreach ( $entityIds as $entityId ) { |
|
140 | - $storedResults = $this->getStoredResults( $entityId ); |
|
141 | - if ( $storedResults !== null ) { |
|
139 | + foreach ($entityIds as $entityId) { |
|
140 | + $storedResults = $this->getStoredResults($entityId); |
|
141 | + if ($storedResults !== null) { |
|
142 | 142 | $this->dataFactory->increment( |
143 | 143 | 'wikibase.quality.constraints.cache.entity.hit' |
144 | 144 | ); |
@@ -147,20 +147,20 @@ discard block |
||
147 | 147 | $storedEntityIds[] = $entityId; |
148 | 148 | } |
149 | 149 | } |
150 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
150 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
151 | 151 | } |
152 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
152 | + if ($entityIds !== [] || $claimIds !== []) { |
|
153 | 153 | $this->dataFactory->updateCount( |
154 | 154 | 'wikibase.quality.constraints.cache.entity.miss', |
155 | - count( $entityIds ) |
|
155 | + count($entityIds) |
|
156 | 156 | ); |
157 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
157 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
158 | 158 | $results += $response->getArray(); |
159 | 159 | $metadatas[] = $response->getMetadata(); |
160 | 160 | } |
161 | 161 | return new CachedCheckConstraintsResponse( |
162 | 162 | $results, |
163 | - Metadata::merge( $metadatas ) |
|
163 | + Metadata::merge($metadatas) |
|
164 | 164 | ); |
165 | 165 | } |
166 | 166 | |
@@ -189,13 +189,13 @@ discard block |
||
189 | 189 | array $constraintIds = null, |
190 | 190 | array $statuses |
191 | 191 | ) { |
192 | - if ( $claimIds !== [] ) { |
|
192 | + if ($claimIds !== []) { |
|
193 | 193 | return false; |
194 | 194 | } |
195 | - if ( $constraintIds !== null ) { |
|
195 | + if ($constraintIds !== null) { |
|
196 | 196 | return false; |
197 | 197 | } |
198 | - if ( $statuses != $this->cachedStatuses ) { |
|
198 | + if ($statuses != $this->cachedStatuses) { |
|
199 | 199 | return false; |
200 | 200 | } |
201 | 201 | return true; |
@@ -214,17 +214,17 @@ discard block |
||
214 | 214 | array $constraintIds = null, |
215 | 215 | array $statuses |
216 | 216 | ) { |
217 | - $results = $this->resultsBuilder->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
217 | + $results = $this->resultsBuilder->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
218 | 218 | |
219 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
220 | - foreach ( $entityIds as $entityId ) { |
|
219 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
220 | + foreach ($entityIds as $entityId) { |
|
221 | 221 | $value = [ |
222 | 222 | 'results' => $results->getArray()[$entityId->getSerialization()], |
223 | 223 | 'latestRevisionIds' => $this->getLatestRevisionIds( |
224 | 224 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
225 | 225 | ), |
226 | 226 | ]; |
227 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
227 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
@@ -256,10 +256,10 @@ discard block |
||
256 | 256 | array $constraintIds = null, |
257 | 257 | array $statuses |
258 | 258 | ) { |
259 | - if ( $constraintIds !== null ) { |
|
259 | + if ($constraintIds !== null) { |
|
260 | 260 | return false; |
261 | 261 | } |
262 | - if ( $statuses != $this->cachedStatuses ) { |
|
262 | + if ($statuses != $this->cachedStatuses) { |
|
263 | 263 | return false; |
264 | 264 | } |
265 | 265 | return true; |
@@ -272,45 +272,44 @@ discard block |
||
272 | 272 | public function getStoredResults( |
273 | 273 | EntityId $entityId |
274 | 274 | ) { |
275 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
276 | - $now = call_user_func( $this->microtime, true ); |
|
275 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
276 | + $now = call_user_func($this->microtime, true); |
|
277 | 277 | |
278 | - if ( $value === false ) { |
|
278 | + if ($value === false) { |
|
279 | 279 | return null; |
280 | 280 | } |
281 | 281 | |
282 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
282 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
283 | 283 | |
284 | 284 | $dependedEntityIds = array_map( |
285 | - [ $this->entityIdParser, "parse" ], |
|
286 | - array_keys( $value['latestRevisionIds'] ) |
|
285 | + [$this->entityIdParser, "parse"], |
|
286 | + array_keys($value['latestRevisionIds']) |
|
287 | 287 | ); |
288 | 288 | |
289 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
289 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
290 | 290 | return null; |
291 | 291 | } |
292 | 292 | |
293 | 293 | $cachingMetadata = $ageInSeconds > 0 ? |
294 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
295 | - CachingMetadata::fresh(); |
|
294 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
296 | 295 | |
297 | - if ( is_array( $value['results'] ) ) { |
|
298 | - array_walk( $value['results'], [ $this, 'updateCachingMetadata' ], $cachingMetadata ); |
|
296 | + if (is_array($value['results'])) { |
|
297 | + array_walk($value['results'], [$this, 'updateCachingMetadata'], $cachingMetadata); |
|
299 | 298 | } |
300 | 299 | |
301 | 300 | return new CachedCheckConstraintsResponse( |
302 | - [ $entityId->getSerialization() => $value['results'] ], |
|
301 | + [$entityId->getSerialization() => $value['results']], |
|
303 | 302 | array_reduce( |
304 | 303 | $dependedEntityIds, |
305 | - function( Metadata $metadata, EntityId $entityId ) { |
|
306 | - return Metadata::merge( [ |
|
304 | + function(Metadata $metadata, EntityId $entityId) { |
|
305 | + return Metadata::merge([ |
|
307 | 306 | $metadata, |
308 | 307 | Metadata::ofDependencyMetadata( |
309 | - DependencyMetadata::ofEntityId( $entityId ) |
|
308 | + DependencyMetadata::ofEntityId($entityId) |
|
310 | 309 | ) |
311 | - ] ); |
|
310 | + ]); |
|
312 | 311 | }, |
313 | - Metadata::ofCachingMetadata( $cachingMetadata ) |
|
312 | + Metadata::ofCachingMetadata($cachingMetadata) |
|
314 | 313 | ) |
315 | 314 | ); |
316 | 315 | } |
@@ -319,39 +318,39 @@ discard block |
||
319 | 318 | * @param EntityId[] $entityIds |
320 | 319 | * @return int[] |
321 | 320 | */ |
322 | - private function getLatestRevisionIds( array $entityIds ) { |
|
321 | + private function getLatestRevisionIds(array $entityIds) { |
|
323 | 322 | $revisionInformations = $this->wikiPageEntityMetaDataAccessor->loadRevisionInformation( |
324 | 323 | $entityIds, |
325 | 324 | EntityRevisionLookup::LATEST_FROM_REPLICA |
326 | 325 | ); |
327 | 326 | $latestRevisionIds = []; |
328 | - foreach ( $revisionInformations as $serialization => $revisionInformation ) { |
|
327 | + foreach ($revisionInformations as $serialization => $revisionInformation) { |
|
329 | 328 | $latestRevisionIds[$serialization] = $revisionInformation->page_latest; |
330 | 329 | } |
331 | 330 | return $latestRevisionIds; |
332 | 331 | } |
333 | 332 | |
334 | - public function updateCachingMetadata( &$element, $key, CachingMetadata $cachingMetadata ) { |
|
335 | - if ( $key === 'cached' ) { |
|
336 | - $element = CachingMetadata::merge( [ |
|
333 | + public function updateCachingMetadata(&$element, $key, CachingMetadata $cachingMetadata) { |
|
334 | + if ($key === 'cached') { |
|
335 | + $element = CachingMetadata::merge([ |
|
337 | 336 | $cachingMetadata, |
338 | - CachingMetadata::ofArray( $element ), |
|
339 | - ] )->toArray(); |
|
337 | + CachingMetadata::ofArray($element), |
|
338 | + ])->toArray(); |
|
340 | 339 | } |
341 | 340 | if ( |
342 | - is_array( $element ) && |
|
343 | - array_key_exists( 'constraint', $element ) && |
|
344 | - in_array( $element['constraint']['type'], $this->possiblyStaleConstraintTypes, true ) |
|
341 | + is_array($element) && |
|
342 | + array_key_exists('constraint', $element) && |
|
343 | + in_array($element['constraint']['type'], $this->possiblyStaleConstraintTypes, true) |
|
345 | 344 | ) { |
346 | - $element['cached'] = CachingMetadata::merge( [ |
|
345 | + $element['cached'] = CachingMetadata::merge([ |
|
347 | 346 | $cachingMetadata, |
348 | 347 | CachingMetadata::ofArray( |
349 | - array_key_exists( 'cached', $element ) ? $element['cached'] : null |
|
348 | + array_key_exists('cached', $element) ? $element['cached'] : null |
|
350 | 349 | ), |
351 | - ] )->toArray(); |
|
350 | + ])->toArray(); |
|
352 | 351 | } |
353 | - if ( is_array( $element ) ) { |
|
354 | - array_walk( $element, [ $this, __FUNCTION__ ], $cachingMetadata ); |
|
352 | + if (is_array($element)) { |
|
353 | + array_walk($element, [$this, __FUNCTION__], $cachingMetadata); |
|
355 | 354 | } |
356 | 355 | } |
357 | 356 | |
@@ -360,7 +359,7 @@ discard block |
||
360 | 359 | * |
361 | 360 | * @param callable $microtime |
362 | 361 | */ |
363 | - public function setMicrotimeFunction( callable $microtime ) { |
|
362 | + public function setMicrotimeFunction(callable $microtime) { |
|
364 | 363 | $this->microtime = $microtime; |
365 | 364 | } |
366 | 365 |
@@ -76,21 +76,21 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return self |
78 | 78 | */ |
79 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
79 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
80 | 80 | $repo = WikibaseRepo::getDefaultInstance(); |
81 | 81 | |
82 | 82 | $language = $repo->getUserLanguage(); |
83 | 83 | $formatterOptions = new FormatterOptions(); |
84 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
84 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
85 | 85 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
86 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
86 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
87 | 87 | |
88 | 88 | $languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory(); |
89 | - $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language ); |
|
89 | + $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language); |
|
90 | 90 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
91 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
91 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
92 | 92 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
93 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
93 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
94 | 94 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
95 | 95 | $titleParser = MediaWikiServices::getInstance()->getTitleParser(); |
96 | 96 | $unitConverter = $repo->getUnitConverter(); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | $constraintParameterRenderer, |
126 | 126 | $config |
127 | 127 | ); |
128 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
128 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
129 | 129 | $wikiPageEntityMetaDataAccessor = new WikiPageEntityMetaDataLookup( |
130 | 130 | $repo->getEntityNamespaceLookup() |
131 | 131 | ); |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | ResultsCache::getDefaultInstance(), |
137 | 137 | $wikiPageEntityMetaDataAccessor, |
138 | 138 | $entityIdParser, |
139 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
139 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
140 | 140 | [ |
141 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
142 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
143 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
144 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
141 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
142 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
143 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
144 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
145 | 145 | ], |
146 | 146 | $dataFactory |
147 | 147 | ); |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $prefix, |
154 | 154 | $repo->getEntityIdParser(), |
155 | 155 | $repo->getStatementGuidValidator(), |
156 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
156 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
157 | 157 | $resultsBuilder, |
158 | 158 | $dataFactory |
159 | 159 | ); |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | ResultsBuilder $resultsBuilder, |
180 | 180 | IBufferingStatsdDataFactory $dataFactory |
181 | 181 | ) { |
182 | - parent::__construct( $main, $name, $prefix ); |
|
182 | + parent::__construct($main, $name, $prefix); |
|
183 | 183 | $this->entityIdParser = $entityIdParser; |
184 | 184 | $this->statementGuidValidator = $statementGuidValidator; |
185 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
186 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
185 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
186 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
187 | 187 | $this->resultsBuilder = $resultsBuilder; |
188 | 188 | $this->dataFactory = $dataFactory; |
189 | 189 | } |
@@ -198,9 +198,9 @@ discard block |
||
198 | 198 | |
199 | 199 | $params = $this->extractRequestParams(); |
200 | 200 | |
201 | - $this->validateParameters( $params ); |
|
202 | - $entityIds = $this->parseEntityIds( $params ); |
|
203 | - $claimIds = $this->parseClaimIds( $params ); |
|
201 | + $this->validateParameters($params); |
|
202 | + $entityIds = $this->parseEntityIds($params); |
|
203 | + $claimIds = $this->parseClaimIds($params); |
|
204 | 204 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
205 | 205 | $statuses = $params[self::PARAM_STATUS]; |
206 | 206 | |
@@ -215,13 +215,13 @@ discard block |
||
215 | 215 | )->getArray() |
216 | 216 | ); |
217 | 217 | // ensure that result contains the given entity IDs even if they have no statements |
218 | - foreach ( $entityIds as $entityId ) { |
|
218 | + foreach ($entityIds as $entityId) { |
|
219 | 219 | $this->getResult()->addArrayType( |
220 | - [ $this->getModuleName(), $entityId->getSerialization() ], |
|
220 | + [$this->getModuleName(), $entityId->getSerialization()], |
|
221 | 221 | 'assoc' |
222 | 222 | ); |
223 | 223 | } |
224 | - $this->resultBuilder->markSuccess( 1 ); |
|
224 | + $this->resultBuilder->markSuccess(1); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -229,24 +229,24 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @return EntityId[] |
231 | 231 | */ |
232 | - private function parseEntityIds( array $params ) { |
|
232 | + private function parseEntityIds(array $params) { |
|
233 | 233 | $ids = $params[self::PARAM_ID]; |
234 | 234 | |
235 | - if ( $ids === null ) { |
|
235 | + if ($ids === null) { |
|
236 | 236 | return []; |
237 | - } elseif ( $ids === [] ) { |
|
237 | + } elseif ($ids === []) { |
|
238 | 238 | $this->errorReporter->dieError( |
239 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
239 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
240 | 240 | } |
241 | 241 | |
242 | - return array_map( function ( $id ) { |
|
242 | + return array_map(function($id) { |
|
243 | 243 | try { |
244 | - return $this->entityIdParser->parse( $id ); |
|
245 | - } catch ( EntityIdParsingException $e ) { |
|
244 | + return $this->entityIdParser->parse($id); |
|
245 | + } catch (EntityIdParsingException $e) { |
|
246 | 246 | $this->errorReporter->dieError( |
247 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
247 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
248 | 248 | } |
249 | - }, $ids ); |
|
249 | + }, $ids); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -254,35 +254,35 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @return string[] |
256 | 256 | */ |
257 | - private function parseClaimIds( array $params ) { |
|
257 | + private function parseClaimIds(array $params) { |
|
258 | 258 | $ids = $params[self::PARAM_CLAIM_ID]; |
259 | 259 | |
260 | - if ( $ids === null ) { |
|
260 | + if ($ids === null) { |
|
261 | 261 | return []; |
262 | - } elseif ( $ids === [] ) { |
|
262 | + } elseif ($ids === []) { |
|
263 | 263 | $this->errorReporter->dieError( |
264 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
264 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
265 | 265 | } |
266 | 266 | |
267 | - foreach ( $ids as $id ) { |
|
268 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
267 | + foreach ($ids as $id) { |
|
268 | + if (!$this->statementGuidValidator->validate($id)) { |
|
269 | 269 | $this->errorReporter->dieError( |
270 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
270 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | 274 | return $ids; |
275 | 275 | } |
276 | 276 | |
277 | - private function validateParameters( array $params ) { |
|
278 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
279 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
277 | + private function validateParameters(array $params) { |
|
278 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
279 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
280 | 280 | ) { |
281 | 281 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
282 | 282 | $this->errorReporter->dieError( |
283 | 283 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
284 | 284 | } |
285 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
285 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
286 | 286 | $paramId = self::PARAM_ID; |
287 | 287 | $paramClaimId = self::PARAM_CLAIM_ID; |
288 | 288 | $this->errorReporter->dieError( |
@@ -104,37 +104,37 @@ discard block |
||
104 | 104 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
105 | 105 | * @return CheckResult |
106 | 106 | */ |
107 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
108 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
109 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
107 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
108 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
109 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | $parameters = []; |
113 | 113 | $constraintParameters = $constraint->getConstraintParameters(); |
114 | 114 | |
115 | - $classes = $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
115 | + $classes = $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
116 | 116 | $parameters['class'] = array_map( |
117 | - function( $id ) { |
|
118 | - return new ItemId( $id ); |
|
117 | + function($id) { |
|
118 | + return new ItemId($id); |
|
119 | 119 | }, |
120 | 120 | $classes |
121 | 121 | ); |
122 | 122 | |
123 | - $relation = $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
123 | + $relation = $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
124 | 124 | $relationIds = []; |
125 | - if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) { |
|
126 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
125 | + if ($relation === 'instance' || $relation === 'instanceOrSubclass') { |
|
126 | + $relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
127 | 127 | } |
128 | - if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) { |
|
129 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
128 | + if ($relation === 'subclass' || $relation === 'instanceOrSubclass') { |
|
129 | + $relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
130 | 130 | } |
131 | - $parameters['relation'] = [ $relation ]; |
|
131 | + $parameters['relation'] = [$relation]; |
|
132 | 132 | |
133 | 133 | $snak = $context->getSnak(); |
134 | 134 | |
135 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
135 | + if (!$snak instanceof PropertyValueSnak) { |
|
136 | 136 | // nothing to check |
137 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
137 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $dataValue = $snak->getDataValue(); |
@@ -143,22 +143,22 @@ discard block |
||
143 | 143 | * error handling: |
144 | 144 | * type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid' |
145 | 145 | */ |
146 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
147 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
146 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
147 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
148 | 148 | ->rawParams( |
149 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
149 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
150 | 150 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
151 | 151 | ) |
152 | 152 | ->escaped(); |
153 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
153 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
154 | 154 | } |
155 | 155 | /** @var EntityIdValue $dataValue */ |
156 | 156 | |
157 | - $item = $this->entityLookup->getEntity( $dataValue->getEntityId() ); |
|
157 | + $item = $this->entityLookup->getEntity($dataValue->getEntityId()); |
|
158 | 158 | |
159 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
160 | - $message = wfMessage( "wbqc-violation-message-value-entity-must-exist" )->escaped(); |
|
161 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
159 | + if (!($item instanceof StatementListProvider)) { |
|
160 | + $message = wfMessage("wbqc-violation-message-value-entity-must-exist")->escaped(); |
|
161 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | $statements = $item->getStatements(); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | $classes |
170 | 170 | ); |
171 | 171 | |
172 | - if ( $result->getBool() ) { |
|
172 | + if ($result->getBool()) { |
|
173 | 173 | $message = ''; |
174 | 174 | $status = CheckResult::STATUS_COMPLIANCE; |
175 | 175 | } else { |
@@ -183,21 +183,21 @@ discard block |
||
183 | 183 | $status = CheckResult::STATUS_VIOLATION; |
184 | 184 | } |
185 | 185 | |
186 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
187 | - ->withMetadata( $result->getMetadata() ); |
|
186 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
187 | + ->withMetadata($result->getMetadata()); |
|
188 | 188 | } |
189 | 189 | |
190 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
190 | + public function checkConstraintParameters(Constraint $constraint) { |
|
191 | 191 | $constraintParameters = $constraint->getConstraintParameters(); |
192 | 192 | $exceptions = []; |
193 | 193 | try { |
194 | - $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
195 | - } catch ( ConstraintParameterException $e ) { |
|
194 | + $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
195 | + } catch (ConstraintParameterException $e) { |
|
196 | 196 | $exceptions[] = $e; |
197 | 197 | } |
198 | 198 | try { |
199 | - $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
200 | - } catch ( ConstraintParameterException $e ) { |
|
199 | + $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
200 | + } catch (ConstraintParameterException $e) { |
|
201 | 201 | $exceptions[] = $e; |
202 | 202 | } |
203 | 203 | return $exceptions; |