@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Cache; |
6 | 6 |
@@ -15,12 +15,12 @@ |
||
15 | 15 | /** |
16 | 16 | * @param DatabaseUpdater $updater |
17 | 17 | */ |
18 | - public function onLoadExtensionSchemaUpdates( $updater ) { |
|
19 | - $dir = dirname( __DIR__ ) . '/sql/'; |
|
18 | + public function onLoadExtensionSchemaUpdates($updater) { |
|
19 | + $dir = dirname(__DIR__).'/sql/'; |
|
20 | 20 | |
21 | 21 | $updater->addExtensionTable( |
22 | 22 | 'wbqc_constraints', |
23 | - $dir . "/{$updater->getDB()->getType()}/tables-generated.sql" |
|
23 | + $dir."/{$updater->getDB()->getType()}/tables-generated.sql" |
|
24 | 24 | ); |
25 | 25 | } |
26 | 26 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker; |
6 | 6 | |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | private ConstraintParameterParser $constraintParameterParser; |
24 | 24 | |
25 | - public function __construct( ConstraintParameterParser $constraintParameterParser ) { |
|
25 | + public function __construct(ConstraintParameterParser $constraintParameterParser) { |
|
26 | 26 | $this->constraintParameterParser = $constraintParameterParser; |
27 | 27 | } |
28 | 28 | |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @throws ConstraintParameterException |
66 | 66 | */ |
67 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
68 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
69 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
67 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
68 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
69 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -77,21 +77,21 @@ discard block |
||
77 | 77 | ); |
78 | 78 | |
79 | 79 | $status = CheckResult::STATUS_VIOLATION; |
80 | - $message = ( new ViolationMessage( 'wbqc-violation-message-label-lacking' ) ) |
|
81 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
82 | - ->withLanguages( $languages ); |
|
80 | + $message = (new ViolationMessage('wbqc-violation-message-label-lacking')) |
|
81 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
82 | + ->withLanguages($languages); |
|
83 | 83 | |
84 | 84 | /** @var LabelsProvider $entity */ |
85 | 85 | $entity = $context->getEntity(); |
86 | 86 | '@phan-var LabelsProvider $entity'; |
87 | 87 | $labels = $entity->getLabels(); |
88 | 88 | |
89 | - if ( $labels->hasTermForLanguage( 'mul' ) ) { |
|
89 | + if ($labels->hasTermForLanguage('mul')) { |
|
90 | 90 | $message = null; |
91 | 91 | $status = CheckResult::STATUS_COMPLIANCE; |
92 | 92 | } else { |
93 | - foreach ( $languages as $language ) { |
|
94 | - if ( $labels->hasTermForLanguage( $language ) ) { |
|
93 | + foreach ($languages as $language) { |
|
94 | + if ($labels->hasTermForLanguage($language)) { |
|
95 | 95 | $message = null; |
96 | 96 | $status = CheckResult::STATUS_COMPLIANCE; |
97 | 97 | break; |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - return new CheckResult( $context, $constraint, $status, $message ); |
|
102 | + return new CheckResult($context, $constraint, $status, $message); |
|
103 | 103 | } |
104 | 104 | |
105 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
105 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
106 | 106 | $constraintParameters = $constraint->getConstraintParameters(); |
107 | 107 | $exceptions = []; |
108 | 108 | try { |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $constraintParameters, |
111 | 111 | $constraint->getConstraintTypeItemId() |
112 | 112 | ); |
113 | - } catch ( ConstraintParameterException $e ) { |
|
113 | + } catch (ConstraintParameterException $e) { |
|
114 | 114 | $exceptions[] = $e; |
115 | 115 | } |
116 | 116 | return $exceptions; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\Html; |
6 | 6 | |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @throws InvalidArgumentException |
35 | 35 | */ |
36 | - public function __construct( $content, bool $isSortable = false ) { |
|
37 | - Assert::parameterType( [ 'string', HtmlArmor::class ], $content, '$content' ); |
|
36 | + public function __construct($content, bool $isSortable = false) { |
|
37 | + Assert::parameterType(['string', HtmlArmor::class], $content, '$content'); |
|
38 | 38 | |
39 | 39 | $this->content = $content; |
40 | 40 | $this->isSortable = $isSortable; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @return string HTML |
45 | 45 | */ |
46 | 46 | public function getContent(): string { |
47 | - return HtmlArmor::getHtml( $this->content ); |
|
47 | + return HtmlArmor::getHtml($this->content); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | public function getIsSortable(): bool { |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | * @return string HTML |
58 | 58 | */ |
59 | 59 | public function toHtml(): string { |
60 | - $attributes = [ 'role' => 'columnheader button' ]; |
|
60 | + $attributes = ['role' => 'columnheader button']; |
|
61 | 61 | |
62 | - if ( !$this->isSortable ) { |
|
62 | + if (!$this->isSortable) { |
|
63 | 63 | $attributes['class'] = 'unsortable'; |
64 | 64 | } |
65 | 65 | |
66 | - return Html::rawElement( 'th', $attributes, $this->getContent() ); |
|
66 | + return Html::rawElement('th', $attributes, $this->getContent()); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Message; |
6 | 6 | |
@@ -21,26 +21,26 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class ViolationMessageSerializer implements Serializer { |
23 | 23 | |
24 | - private function abbreviateViolationMessageKey( string $fullMessageKey ): string { |
|
25 | - return substr( $fullMessageKey, strlen( ViolationMessage::MESSAGE_KEY_PREFIX ) ); |
|
24 | + private function abbreviateViolationMessageKey(string $fullMessageKey): string { |
|
25 | + return substr($fullMessageKey, strlen(ViolationMessage::MESSAGE_KEY_PREFIX)); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @param ViolationMessage $object |
30 | 30 | * @return array |
31 | 31 | */ |
32 | - public function serialize( $object ): array { |
|
32 | + public function serialize($object): array { |
|
33 | 33 | /** @var ViolationMessage $object */ |
34 | - Assert::parameterType( ViolationMessage::class, $object, '$object' ); |
|
34 | + Assert::parameterType(ViolationMessage::class, $object, '$object'); |
|
35 | 35 | |
36 | 36 | $arguments = $object->getArguments(); |
37 | 37 | $serializedArguments = []; |
38 | - foreach ( $arguments as $argument ) { |
|
39 | - $serializedArguments[] = $this->serializeArgument( $argument ); |
|
38 | + foreach ($arguments as $argument) { |
|
39 | + $serializedArguments[] = $this->serializeArgument($argument); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | return [ |
43 | - 'k' => $this->abbreviateViolationMessageKey( $object->getMessageKey() ), |
|
43 | + 'k' => $this->abbreviateViolationMessageKey($object->getMessageKey()), |
|
44 | 44 | 'a' => $serializedArguments, |
45 | 45 | ]; |
46 | 46 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param array $argument element of ViolationMessage::getArguments() |
50 | 50 | * @return array [ 't' => ViolationMessage::TYPE_*, 'v' => serialized value, 'r' => $role ] |
51 | 51 | */ |
52 | - private function serializeArgument( array $argument ): array { |
|
52 | + private function serializeArgument(array $argument): array { |
|
53 | 53 | $methods = [ |
54 | 54 | ViolationMessage::TYPE_ENTITY_ID => 'serializeEntityId', |
55 | 55 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'serializeEntityIdList', |
@@ -71,12 +71,12 @@ discard block |
||
71 | 71 | $value = $argument['value']; |
72 | 72 | $role = $argument['role']; |
73 | 73 | |
74 | - if ( array_key_exists( $type, $methods ) ) { |
|
74 | + if (array_key_exists($type, $methods)) { |
|
75 | 75 | $method = $methods[$type]; |
76 | - $serializedValue = $this->$method( $value ); |
|
76 | + $serializedValue = $this->$method($value); |
|
77 | 77 | } else { |
78 | 78 | throw new InvalidArgumentException( |
79 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
79 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param string $string any value that shall simply be serialized to itself |
94 | 94 | * @return string that same value, unchanged |
95 | 95 | */ |
96 | - private function serializeStringByIdentity( string $string ): string { |
|
96 | + private function serializeStringByIdentity(string $string): string { |
|
97 | 97 | return $string; |
98 | 98 | } |
99 | 99 | |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | * @param string[] $strings |
102 | 102 | * @return string[] |
103 | 103 | */ |
104 | - private function serializeStringListByIdentity( array $strings ): array { |
|
105 | - Assert::parameterElementType( 'string', $strings, '$strings' ); |
|
104 | + private function serializeStringListByIdentity(array $strings): array { |
|
105 | + Assert::parameterElementType('string', $strings, '$strings'); |
|
106 | 106 | return $strings; |
107 | 107 | } |
108 | 108 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param EntityId $entityId |
111 | 111 | * @return string entity ID serialization |
112 | 112 | */ |
113 | - private function serializeEntityId( EntityId $entityId ): string { |
|
113 | + private function serializeEntityId(EntityId $entityId): string { |
|
114 | 114 | return $entityId->getSerialization(); |
115 | 115 | } |
116 | 116 | |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * @param EntityId[] $entityIdList |
119 | 119 | * @return string[] entity ID serializations |
120 | 120 | */ |
121 | - private function serializeEntityIdList( array $entityIdList ): array { |
|
122 | - return array_map( [ $this, 'serializeEntityId' ], $entityIdList ); |
|
121 | + private function serializeEntityIdList(array $entityIdList): array { |
|
122 | + return array_map([$this, 'serializeEntityId'], $entityIdList); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | * @return string entity ID serialization, '::somevalue', or '::novalue' |
128 | 128 | * (according to EntityId::PATTERN, entity ID serializations can never begin with two colons) |
129 | 129 | */ |
130 | - private function serializeItemIdSnakValue( ItemIdSnakValue $value ): string { |
|
131 | - switch ( true ) { |
|
130 | + private function serializeItemIdSnakValue(ItemIdSnakValue $value): string { |
|
131 | + switch (true) { |
|
132 | 132 | case $value->isValue(): |
133 | - return $this->serializeEntityId( $value->getItemId() ); |
|
133 | + return $this->serializeEntityId($value->getItemId()); |
|
134 | 134 | case $value->isSomeValue(): |
135 | 135 | return '::somevalue'; |
136 | 136 | case $value->isNoValue(): |
@@ -148,15 +148,15 @@ discard block |
||
148 | 148 | * @param ItemIdSnakValue[] $valueList |
149 | 149 | * @return string[] array of entity ID serializations, '::somevalue's or '::novalue's |
150 | 150 | */ |
151 | - private function serializeItemIdSnakValueList( array $valueList ): array { |
|
152 | - return array_map( [ $this, 'serializeItemIdSnakValue' ], $valueList ); |
|
151 | + private function serializeItemIdSnakValueList(array $valueList): array { |
|
152 | + return array_map([$this, 'serializeItemIdSnakValue'], $valueList); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
156 | 156 | * @param DataValue $dataValue |
157 | 157 | * @return array the data value in array form |
158 | 158 | */ |
159 | - private function serializeDataValue( DataValue $dataValue ): array { |
|
159 | + private function serializeDataValue(DataValue $dataValue): array { |
|
160 | 160 | return $dataValue->toArray(); |
161 | 161 | } |
162 | 162 | |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | * @param string $contextType one of the Context::TYPE_* constants |
165 | 165 | * @return string the abbreviated context type |
166 | 166 | */ |
167 | - private function serializeContextType( string $contextType ): string { |
|
168 | - switch ( $contextType ) { |
|
167 | + private function serializeContextType(string $contextType): string { |
|
168 | + switch ($contextType) { |
|
169 | 169 | case Context::TYPE_STATEMENT: |
170 | 170 | return 's'; |
171 | 171 | case Context::TYPE_QUALIFIER: |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | default: |
176 | 176 | // @codeCoverageIgnoreStart |
177 | 177 | throw new LogicException( |
178 | - 'Unknown context type ' . $contextType |
|
178 | + 'Unknown context type '.$contextType |
|
179 | 179 | ); |
180 | 180 | // @codeCoverageIgnoreEnd |
181 | 181 | } |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | * @param string[] $contextTypeList Context::TYPE_* constants |
186 | 186 | * @return string[] abbreviated context types |
187 | 187 | */ |
188 | - private function serializeContextTypeList( array $contextTypeList ): array { |
|
189 | - return array_map( [ $this, 'serializeContextType' ], $contextTypeList ); |
|
188 | + private function serializeContextTypeList(array $contextTypeList): array { |
|
189 | + return array_map([$this, 'serializeContextType'], $contextTypeList); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | 193 | * @param MultilingualTextValue $text |
194 | 194 | * @return mixed {@see MultilingualTextValue::getArrayValue} |
195 | 195 | */ |
196 | - private function serializeMultilingualText( MultilingualTextValue $text ) { |
|
196 | + private function serializeMultilingualText(MultilingualTextValue $text) { |
|
197 | 197 | return $text->getArrayValue(); |
198 | 198 | } |
199 | 199 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\Api; |
6 | 6 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | private BagOStuff $cache; |
23 | 23 | |
24 | - public function __construct( BagOStuff $cache ) { |
|
24 | + public function __construct(BagOStuff $cache) { |
|
25 | 25 | $this->cache = $cache; |
26 | 26 | } |
27 | 27 | |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @throws \Wikimedia\Assert\ParameterTypeException |
34 | 34 | */ |
35 | - private function makeKey( string $id ): string { |
|
36 | - if ( trim( $id ) === '' ) { |
|
37 | - throw new ParameterTypeException( '$id', 'non-empty string' ); |
|
35 | + private function makeKey(string $id): string { |
|
36 | + if (trim($id) === '') { |
|
37 | + throw new ParameterTypeException('$id', 'non-empty string'); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | return $this->cache->makeKey( |
@@ -52,15 +52,15 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @throws \Wikimedia\Assert\ParameterTypeException |
54 | 54 | */ |
55 | - public function lock( string $id, ConvertibleTimestamp $expiryTimestamp ): bool { |
|
55 | + public function lock(string $id, ConvertibleTimestamp $expiryTimestamp): bool { |
|
56 | 56 | |
57 | - $cacheId = $this->makeKey( $id ); |
|
57 | + $cacheId = $this->makeKey($id); |
|
58 | 58 | |
59 | - if ( !$this->isLockedInternal( $cacheId ) ) { |
|
59 | + if (!$this->isLockedInternal($cacheId)) { |
|
60 | 60 | return $this->cache->set( |
61 | 61 | $cacheId, |
62 | - $expiryTimestamp->getTimestamp( TS_UNIX ), |
|
63 | - (int)$expiryTimestamp->getTimestamp( TS_UNIX ) |
|
62 | + $expiryTimestamp->getTimestamp(TS_UNIX), |
|
63 | + (int) $expiryTimestamp->getTimestamp(TS_UNIX) |
|
64 | 64 | ); |
65 | 65 | } else { |
66 | 66 | return false; |
@@ -74,20 +74,20 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @throws \Wikimedia\Assert\ParameterTypeException |
76 | 76 | */ |
77 | - private function isLockedInternal( string $cacheId ): bool { |
|
78 | - $expiryTime = $this->cache->get( $cacheId ); |
|
79 | - if ( !$expiryTime ) { |
|
77 | + private function isLockedInternal(string $cacheId): bool { |
|
78 | + $expiryTime = $this->cache->get($cacheId); |
|
79 | + if (!$expiryTime) { |
|
80 | 80 | return false; |
81 | 81 | } |
82 | 82 | |
83 | 83 | try { |
84 | - $lockExpiryTimeStamp = new ConvertibleTimestamp( $expiryTime ); |
|
85 | - } catch ( TimestampException $exception ) { |
|
84 | + $lockExpiryTimeStamp = new ConvertibleTimestamp($expiryTime); |
|
85 | + } catch (TimestampException $exception) { |
|
86 | 86 | return false; |
87 | 87 | } |
88 | 88 | |
89 | 89 | $now = new ConvertibleTimestamp(); |
90 | - if ( $now->timestamp < $lockExpiryTimeStamp->timestamp ) { |
|
90 | + if ($now->timestamp < $lockExpiryTimeStamp->timestamp) { |
|
91 | 91 | return true; |
92 | 92 | } else { |
93 | 93 | return false; |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @throws \Wikimedia\Assert\ParameterTypeException |
103 | 103 | */ |
104 | - public function isLocked( string $id ): bool { |
|
105 | - return $this->isLockedInternal( $this->makeKey( $id ) ); |
|
104 | + public function isLocked(string $id): bool { |
|
105 | + return $this->isLockedInternal($this->makeKey($id)); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport; |
6 | 6 | |
@@ -11,16 +11,16 @@ discard block |
||
11 | 11 | use Wikibase\Repo\WikibaseRepo; |
12 | 12 | |
13 | 13 | return [ |
14 | - WikibaseServices::ENTITY_LOOKUP => static function ( MediaWikiServices $services ): EntityLookup { |
|
14 | + WikibaseServices::ENTITY_LOOKUP => static function(MediaWikiServices $services): EntityLookup { |
|
15 | 15 | return new ExceptionIgnoringEntityLookup( |
16 | - WikibaseRepo::getEntityLookup( $services ) |
|
16 | + WikibaseRepo::getEntityLookup($services) |
|
17 | 17 | ); |
18 | 18 | }, |
19 | 19 | |
20 | - WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function ( MediaWikiServices $services ): EntityLookup { |
|
20 | + WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function(MediaWikiServices $services): EntityLookup { |
|
21 | 21 | return new ExceptionIgnoringEntityLookup( |
22 | - WikibaseRepo::getStore( $services ) |
|
23 | - ->getEntityLookup( Store::LOOKUP_CACHING_RETRIEVE_ONLY ) |
|
22 | + WikibaseRepo::getStore($services) |
|
23 | + ->getEntityLookup(Store::LOOKUP_CACHING_RETRIEVE_ONLY) |
|
24 | 24 | ); |
25 | 25 | }, |
26 | 26 | ]; |
@@ -38,216 +38,216 @@ |
||
38 | 38 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker; |
39 | 39 | |
40 | 40 | return [ |
41 | - ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function ( MediaWikiServices $services ): ConflictsWithChecker { |
|
41 | + ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function(MediaWikiServices $services): ConflictsWithChecker { |
|
42 | 42 | return new ConflictsWithChecker( |
43 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
44 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
43 | + ConstraintsServices::getConstraintParameterParser($services), |
|
44 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
45 | 45 | ); |
46 | 46 | }, |
47 | 47 | |
48 | - ConstraintCheckerServices::ITEM_CHECKER => static function ( MediaWikiServices $services ): ItemChecker { |
|
48 | + ConstraintCheckerServices::ITEM_CHECKER => static function(MediaWikiServices $services): ItemChecker { |
|
49 | 49 | return new ItemChecker( |
50 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
51 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
50 | + ConstraintsServices::getConstraintParameterParser($services), |
|
51 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
52 | 52 | ); |
53 | 53 | }, |
54 | 54 | |
55 | - ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function ( |
|
55 | + ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function( |
|
56 | 56 | MediaWikiServices $services |
57 | 57 | ): TargetRequiredClaimChecker { |
58 | 58 | return new TargetRequiredClaimChecker( |
59 | - WikibaseServices::getEntityLookup( $services ), |
|
60 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
61 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
59 | + WikibaseServices::getEntityLookup($services), |
|
60 | + ConstraintsServices::getConstraintParameterParser($services), |
|
61 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
62 | 62 | ); |
63 | 63 | }, |
64 | 64 | |
65 | - ConstraintCheckerServices::SYMMETRIC_CHECKER => static function ( MediaWikiServices $services ): SymmetricChecker { |
|
65 | + ConstraintCheckerServices::SYMMETRIC_CHECKER => static function(MediaWikiServices $services): SymmetricChecker { |
|
66 | 66 | return new SymmetricChecker( |
67 | - WikibaseServices::getEntityLookupWithoutCache( $services ), |
|
68 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
67 | + WikibaseServices::getEntityLookupWithoutCache($services), |
|
68 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
69 | 69 | ); |
70 | 70 | }, |
71 | 71 | |
72 | - ConstraintCheckerServices::INVERSE_CHECKER => static function ( MediaWikiServices $services ): InverseChecker { |
|
72 | + ConstraintCheckerServices::INVERSE_CHECKER => static function(MediaWikiServices $services): InverseChecker { |
|
73 | 73 | return new InverseChecker( |
74 | - WikibaseServices::getEntityLookup( $services ), |
|
75 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
76 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
74 | + WikibaseServices::getEntityLookup($services), |
|
75 | + ConstraintsServices::getConstraintParameterParser($services), |
|
76 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
77 | 77 | ); |
78 | 78 | }, |
79 | 79 | |
80 | - ConstraintCheckerServices::QUALIFIER_CHECKER => static function ( MediaWikiServices $services ): QualifierChecker { |
|
80 | + ConstraintCheckerServices::QUALIFIER_CHECKER => static function(MediaWikiServices $services): QualifierChecker { |
|
81 | 81 | return new QualifierChecker(); |
82 | 82 | }, |
83 | 83 | |
84 | - ConstraintCheckerServices::QUALIFIERS_CHECKER => static function ( MediaWikiServices $services ): QualifiersChecker { |
|
84 | + ConstraintCheckerServices::QUALIFIERS_CHECKER => static function(MediaWikiServices $services): QualifiersChecker { |
|
85 | 85 | return new QualifiersChecker( |
86 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
86 | + ConstraintsServices::getConstraintParameterParser($services) |
|
87 | 87 | ); |
88 | 88 | }, |
89 | 89 | |
90 | - ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function ( |
|
90 | + ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function( |
|
91 | 91 | MediaWikiServices $services |
92 | 92 | ): MandatoryQualifiersChecker { |
93 | 93 | return new MandatoryQualifiersChecker( |
94 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
94 | + ConstraintsServices::getConstraintParameterParser($services) |
|
95 | 95 | ); |
96 | 96 | }, |
97 | 97 | |
98 | - ConstraintCheckerServices::RANGE_CHECKER => static function ( MediaWikiServices $services ): RangeChecker { |
|
98 | + ConstraintCheckerServices::RANGE_CHECKER => static function(MediaWikiServices $services): RangeChecker { |
|
99 | 99 | return new RangeChecker( |
100 | - WikibaseRepo::getPropertyDataTypeLookup( $services ), |
|
101 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
102 | - ConstraintsServices::getRangeCheckerHelper( $services ) |
|
100 | + WikibaseRepo::getPropertyDataTypeLookup($services), |
|
101 | + ConstraintsServices::getConstraintParameterParser($services), |
|
102 | + ConstraintsServices::getRangeCheckerHelper($services) |
|
103 | 103 | ); |
104 | 104 | }, |
105 | 105 | |
106 | - ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function ( |
|
106 | + ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function( |
|
107 | 107 | MediaWikiServices $services |
108 | 108 | ): DiffWithinRangeChecker { |
109 | 109 | return new DiffWithinRangeChecker( |
110 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
111 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
110 | + ConstraintsServices::getConstraintParameterParser($services), |
|
111 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
112 | 112 | $services->getMainConfig() |
113 | 113 | ); |
114 | 114 | }, |
115 | 115 | |
116 | - ConstraintCheckerServices::TYPE_CHECKER => static function ( MediaWikiServices $services ): TypeChecker { |
|
116 | + ConstraintCheckerServices::TYPE_CHECKER => static function(MediaWikiServices $services): TypeChecker { |
|
117 | 117 | return new TypeChecker( |
118 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
119 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
118 | + ConstraintsServices::getConstraintParameterParser($services), |
|
119 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
120 | 120 | $services->getMainConfig() |
121 | 121 | ); |
122 | 122 | }, |
123 | 123 | |
124 | - ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function ( MediaWikiServices $services ): ValueTypeChecker { |
|
124 | + ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function(MediaWikiServices $services): ValueTypeChecker { |
|
125 | 125 | return new ValueTypeChecker( |
126 | - WikibaseServices::getEntityLookup( $services ), |
|
127 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
128 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
126 | + WikibaseServices::getEntityLookup($services), |
|
127 | + ConstraintsServices::getConstraintParameterParser($services), |
|
128 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
129 | 129 | $services->getMainConfig() |
130 | 130 | ); |
131 | 131 | }, |
132 | 132 | |
133 | - ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function ( MediaWikiServices $services ): SingleValueChecker { |
|
133 | + ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function(MediaWikiServices $services): SingleValueChecker { |
|
134 | 134 | return new SingleValueChecker( |
135 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
135 | + ConstraintsServices::getConstraintParameterParser($services) |
|
136 | 136 | ); |
137 | 137 | }, |
138 | 138 | |
139 | - ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function ( MediaWikiServices $services ): MultiValueChecker { |
|
139 | + ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function(MediaWikiServices $services): MultiValueChecker { |
|
140 | 140 | return new MultiValueChecker( |
141 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
141 | + ConstraintsServices::getConstraintParameterParser($services) |
|
142 | 142 | ); |
143 | 143 | }, |
144 | 144 | |
145 | - ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function ( MediaWikiServices $services ): UniqueValueChecker { |
|
145 | + ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function(MediaWikiServices $services): UniqueValueChecker { |
|
146 | 146 | // TODO return a different, dummy implementation if SPARQL is not available |
147 | 147 | return new UniqueValueChecker( |
148 | - ConstraintsServices::getSparqlHelper( $services ), |
|
149 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
148 | + ConstraintsServices::getSparqlHelper($services), |
|
149 | + ConstraintsServices::getConstraintParameterParser($services) |
|
150 | 150 | ); |
151 | 151 | }, |
152 | 152 | |
153 | - ConstraintCheckerServices::FORMAT_CHECKER => static function ( MediaWikiServices $services ): FormatChecker { |
|
153 | + ConstraintCheckerServices::FORMAT_CHECKER => static function(MediaWikiServices $services): FormatChecker { |
|
154 | 154 | // TODO return a different, dummy implementation if SPARQL is not available |
155 | 155 | return new FormatChecker( |
156 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
156 | + ConstraintsServices::getConstraintParameterParser($services), |
|
157 | 157 | $services->getMainConfig(), |
158 | - ConstraintsServices::getSparqlHelper( $services ), |
|
158 | + ConstraintsServices::getSparqlHelper($services), |
|
159 | 159 | $services->getShellboxClientFactory() |
160 | 160 | ); |
161 | 161 | }, |
162 | 162 | |
163 | - ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function ( MediaWikiServices $services ): CommonsLinkChecker { |
|
163 | + ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function(MediaWikiServices $services): CommonsLinkChecker { |
|
164 | 164 | $pageNameNormalizer = new MediaWikiPageNameNormalizer(); |
165 | 165 | return new CommonsLinkChecker( |
166 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
166 | + ConstraintsServices::getConstraintParameterParser($services), |
|
167 | 167 | $pageNameNormalizer, |
168 | - WikibaseRepo::getPropertyDataTypeLookup( $services ) |
|
168 | + WikibaseRepo::getPropertyDataTypeLookup($services) |
|
169 | 169 | ); |
170 | 170 | }, |
171 | 171 | |
172 | - ConstraintCheckerServices::ONE_OF_CHECKER => static function ( MediaWikiServices $services ): OneOfChecker { |
|
172 | + ConstraintCheckerServices::ONE_OF_CHECKER => static function(MediaWikiServices $services): OneOfChecker { |
|
173 | 173 | return new OneOfChecker( |
174 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
174 | + ConstraintsServices::getConstraintParameterParser($services) |
|
175 | 175 | ); |
176 | 176 | }, |
177 | 177 | |
178 | - ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function ( MediaWikiServices $services ): ValueOnlyChecker { |
|
178 | + ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function(MediaWikiServices $services): ValueOnlyChecker { |
|
179 | 179 | return new ValueOnlyChecker(); |
180 | 180 | }, |
181 | 181 | |
182 | - ConstraintCheckerServices::REFERENCE_CHECKER => static function ( MediaWikiServices $services ): ReferenceChecker { |
|
182 | + ConstraintCheckerServices::REFERENCE_CHECKER => static function(MediaWikiServices $services): ReferenceChecker { |
|
183 | 183 | return new ReferenceChecker(); |
184 | 184 | }, |
185 | 185 | |
186 | - ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function ( MediaWikiServices $services ): NoBoundsChecker { |
|
186 | + ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function(MediaWikiServices $services): NoBoundsChecker { |
|
187 | 187 | return new NoBoundsChecker(); |
188 | 188 | }, |
189 | 189 | |
190 | - ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function ( MediaWikiServices $services ): AllowedUnitsChecker { |
|
190 | + ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function(MediaWikiServices $services): AllowedUnitsChecker { |
|
191 | 191 | return new AllowedUnitsChecker( |
192 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
193 | - WikibaseRepo::getUnitConverter( $services ) |
|
192 | + ConstraintsServices::getConstraintParameterParser($services), |
|
193 | + WikibaseRepo::getUnitConverter($services) |
|
194 | 194 | ); |
195 | 195 | }, |
196 | 196 | |
197 | - ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function ( |
|
197 | + ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function( |
|
198 | 198 | MediaWikiServices $services |
199 | 199 | ): SingleBestValueChecker { |
200 | 200 | return new SingleBestValueChecker( |
201 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
201 | + ConstraintsServices::getConstraintParameterParser($services) |
|
202 | 202 | ); |
203 | 203 | }, |
204 | 204 | |
205 | - ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function ( MediaWikiServices $services ): EntityTypeChecker { |
|
205 | + ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function(MediaWikiServices $services): EntityTypeChecker { |
|
206 | 206 | return new EntityTypeChecker( |
207 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
207 | + ConstraintsServices::getConstraintParameterParser($services) |
|
208 | 208 | ); |
209 | 209 | }, |
210 | 210 | |
211 | - ConstraintCheckerServices::NONE_OF_CHECKER => static function ( MediaWikiServices $services ): NoneOfChecker { |
|
211 | + ConstraintCheckerServices::NONE_OF_CHECKER => static function(MediaWikiServices $services): NoneOfChecker { |
|
212 | 212 | return new NoneOfChecker( |
213 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
213 | + ConstraintsServices::getConstraintParameterParser($services) |
|
214 | 214 | ); |
215 | 215 | }, |
216 | 216 | |
217 | - ConstraintCheckerServices::INTEGER_CHECKER => static function ( MediaWikiServices $services ): IntegerChecker { |
|
217 | + ConstraintCheckerServices::INTEGER_CHECKER => static function(MediaWikiServices $services): IntegerChecker { |
|
218 | 218 | return new IntegerChecker(); |
219 | 219 | }, |
220 | 220 | |
221 | - ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function ( MediaWikiServices $services ): CitationNeededChecker { |
|
221 | + ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function(MediaWikiServices $services): CitationNeededChecker { |
|
222 | 222 | return new CitationNeededChecker(); |
223 | 223 | }, |
224 | 224 | |
225 | - ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function ( MediaWikiServices $services ): PropertyScopeChecker { |
|
225 | + ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function(MediaWikiServices $services): PropertyScopeChecker { |
|
226 | 226 | return new PropertyScopeChecker( |
227 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
227 | + ConstraintsServices::getConstraintParameterParser($services) |
|
228 | 228 | ); |
229 | 229 | }, |
230 | 230 | |
231 | - ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function ( MediaWikiServices $services ): ContemporaryChecker { |
|
231 | + ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function(MediaWikiServices $services): ContemporaryChecker { |
|
232 | 232 | return new ContemporaryChecker( |
233 | - WikibaseServices::getEntityLookup( $services ), |
|
234 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
233 | + WikibaseServices::getEntityLookup($services), |
|
234 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
235 | 235 | $services->getMainConfig() |
236 | 236 | ); |
237 | 237 | }, |
238 | 238 | |
239 | - ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function ( MediaWikiServices $services ): LanguageChecker { |
|
239 | + ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function(MediaWikiServices $services): LanguageChecker { |
|
240 | 240 | return new LanguageChecker( |
241 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
242 | - WikibaseServices::getEntityLookup( $services ) |
|
241 | + ConstraintsServices::getConstraintParameterParser($services), |
|
242 | + WikibaseServices::getEntityLookup($services) |
|
243 | 243 | ); |
244 | 244 | }, |
245 | 245 | |
246 | - ConstraintCheckerServices::LABEL_IN_LANGUAGE_CHECKER => static function ( |
|
246 | + ConstraintCheckerServices::LABEL_IN_LANGUAGE_CHECKER => static function( |
|
247 | 247 | MediaWikiServices $services |
248 | 248 | ): LabelInLanguageChecker { |
249 | 249 | return new LabelInLanguageChecker( |
250 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
250 | + ConstraintsServices::getConstraintParameterParser($services) |
|
251 | 251 | ); |
252 | 252 | }, |
253 | 253 | ]; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck; |
6 | 6 | |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | ?callable $defaultResultsPerEntity = null |
124 | 124 | ): array { |
125 | 125 | $checkResults = []; |
126 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
126 | + $entity = $this->entityLookup->getEntity($entityId); |
|
127 | 127 | |
128 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
129 | - $startTime = microtime( true ); |
|
128 | + if ($entity instanceof StatementListProvidingEntity) { |
|
129 | + $startTime = microtime(true); |
|
130 | 130 | |
131 | 131 | $checkResults = $this->checkEveryStatement( |
132 | 132 | $entity, |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | $defaultResultsPerContext |
135 | 135 | ); |
136 | 136 | |
137 | - $endTime = microtime( true ); |
|
137 | + $endTime = microtime(true); |
|
138 | 138 | |
139 | - if ( $constraintIds === null ) { // only log full constraint checks |
|
139 | + if ($constraintIds === null) { // only log full constraint checks |
|
140 | 140 | $this->loggingHelper->logConstraintCheckOnEntity( |
141 | 141 | $entityId, |
142 | 142 | $checkResults, |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | - if ( $defaultResultsPerEntity !== null ) { |
|
150 | - $checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults ); |
|
149 | + if ($defaultResultsPerEntity !== null) { |
|
150 | + $checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults); |
|
151 | 151 | } |
152 | 152 | |
153 | - return $this->sortResult( $checkResults ); |
|
153 | + return $this->sortResult($checkResults); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | ?callable $defaultResults = null |
173 | 173 | ): array { |
174 | 174 | |
175 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
175 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
176 | 176 | $entityId = $parsedGuid->getEntityId(); |
177 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
178 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
179 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
180 | - if ( $statement ) { |
|
177 | + $entity = $this->entityLookup->getEntity($entityId); |
|
178 | + if ($entity instanceof StatementListProvidingEntity) { |
|
179 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
180 | + if ($statement) { |
|
181 | 181 | $result = $this->checkStatement( |
182 | 182 | $entity, |
183 | 183 | $statement, |
184 | 184 | $constraintIds, |
185 | 185 | $defaultResults |
186 | 186 | ); |
187 | - $output = $this->sortResult( $result ); |
|
187 | + $output = $this->sortResult($result); |
|
188 | 188 | return $output; |
189 | 189 | } |
190 | 190 | } |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | return []; |
193 | 193 | } |
194 | 194 | |
195 | - private function getValidContextTypes( Constraint $constraint ): array { |
|
196 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
195 | + private function getValidContextTypes(Constraint $constraint): array { |
|
196 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
197 | 197 | return [ |
198 | 198 | Context::TYPE_STATEMENT, |
199 | 199 | Context::TYPE_QUALIFIER, |
@@ -201,21 +201,21 @@ discard block |
||
201 | 201 | ]; |
202 | 202 | } |
203 | 203 | |
204 | - return array_keys( array_filter( |
|
204 | + return array_keys(array_filter( |
|
205 | 205 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
206 | - static fn ( $status ) => $status !== CheckResult::STATUS_NOT_IN_SCOPE |
|
207 | - ) ); |
|
206 | + static fn ($status) => $status !== CheckResult::STATUS_NOT_IN_SCOPE |
|
207 | + )); |
|
208 | 208 | } |
209 | 209 | |
210 | - private function getValidEntityTypes( Constraint $constraint ): array { |
|
211 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
212 | - return array_keys( ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED ); |
|
210 | + private function getValidEntityTypes(Constraint $constraint): array { |
|
211 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
212 | + return array_keys(ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED); |
|
213 | 213 | } |
214 | 214 | |
215 | - return array_keys( array_filter( |
|
215 | + return array_keys(array_filter( |
|
216 | 216 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedEntityTypes(), |
217 | - static fn ( $status ) => $status !== CheckResult::STATUS_NOT_IN_SCOPE |
|
218 | - ) ); |
|
217 | + static fn ($status) => $status !== CheckResult::STATUS_NOT_IN_SCOPE |
|
218 | + )); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -226,38 +226,38 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @return ConstraintParameterException[] |
228 | 228 | */ |
229 | - private function checkCommonConstraintParameters( Constraint $constraint ): array { |
|
229 | + private function checkCommonConstraintParameters(Constraint $constraint): array { |
|
230 | 230 | $constraintParameters = $constraint->getConstraintParameters(); |
231 | 231 | try { |
232 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
233 | - } catch ( ConstraintParameterException $e ) { |
|
234 | - return [ $e ]; |
|
232 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
233 | + } catch (ConstraintParameterException $e) { |
|
234 | + return [$e]; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | $problems = []; |
238 | 238 | try { |
239 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
240 | - } catch ( ConstraintParameterException $e ) { |
|
239 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
240 | + } catch (ConstraintParameterException $e) { |
|
241 | 241 | $problems[] = $e; |
242 | 242 | } |
243 | 243 | try { |
244 | - $this->constraintParameterParser->parseConstraintClarificationParameter( $constraintParameters ); |
|
245 | - } catch ( ConstraintParameterException $e ) { |
|
244 | + $this->constraintParameterParser->parseConstraintClarificationParameter($constraintParameters); |
|
245 | + } catch (ConstraintParameterException $e) { |
|
246 | 246 | $problems[] = $e; |
247 | 247 | } |
248 | 248 | try { |
249 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
250 | - } catch ( ConstraintParameterException $e ) { |
|
249 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
250 | + } catch (ConstraintParameterException $e) { |
|
251 | 251 | $problems[] = $e; |
252 | 252 | } |
253 | 253 | try { |
254 | 254 | $this->constraintParameterParser->parseConstraintScopeParameters( |
255 | 255 | $constraintParameters, |
256 | 256 | $constraint->getConstraintTypeItemId(), |
257 | - $this->getValidContextTypes( $constraint ), |
|
258 | - $this->getValidEntityTypes( $constraint ) |
|
257 | + $this->getValidContextTypes($constraint), |
|
258 | + $this->getValidEntityTypes($constraint) |
|
259 | 259 | ); |
260 | - } catch ( ConstraintParameterException $e ) { |
|
260 | + } catch (ConstraintParameterException $e) { |
|
261 | 261 | $problems[] = $e; |
262 | 262 | } |
263 | 263 | return $problems; |
@@ -270,16 +270,16 @@ discard block |
||
270 | 270 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
271 | 271 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
272 | 272 | */ |
273 | - public function checkConstraintParametersOnPropertyId( NumericPropertyId $propertyId ): array { |
|
274 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
273 | + public function checkConstraintParametersOnPropertyId(NumericPropertyId $propertyId): array { |
|
274 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
275 | 275 | $result = []; |
276 | 276 | |
277 | - foreach ( $constraints as $constraint ) { |
|
278 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
277 | + foreach ($constraints as $constraint) { |
|
278 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
279 | 279 | |
280 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
280 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
281 | 281 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
282 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
282 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | $result[$constraint->getConstraintId()] = $problems; |
@@ -296,18 +296,18 @@ discard block |
||
296 | 296 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
297 | 297 | * (empty means all parameters okay), or null if constraint is not found |
298 | 298 | */ |
299 | - public function checkConstraintParametersOnConstraintId( string $constraintId ): ?array { |
|
300 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
299 | + public function checkConstraintParametersOnConstraintId(string $constraintId): ?array { |
|
300 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
301 | 301 | '@phan-var NumericPropertyId $propertyId'; |
302 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
302 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
303 | 303 | |
304 | - foreach ( $constraints as $constraint ) { |
|
305 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
306 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
304 | + foreach ($constraints as $constraint) { |
|
305 | + if ($constraint->getConstraintId() === $constraintId) { |
|
306 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
307 | 307 | |
308 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
308 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
309 | 309 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
310 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
310 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | return $problems; |
@@ -332,14 +332,14 @@ discard block |
||
332 | 332 | $result = []; |
333 | 333 | |
334 | 334 | /** @var Statement $statement */ |
335 | - foreach ( $entity->getStatements() as $statement ) { |
|
336 | - $result = array_merge( $result, |
|
335 | + foreach ($entity->getStatements() as $statement) { |
|
336 | + $result = array_merge($result, |
|
337 | 337 | $this->checkStatement( |
338 | 338 | $entity, |
339 | 339 | $statement, |
340 | 340 | $constraintIds, |
341 | 341 | $defaultResultsPerContext |
342 | - ) ); |
|
342 | + )); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | return $result; |
@@ -361,32 +361,32 @@ discard block |
||
361 | 361 | ): array { |
362 | 362 | $result = []; |
363 | 363 | |
364 | - $result = array_merge( $result, |
|
364 | + $result = array_merge($result, |
|
365 | 365 | $this->checkConstraintsForMainSnak( |
366 | 366 | $entity, |
367 | 367 | $statement, |
368 | 368 | $constraintIds, |
369 | 369 | $defaultResultsPerContext |
370 | - ) ); |
|
370 | + )); |
|
371 | 371 | |
372 | - if ( $this->checkQualifiers ) { |
|
373 | - $result = array_merge( $result, |
|
372 | + if ($this->checkQualifiers) { |
|
373 | + $result = array_merge($result, |
|
374 | 374 | $this->checkConstraintsForQualifiers( |
375 | 375 | $entity, |
376 | 376 | $statement, |
377 | 377 | $constraintIds, |
378 | 378 | $defaultResultsPerContext |
379 | - ) ); |
|
379 | + )); |
|
380 | 380 | } |
381 | 381 | |
382 | - if ( $this->checkReferences ) { |
|
383 | - $result = array_merge( $result, |
|
382 | + if ($this->checkReferences) { |
|
383 | + $result = array_merge($result, |
|
384 | 384 | $this->checkConstraintsForReferences( |
385 | 385 | $entity, |
386 | 386 | $statement, |
387 | 387 | $constraintIds, |
388 | 388 | $defaultResultsPerContext |
389 | - ) ); |
|
389 | + )); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | return $result; |
@@ -401,17 +401,17 @@ discard block |
||
401 | 401 | * @param string[]|null $constraintIds |
402 | 402 | * @return Constraint[] |
403 | 403 | */ |
404 | - private function getConstraintsToUse( PropertyId $propertyId, ?array $constraintIds ): array { |
|
405 | - if ( !( $propertyId instanceof NumericPropertyId ) ) { |
|
404 | + private function getConstraintsToUse(PropertyId $propertyId, ?array $constraintIds): array { |
|
405 | + if (!($propertyId instanceof NumericPropertyId)) { |
|
406 | 406 | throw new InvalidArgumentException( |
407 | - 'Non-numeric property ID not supported:' . $propertyId->getSerialization() |
|
407 | + 'Non-numeric property ID not supported:'.$propertyId->getSerialization() |
|
408 | 408 | ); |
409 | 409 | } |
410 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
411 | - if ( $constraintIds !== null ) { |
|
410 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
411 | + if ($constraintIds !== null) { |
|
412 | 412 | $constraintsToUse = []; |
413 | - foreach ( $constraints as $constraint ) { |
|
414 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
413 | + foreach ($constraints as $constraint) { |
|
414 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
415 | 415 | $constraintsToUse[] = $constraint; |
416 | 416 | } |
417 | 417 | } |
@@ -435,18 +435,18 @@ discard block |
||
435 | 435 | ?array $constraintIds, |
436 | 436 | ?callable $defaultResults |
437 | 437 | ): array { |
438 | - $context = new MainSnakContext( $entity, $statement ); |
|
438 | + $context = new MainSnakContext($entity, $statement); |
|
439 | 439 | $constraints = $this->getConstraintsToUse( |
440 | 440 | $statement->getPropertyId(), |
441 | 441 | $constraintIds |
442 | 442 | ); |
443 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
443 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
444 | 444 | |
445 | - foreach ( $constraints as $constraint ) { |
|
445 | + foreach ($constraints as $constraint) { |
|
446 | 446 | $parameters = $constraint->getConstraintParameters(); |
447 | 447 | try { |
448 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
449 | - } catch ( ConstraintParameterException $e ) { |
|
448 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
449 | + } catch (ConstraintParameterException $e) { |
|
450 | 450 | $result[] = new CheckResult( |
451 | 451 | $context, |
452 | 452 | $constraint, |
@@ -456,13 +456,13 @@ discard block |
||
456 | 456 | continue; |
457 | 457 | } |
458 | 458 | |
459 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
460 | - $message = new ViolationMessage( 'wbqc-violation-message-exception' ); |
|
461 | - $result[] = new CheckResult( $context, $constraint, CheckResult::STATUS_EXCEPTION, $message ); |
|
459 | + if (in_array($entity->getId(), $exceptions)) { |
|
460 | + $message = new ViolationMessage('wbqc-violation-message-exception'); |
|
461 | + $result[] = new CheckResult($context, $constraint, CheckResult::STATUS_EXCEPTION, $message); |
|
462 | 462 | continue; |
463 | 463 | } |
464 | 464 | |
465 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
465 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | return $result; |
@@ -484,24 +484,24 @@ discard block |
||
484 | 484 | ): array { |
485 | 485 | $result = []; |
486 | 486 | |
487 | - if ( in_array( |
|
487 | + if (in_array( |
|
488 | 488 | $statement->getPropertyId()->getSerialization(), |
489 | 489 | $this->propertiesWithViolatingQualifiers |
490 | - ) ) { |
|
490 | + )) { |
|
491 | 491 | return $result; |
492 | 492 | } |
493 | 493 | |
494 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
495 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
496 | - if ( $defaultResultsPerContext !== null ) { |
|
497 | - $result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) ); |
|
494 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
495 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
496 | + if ($defaultResultsPerContext !== null) { |
|
497 | + $result = array_merge($result, $defaultResultsPerContext($qualifierContext)); |
|
498 | 498 | } |
499 | 499 | $qualifierConstraints = $this->getConstraintsToUse( |
500 | 500 | $qualifierContext->getSnak()->getPropertyId(), |
501 | 501 | $constraintIds |
502 | 502 | ); |
503 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
504 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
503 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
504 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
505 | 505 | } |
506 | 506 | } |
507 | 507 | |
@@ -525,19 +525,19 @@ discard block |
||
525 | 525 | $result = []; |
526 | 526 | |
527 | 527 | /** @var Reference $reference */ |
528 | - foreach ( $statement->getReferences() as $reference ) { |
|
529 | - foreach ( $reference->getSnaks() as $snak ) { |
|
528 | + foreach ($statement->getReferences() as $reference) { |
|
529 | + foreach ($reference->getSnaks() as $snak) { |
|
530 | 530 | $referenceContext = new ReferenceContext( |
531 | 531 | $entity, $statement, $reference, $snak |
532 | 532 | ); |
533 | - if ( $defaultResultsPerContext !== null ) { |
|
534 | - $result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) ); |
|
533 | + if ($defaultResultsPerContext !== null) { |
|
534 | + $result = array_merge($result, $defaultResultsPerContext($referenceContext)); |
|
535 | 535 | } |
536 | 536 | $referenceConstraints = $this->getConstraintsToUse( |
537 | 537 | $referenceContext->getSnak()->getPropertyId(), |
538 | 538 | $constraintIds |
539 | 539 | ); |
540 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
540 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
541 | 541 | $result[] = $this->getCheckResultFor( |
542 | 542 | $referenceContext, |
543 | 543 | $referenceConstraint |
@@ -549,50 +549,50 @@ discard block |
||
549 | 549 | return $result; |
550 | 550 | } |
551 | 551 | |
552 | - private function getCheckResultFor( Context $context, Constraint $constraint ): CheckResult { |
|
553 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
552 | + private function getCheckResultFor(Context $context, Constraint $constraint): CheckResult { |
|
553 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
554 | 554 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
555 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
555 | + $result = $this->handleScope($checker, $context, $constraint); |
|
556 | 556 | |
557 | - if ( $result !== null ) { |
|
558 | - $this->addMetadata( $context, $result ); |
|
557 | + if ($result !== null) { |
|
558 | + $this->addMetadata($context, $result); |
|
559 | 559 | return $result; |
560 | 560 | } |
561 | 561 | |
562 | - $startTime = microtime( true ); |
|
562 | + $startTime = microtime(true); |
|
563 | 563 | try { |
564 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
565 | - } catch ( ConstraintParameterException $e ) { |
|
564 | + $result = $checker->checkConstraint($context, $constraint); |
|
565 | + } catch (ConstraintParameterException $e) { |
|
566 | 566 | $result = new CheckResult( |
567 | 567 | $context, |
568 | 568 | $constraint, |
569 | 569 | CheckResult::STATUS_BAD_PARAMETERS, |
570 | 570 | $e->getViolationMessage() |
571 | 571 | ); |
572 | - } catch ( SparqlHelperException $e ) { |
|
573 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
574 | - $result = new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, $message ); |
|
572 | + } catch (SparqlHelperException $e) { |
|
573 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
574 | + $result = new CheckResult($context, $constraint, CheckResult::STATUS_TODO, $message); |
|
575 | 575 | } |
576 | - $endTime = microtime( true ); |
|
576 | + $endTime = microtime(true); |
|
577 | 577 | |
578 | - $this->addMetadata( $context, $result ); |
|
578 | + $this->addMetadata($context, $result); |
|
579 | 579 | |
580 | - $this->addConstraintClarification( $result ); |
|
580 | + $this->addConstraintClarification($result); |
|
581 | 581 | |
582 | - $this->downgradeResultStatus( $result ); |
|
582 | + $this->downgradeResultStatus($result); |
|
583 | 583 | |
584 | 584 | $this->loggingHelper->logConstraintCheck( |
585 | 585 | $context, |
586 | 586 | $constraint, |
587 | 587 | $result, |
588 | - get_class( $checker ), |
|
588 | + get_class($checker), |
|
589 | 589 | $endTime - $startTime, |
590 | 590 | __METHOD__ |
591 | 591 | ); |
592 | 592 | |
593 | 593 | return $result; |
594 | 594 | } else { |
595 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, null ); |
|
595 | + return new CheckResult($context, $constraint, CheckResult::STATUS_TODO, null); |
|
596 | 596 | } |
597 | 597 | } |
598 | 598 | |
@@ -601,87 +601,87 @@ discard block |
||
601 | 601 | Context $context, |
602 | 602 | Constraint $constraint |
603 | 603 | ): ?CheckResult { |
604 | - $validContextTypes = $this->getValidContextTypes( $constraint ); |
|
605 | - $validEntityTypes = $this->getValidEntityTypes( $constraint ); |
|
604 | + $validContextTypes = $this->getValidContextTypes($constraint); |
|
605 | + $validEntityTypes = $this->getValidEntityTypes($constraint); |
|
606 | 606 | try { |
607 | - [ $checkedContextTypes, $checkedEntityTypes ] = $this->constraintParameterParser->parseConstraintScopeParameters( |
|
607 | + [$checkedContextTypes, $checkedEntityTypes] = $this->constraintParameterParser->parseConstraintScopeParameters( |
|
608 | 608 | $constraint->getConstraintParameters(), |
609 | 609 | $constraint->getConstraintTypeItemId(), |
610 | 610 | $validContextTypes, |
611 | 611 | $validEntityTypes |
612 | 612 | ); |
613 | - } catch ( ConstraintParameterException $e ) { |
|
614 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
613 | + } catch (ConstraintParameterException $e) { |
|
614 | + return new CheckResult($context, $constraint, CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | $checkedContextTypes ??= $checker->getDefaultContextTypes(); |
618 | 618 | $contextType = $context->getType(); |
619 | - if ( !in_array( $contextType, $checkedContextTypes ) ) { |
|
620 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
619 | + if (!in_array($contextType, $checkedContextTypes)) { |
|
620 | + return new CheckResult($context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
621 | 621 | } |
622 | - if ( $checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO ) { |
|
623 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, null ); |
|
622 | + if ($checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO) { |
|
623 | + return new CheckResult($context, $constraint, CheckResult::STATUS_TODO, null); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | $checkedEntityTypes ??= $validEntityTypes; |
627 | 627 | $entityType = $context->getEntity()->getType(); |
628 | - if ( !in_array( $entityType, $checkedEntityTypes ) ) { |
|
629 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
628 | + if (!in_array($entityType, $checkedEntityTypes)) { |
|
629 | + return new CheckResult($context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
630 | 630 | } |
631 | - if ( $checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO ) { |
|
632 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, null ); |
|
631 | + if ($checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO) { |
|
632 | + return new CheckResult($context, $constraint, CheckResult::STATUS_TODO, null); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | return null; |
636 | 636 | } |
637 | 637 | |
638 | - private function addMetadata( Context $context, CheckResult $result ): void { |
|
639 | - $result->withMetadata( Metadata::merge( [ |
|
638 | + private function addMetadata(Context $context, CheckResult $result): void { |
|
639 | + $result->withMetadata(Metadata::merge([ |
|
640 | 640 | $result->getMetadata(), |
641 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
642 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
643 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
644 | - ] ) ), |
|
645 | - ] ) ); |
|
641 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
642 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
643 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
644 | + ])), |
|
645 | + ])); |
|
646 | 646 | } |
647 | 647 | |
648 | - private function addConstraintClarification( CheckResult $result ): void { |
|
648 | + private function addConstraintClarification(CheckResult $result): void { |
|
649 | 649 | $constraint = $result->getConstraint(); |
650 | 650 | try { |
651 | 651 | $constraintClarification = $this->constraintParameterParser |
652 | - ->parseConstraintClarificationParameter( $constraint->getConstraintParameters() ); |
|
653 | - $result->setConstraintClarification( $constraintClarification ); |
|
654 | - } catch ( ConstraintParameterException $e ) { |
|
655 | - $result->setStatus( CheckResult::STATUS_BAD_PARAMETERS ); |
|
656 | - $result->setMessage( $e->getViolationMessage() ); |
|
652 | + ->parseConstraintClarificationParameter($constraint->getConstraintParameters()); |
|
653 | + $result->setConstraintClarification($constraintClarification); |
|
654 | + } catch (ConstraintParameterException $e) { |
|
655 | + $result->setStatus(CheckResult::STATUS_BAD_PARAMETERS); |
|
656 | + $result->setMessage($e->getViolationMessage()); |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | |
660 | - private function downgradeResultStatus( CheckResult $result ): void { |
|
660 | + private function downgradeResultStatus(CheckResult $result): void { |
|
661 | 661 | $constraint = $result->getConstraint(); |
662 | 662 | try { |
663 | 663 | $constraintStatus = $this->constraintParameterParser |
664 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
665 | - } catch ( ConstraintParameterException $e ) { |
|
666 | - $result->setStatus( CheckResult::STATUS_BAD_PARAMETERS ); |
|
667 | - $result->setMessage( $e->getViolationMessage() ); |
|
664 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
665 | + } catch (ConstraintParameterException $e) { |
|
666 | + $result->setStatus(CheckResult::STATUS_BAD_PARAMETERS); |
|
667 | + $result->setMessage($e->getViolationMessage()); |
|
668 | 668 | return; |
669 | 669 | } |
670 | - if ( $constraintStatus === null ) { |
|
670 | + if ($constraintStatus === null) { |
|
671 | 671 | // downgrade violation to warning |
672 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
673 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
672 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
673 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
674 | 674 | } |
675 | - } elseif ( $constraintStatus === 'suggestion' ) { |
|
675 | + } elseif ($constraintStatus === 'suggestion') { |
|
676 | 676 | // downgrade violation to suggestion |
677 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
678 | - $result->setStatus( CheckResult::STATUS_SUGGESTION ); |
|
677 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
678 | + $result->setStatus(CheckResult::STATUS_SUGGESTION); |
|
679 | 679 | } |
680 | 680 | } else { |
681 | - if ( $constraintStatus !== 'mandatory' ) { |
|
681 | + if ($constraintStatus !== 'mandatory') { |
|
682 | 682 | // @codeCoverageIgnoreStart |
683 | 683 | throw new LogicException( |
684 | - "Unknown constraint status '$constraintStatus', " . |
|
684 | + "Unknown constraint status '$constraintStatus', ". |
|
685 | 685 | "only known statuses are 'mandatory' and 'suggestion'" |
686 | 686 | ); |
687 | 687 | // @codeCoverageIgnoreEnd |
@@ -694,12 +694,12 @@ discard block |
||
694 | 694 | * |
695 | 695 | * @return CheckResult[] |
696 | 696 | */ |
697 | - private function sortResult( array $result ): array { |
|
698 | - if ( count( $result ) < 2 ) { |
|
697 | + private function sortResult(array $result): array { |
|
698 | + if (count($result) < 2) { |
|
699 | 699 | return $result; |
700 | 700 | } |
701 | 701 | |
702 | - $sortFunction = static function ( CheckResult $a, CheckResult $b ) { |
|
702 | + $sortFunction = static function(CheckResult $a, CheckResult $b) { |
|
703 | 703 | $orderNum = 0; |
704 | 704 | $order = [ |
705 | 705 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -716,55 +716,55 @@ discard block |
||
716 | 716 | $statusA = $a->getStatus(); |
717 | 717 | $statusB = $b->getStatus(); |
718 | 718 | |
719 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
720 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
719 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
720 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
721 | 721 | |
722 | - if ( $orderA === $orderB ) { |
|
722 | + if ($orderA === $orderB) { |
|
723 | 723 | $cursorA = $a->getContextCursor(); |
724 | 724 | $cursorB = $b->getContextCursor(); |
725 | 725 | |
726 | - if ( $cursorA instanceof EntityContextCursor ) { |
|
726 | + if ($cursorA instanceof EntityContextCursor) { |
|
727 | 727 | return $cursorB instanceof EntityContextCursor ? 0 : -1; |
728 | 728 | } |
729 | - if ( $cursorB instanceof EntityContextCursor ) { |
|
729 | + if ($cursorB instanceof EntityContextCursor) { |
|
730 | 730 | return $cursorA instanceof EntityContextCursor ? 0 : 1; |
731 | 731 | } |
732 | 732 | |
733 | 733 | $pidA = $cursorA->getSnakPropertyId(); |
734 | 734 | $pidB = $cursorB->getSnakPropertyId(); |
735 | 735 | |
736 | - if ( $pidA === $pidB ) { |
|
736 | + if ($pidA === $pidB) { |
|
737 | 737 | $hashA = $cursorA->getSnakHash(); |
738 | 738 | $hashB = $cursorB->getSnakHash(); |
739 | 739 | |
740 | - if ( $hashA === $hashB ) { |
|
741 | - if ( $a instanceof NullResult ) { |
|
740 | + if ($hashA === $hashB) { |
|
741 | + if ($a instanceof NullResult) { |
|
742 | 742 | return $b instanceof NullResult ? 0 : -1; |
743 | 743 | } |
744 | - if ( $b instanceof NullResult ) { |
|
744 | + if ($b instanceof NullResult) { |
|
745 | 745 | return $a instanceof NullResult ? 0 : 1; |
746 | 746 | } |
747 | 747 | |
748 | 748 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
749 | 749 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
750 | 750 | |
751 | - if ( $typeA == $typeB ) { |
|
751 | + if ($typeA == $typeB) { |
|
752 | 752 | return 0; |
753 | 753 | } else { |
754 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
754 | + return ($typeA > $typeB) ? 1 : -1; |
|
755 | 755 | } |
756 | 756 | } else { |
757 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
757 | + return ($hashA > $hashB) ? 1 : -1; |
|
758 | 758 | } |
759 | 759 | } else { |
760 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
760 | + return ($pidA > $pidB) ? 1 : -1; |
|
761 | 761 | } |
762 | 762 | } else { |
763 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
763 | + return ($orderA > $orderB) ? 1 : -1; |
|
764 | 764 | } |
765 | 765 | }; |
766 | 766 | |
767 | - uasort( $result, $sortFunction ); |
|
767 | + uasort($result, $sortFunction); |
|
768 | 768 | |
769 | 769 | return $result; |
770 | 770 | } |