@@ -19,26 +19,26 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class ViolationMessageSerializer implements Serializer { |
21 | 21 | |
22 | - private function abbreviateViolationMessageKey( $fullMessageKey ) { |
|
23 | - return substr( $fullMessageKey, strlen( ViolationMessage::MESSAGE_KEY_PREFIX ) ); |
|
22 | + private function abbreviateViolationMessageKey($fullMessageKey) { |
|
23 | + return substr($fullMessageKey, strlen(ViolationMessage::MESSAGE_KEY_PREFIX)); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @param ViolationMessage $object |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - public function serialize( $object ) { |
|
30 | + public function serialize($object) { |
|
31 | 31 | /** @var ViolationMessage $object */ |
32 | - Assert::parameterType( ViolationMessage::class, $object, '$object' ); |
|
32 | + Assert::parameterType(ViolationMessage::class, $object, '$object'); |
|
33 | 33 | |
34 | 34 | $arguments = $object->getArguments(); |
35 | 35 | $serializedArguments = []; |
36 | - foreach ( $arguments as $argument ) { |
|
37 | - $serializedArguments[] = $this->serializeArgument( $argument ); |
|
36 | + foreach ($arguments as $argument) { |
|
37 | + $serializedArguments[] = $this->serializeArgument($argument); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | return [ |
41 | - 'k' => $this->abbreviateViolationMessageKey( $object->getMessageKey() ), |
|
41 | + 'k' => $this->abbreviateViolationMessageKey($object->getMessageKey()), |
|
42 | 42 | 'a' => $serializedArguments, |
43 | 43 | ]; |
44 | 44 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param array $argument element of ViolationMessage::getArguments() |
48 | 48 | * @return array [ 't' => ViolationMessage::TYPE_*, 'v' => serialized value, 'r' => $role ] |
49 | 49 | */ |
50 | - private function serializeArgument( array $argument ) { |
|
50 | + private function serializeArgument(array $argument) { |
|
51 | 51 | $methods = [ |
52 | 52 | ViolationMessage::TYPE_ENTITY_ID => 'serializeEntityId', |
53 | 53 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'serializeEntityIdList', |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | $value = $argument['value']; |
70 | 70 | $role = $argument['role']; |
71 | 71 | |
72 | - if ( array_key_exists( $type, $methods ) ) { |
|
72 | + if (array_key_exists($type, $methods)) { |
|
73 | 73 | $method = $methods[$type]; |
74 | - $serializedValue = $this->$method( $value ); |
|
74 | + $serializedValue = $this->$method($value); |
|
75 | 75 | } else { |
76 | 76 | throw new InvalidArgumentException( |
77 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
77 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
78 | 78 | ); |
79 | 79 | } |
80 | 80 | |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | * @param string $string any value that shall simply be serialized to itself |
92 | 92 | * @return string that same value, unchanged |
93 | 93 | */ |
94 | - private function serializeStringByIdentity( $string ) { |
|
95 | - Assert::parameterType( 'string', $string, '$string' ); |
|
94 | + private function serializeStringByIdentity($string) { |
|
95 | + Assert::parameterType('string', $string, '$string'); |
|
96 | 96 | return $string; |
97 | 97 | } |
98 | 98 | |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | * @param string[] $strings |
101 | 101 | * @return string[] |
102 | 102 | */ |
103 | - private function serializeStringListByIdentity( $strings ) { |
|
104 | - Assert::parameterElementType( 'string', $strings, '$strings' ); |
|
103 | + private function serializeStringListByIdentity($strings) { |
|
104 | + Assert::parameterElementType('string', $strings, '$strings'); |
|
105 | 105 | return $strings; |
106 | 106 | } |
107 | 107 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param EntityId $entityId |
110 | 110 | * @return string entity ID serialization |
111 | 111 | */ |
112 | - private function serializeEntityId( EntityId $entityId ) { |
|
112 | + private function serializeEntityId(EntityId $entityId) { |
|
113 | 113 | return $entityId->getSerialization(); |
114 | 114 | } |
115 | 115 | |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | * @param EntityId[] $entityIdList |
118 | 118 | * @return string[] entity ID serializations |
119 | 119 | */ |
120 | - private function serializeEntityIdList( array $entityIdList ) { |
|
121 | - return array_map( [ $this, 'serializeEntityId' ], $entityIdList ); |
|
120 | + private function serializeEntityIdList(array $entityIdList) { |
|
121 | + return array_map([$this, 'serializeEntityId'], $entityIdList); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | * @return string entity ID serialization, '::somevalue', or '::novalue' |
127 | 127 | * (according to EntityId::PATTERN, entity ID serializations can never begin with two colons) |
128 | 128 | */ |
129 | - private function serializeItemIdSnakValue( ItemIdSnakValue $value ) { |
|
130 | - switch ( true ) { |
|
129 | + private function serializeItemIdSnakValue(ItemIdSnakValue $value) { |
|
130 | + switch (true) { |
|
131 | 131 | case $value->isValue(): |
132 | - return $this->serializeEntityId( $value->getItemId() ); |
|
132 | + return $this->serializeEntityId($value->getItemId()); |
|
133 | 133 | case $value->isSomeValue(): |
134 | 134 | return '::somevalue'; |
135 | 135 | case $value->isNoValue(): |
@@ -147,15 +147,15 @@ discard block |
||
147 | 147 | * @param ItemIdSnakValue[] $valueList |
148 | 148 | * @return string[] array of entity ID serializations, '::somevalue's or '::novalue's |
149 | 149 | */ |
150 | - private function serializeItemIdSnakValueList( array $valueList ) { |
|
151 | - return array_map( [ $this, 'serializeItemIdSnakValue' ], $valueList ); |
|
150 | + private function serializeItemIdSnakValueList(array $valueList) { |
|
151 | + return array_map([$this, 'serializeItemIdSnakValue'], $valueList); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | 155 | * @param DataValue $dataValue |
156 | 156 | * @return array the data value in array form |
157 | 157 | */ |
158 | - private function serializeDataValue( DataValue $dataValue ) { |
|
158 | + private function serializeDataValue(DataValue $dataValue) { |
|
159 | 159 | return $dataValue->toArray(); |
160 | 160 | } |
161 | 161 | |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | * @param string $contextType one of the Context::TYPE_* constants |
164 | 164 | * @return string the abbreviated context type |
165 | 165 | */ |
166 | - private function serializeContextType( $contextType ) { |
|
167 | - switch ( $contextType ) { |
|
166 | + private function serializeContextType($contextType) { |
|
167 | + switch ($contextType) { |
|
168 | 168 | case Context::TYPE_STATEMENT: |
169 | 169 | return 's'; |
170 | 170 | case Context::TYPE_QUALIFIER: |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | default: |
175 | 175 | // @codeCoverageIgnoreStart |
176 | 176 | throw new LogicException( |
177 | - 'Unknown context type ' . $contextType |
|
177 | + 'Unknown context type '.$contextType |
|
178 | 178 | ); |
179 | 179 | // @codeCoverageIgnoreEnd |
180 | 180 | } |
@@ -184,15 +184,15 @@ discard block |
||
184 | 184 | * @param string[] $contextTypeList Context::TYPE_* constants |
185 | 185 | * @return string[] abbreviated context types |
186 | 186 | */ |
187 | - private function serializeContextTypeList( array $contextTypeList ) { |
|
188 | - return array_map( [ $this, 'serializeContextType' ], $contextTypeList ); |
|
187 | + private function serializeContextTypeList(array $contextTypeList) { |
|
188 | + return array_map([$this, 'serializeContextType'], $contextTypeList); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * @param MultilingualTextValue $text |
193 | 193 | * @return mixed {@see MultilingualTextValue::getArrayValue} |
194 | 194 | */ |
195 | - private function serializeMultilingualText( MultilingualTextValue $text ) { |
|
195 | + private function serializeMultilingualText(MultilingualTextValue $text) { |
|
196 | 196 | return $text->getArrayValue(); |
197 | 197 | } |
198 | 198 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | private $constraintParameterParser; |
24 | 24 | |
25 | - public function __construct( ConstraintParameterParser $constraintParameterParser ) { |
|
25 | + public function __construct(ConstraintParameterParser $constraintParameterParser) { |
|
26 | 26 | $this->constraintParameterParser = $constraintParameterParser; |
27 | 27 | } |
28 | 28 | |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * @throws ConstraintParameterException |
69 | 69 | * @return CheckResult |
70 | 70 | */ |
71 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
72 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
73 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
71 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
72 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
73 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | $parameters = []; |
@@ -83,26 +83,26 @@ discard block |
||
83 | 83 | $parameters['language'] = $languages; |
84 | 84 | |
85 | 85 | $status = CheckResult::STATUS_VIOLATION; |
86 | - $message = ( new ViolationMessage( 'wbqc-violation-message-label-lacking' ) ) |
|
87 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
88 | - ->withLanguages( $languages ); |
|
86 | + $message = (new ViolationMessage('wbqc-violation-message-label-lacking')) |
|
87 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
88 | + ->withLanguages($languages); |
|
89 | 89 | |
90 | 90 | /** @var LabelsProvider $entity */ |
91 | 91 | $entity = $context->getEntity(); |
92 | 92 | '@phan-var LabelsProvider $entity'; |
93 | 93 | |
94 | - foreach ( $languages as $language ) { |
|
95 | - if ( $entity->getLabels()->hasTermForLanguage( $language ) ) { |
|
94 | + foreach ($languages as $language) { |
|
95 | + if ($entity->getLabels()->hasTermForLanguage($language)) { |
|
96 | 96 | $message = null; |
97 | 97 | $status = CheckResult::STATUS_COMPLIANCE; |
98 | 98 | break; |
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
102 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
103 | 103 | } |
104 | 104 | |
105 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
105 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
106 | 106 | $constraintParameters = $constraint->getConstraintParameters(); |
107 | 107 | $exceptions = []; |
108 | 108 | try { |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $constraintParameters, |
111 | 111 | $constraint->getConstraintTypeItemId() |
112 | 112 | ); |
113 | - } catch ( ConstraintParameterException $e ) { |
|
113 | + } catch (ConstraintParameterException $e) { |
|
114 | 114 | $exceptions[] = $e; |
115 | 115 | } |
116 | 116 | return $exceptions; |
@@ -72,7 +72,7 @@ |
||
72 | 72 | * @return never |
73 | 73 | */ |
74 | 74 | private function __construct() { |
75 | - throw new LogicException( 'This class should never be instantiated.' ); |
|
75 | + throw new LogicException('This class should never be instantiated.'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | } |
@@ -29,46 +29,46 @@ discard block |
||
29 | 29 | use WikiMap; |
30 | 30 | |
31 | 31 | return [ |
32 | - ConstraintsServices::EXPIRY_LOCK => static function ( MediaWikiServices $services ) { |
|
33 | - return new ExpiryLock( ObjectCache::getInstance( CACHE_ANYTHING ) ); |
|
32 | + ConstraintsServices::EXPIRY_LOCK => static function(MediaWikiServices $services) { |
|
33 | + return new ExpiryLock(ObjectCache::getInstance(CACHE_ANYTHING)); |
|
34 | 34 | }, |
35 | 35 | |
36 | - ConstraintsServices::LOGGING_HELPER => static function ( MediaWikiServices $services ) { |
|
36 | + ConstraintsServices::LOGGING_HELPER => static function(MediaWikiServices $services) { |
|
37 | 37 | return new LoggingHelper( |
38 | 38 | $services->getStatsdDataFactory(), |
39 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
39 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
40 | 40 | $services->getMainConfig() |
41 | 41 | ); |
42 | 42 | }, |
43 | 43 | |
44 | - ConstraintsServices::CONSTRAINT_STORE => static function ( MediaWikiServices $services ) { |
|
45 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
46 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
44 | + ConstraintsServices::CONSTRAINT_STORE => static function(MediaWikiServices $services) { |
|
45 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
46 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
47 | 47 | $dbName = $propertySource->getDatabaseName(); |
48 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
48 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
49 | 49 | |
50 | - if ( $propertySource->getSourceName() !== $localEntitySourceName ) { |
|
51 | - throw new \RuntimeException( 'Can\'t get a ConstraintStore for a non local entity source.' ); |
|
50 | + if ($propertySource->getSourceName() !== $localEntitySourceName) { |
|
51 | + throw new \RuntimeException('Can\'t get a ConstraintStore for a non local entity source.'); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | return new ConstraintRepositoryStore( |
55 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
55 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
56 | 56 | $dbName |
57 | 57 | ); |
58 | 58 | }, |
59 | 59 | |
60 | - ConstraintsServices::CONSTRAINT_LOOKUP => static function ( MediaWikiServices $services ) { |
|
61 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
62 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
60 | + ConstraintsServices::CONSTRAINT_LOOKUP => static function(MediaWikiServices $services) { |
|
61 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
62 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
63 | 63 | $dbName = $propertySource->getDatabaseName(); |
64 | 64 | $rawLookup = new ConstraintRepositoryLookup( |
65 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
65 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
66 | 66 | $dbName |
67 | 67 | ); |
68 | - return new CachingConstraintLookup( $rawLookup ); |
|
68 | + return new CachingConstraintLookup($rawLookup); |
|
69 | 69 | }, |
70 | 70 | |
71 | - ConstraintsServices::CHECK_RESULT_SERIALIZER => static function ( MediaWikiServices $services ) { |
|
71 | + ConstraintsServices::CHECK_RESULT_SERIALIZER => static function(MediaWikiServices $services) { |
|
72 | 72 | return new CheckResultSerializer( |
73 | 73 | new ConstraintSerializer( |
74 | 74 | false // constraint parameters are not exposed |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | ); |
80 | 80 | }, |
81 | 81 | |
82 | - ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function ( MediaWikiServices $services ) { |
|
83 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
84 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
82 | + ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function(MediaWikiServices $services) { |
|
83 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
84 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
85 | 85 | |
86 | 86 | return new CheckResultDeserializer( |
87 | 87 | new ConstraintDeserializer(), |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | ); |
95 | 95 | }, |
96 | 96 | |
97 | - ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function ( MediaWikiServices $services ) { |
|
97 | + ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function(MediaWikiServices $services) { |
|
98 | 98 | return new ViolationMessageSerializer(); |
99 | 99 | }, |
100 | 100 | |
101 | - ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function ( MediaWikiServices $services ) { |
|
102 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
103 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
101 | + ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function(MediaWikiServices $services) { |
|
102 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
103 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
104 | 104 | |
105 | 105 | return new ViolationMessageDeserializer( |
106 | 106 | $entityIdParser, |
@@ -108,37 +108,37 @@ discard block |
||
108 | 108 | ); |
109 | 109 | }, |
110 | 110 | |
111 | - ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function ( MediaWikiServices $services ) { |
|
112 | - $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory( $services ); |
|
113 | - $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
111 | + ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function(MediaWikiServices $services) { |
|
112 | + $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory($services); |
|
113 | + $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
114 | 114 | |
115 | 115 | return new ConstraintParameterParser( |
116 | 116 | $services->getMainConfig(), |
117 | 117 | $deserializerFactory, |
118 | - $entitySourceDefinitions->getDatabaseSourceForEntityType( 'item' )->getConceptBaseUri() |
|
118 | + $entitySourceDefinitions->getDatabaseSourceForEntityType('item')->getConceptBaseUri() |
|
119 | 119 | ); |
120 | 120 | }, |
121 | 121 | |
122 | - ConstraintsServices::CONNECTION_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
122 | + ConstraintsServices::CONNECTION_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
123 | 123 | return new ConnectionCheckerHelper(); |
124 | 124 | }, |
125 | 125 | |
126 | - ConstraintsServices::RANGE_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
126 | + ConstraintsServices::RANGE_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
127 | 127 | return new RangeCheckerHelper( |
128 | 128 | $services->getMainConfig(), |
129 | - WikibaseRepo::getUnitConverter( $services ) |
|
129 | + WikibaseRepo::getUnitConverter($services) |
|
130 | 130 | ); |
131 | 131 | }, |
132 | 132 | |
133 | - ConstraintsServices::SPARQL_HELPER => static function ( MediaWikiServices $services ) { |
|
134 | - $endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
135 | - if ( $endpoint === '' ) { |
|
133 | + ConstraintsServices::SPARQL_HELPER => static function(MediaWikiServices $services) { |
|
134 | + $endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint'); |
|
135 | + if ($endpoint === '') { |
|
136 | 136 | return new DummySparqlHelper(); |
137 | 137 | } |
138 | 138 | |
139 | - $rdfVocabulary = WikibaseRepo::getRdfVocabulary( $services ); |
|
140 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
141 | - $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup( $services ); |
|
139 | + $rdfVocabulary = WikibaseRepo::getRdfVocabulary($services); |
|
140 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
141 | + $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup($services); |
|
142 | 142 | |
143 | 143 | return new SparqlHelper( |
144 | 144 | $services->getMainConfig(), |
@@ -146,126 +146,126 @@ discard block |
||
146 | 146 | $entityIdParser, |
147 | 147 | $propertyDataTypeLookup, |
148 | 148 | $services->getMainWANObjectCache(), |
149 | - ConstraintsServices::getViolationMessageSerializer( $services ), |
|
150 | - ConstraintsServices::getViolationMessageDeserializer( $services ), |
|
149 | + ConstraintsServices::getViolationMessageSerializer($services), |
|
150 | + ConstraintsServices::getViolationMessageDeserializer($services), |
|
151 | 151 | $services->getStatsdDataFactory(), |
152 | - ConstraintsServices::getExpiryLock( $services ), |
|
153 | - ConstraintsServices::getLoggingHelper( $services ), |
|
154 | - WikiMap::getCurrentWikiId() . ' WikibaseQualityConstraints ' . Http::userAgent(), |
|
152 | + ConstraintsServices::getExpiryLock($services), |
|
153 | + ConstraintsServices::getLoggingHelper($services), |
|
154 | + WikiMap::getCurrentWikiId().' WikibaseQualityConstraints '.Http::userAgent(), |
|
155 | 155 | $services->getHttpRequestFactory() |
156 | 156 | ); |
157 | 157 | }, |
158 | 158 | |
159 | - ConstraintsServices::TYPE_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
159 | + ConstraintsServices::TYPE_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
160 | 160 | return new TypeCheckerHelper( |
161 | - WikibaseServices::getEntityLookup( $services ), |
|
161 | + WikibaseServices::getEntityLookup($services), |
|
162 | 162 | $services->getMainConfig(), |
163 | - ConstraintsServices::getSparqlHelper( $services ), |
|
163 | + ConstraintsServices::getSparqlHelper($services), |
|
164 | 164 | $services->getStatsdDataFactory() |
165 | 165 | ); |
166 | 166 | }, |
167 | 167 | |
168 | - ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function ( MediaWikiServices $services ) { |
|
169 | - $statementGuidParser = WikibaseRepo::getStatementGuidParser( $services ); |
|
168 | + ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function(MediaWikiServices $services) { |
|
169 | + $statementGuidParser = WikibaseRepo::getStatementGuidParser($services); |
|
170 | 170 | |
171 | 171 | $config = $services->getMainConfig(); |
172 | 172 | $checkerMap = [ |
173 | - $config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
174 | - => ConstraintCheckerServices::getConflictsWithChecker( $services ), |
|
175 | - $config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
176 | - => ConstraintCheckerServices::getItemChecker( $services ), |
|
177 | - $config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
178 | - => ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ), |
|
179 | - $config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
180 | - => ConstraintCheckerServices::getSymmetricChecker( $services ), |
|
181 | - $config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
182 | - => ConstraintCheckerServices::getInverseChecker( $services ), |
|
183 | - $config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
184 | - => ConstraintCheckerServices::getQualifierChecker( $services ), |
|
185 | - $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
186 | - => ConstraintCheckerServices::getQualifiersChecker( $services ), |
|
187 | - $config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
188 | - => ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ), |
|
189 | - $config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
190 | - => ConstraintCheckerServices::getRangeChecker( $services ), |
|
191 | - $config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
192 | - => ConstraintCheckerServices::getDiffWithinRangeChecker( $services ), |
|
193 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
194 | - => ConstraintCheckerServices::getTypeChecker( $services ), |
|
195 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
196 | - => ConstraintCheckerServices::getValueTypeChecker( $services ), |
|
197 | - $config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
198 | - => ConstraintCheckerServices::getSingleValueChecker( $services ), |
|
199 | - $config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
200 | - => ConstraintCheckerServices::getMultiValueChecker( $services ), |
|
201 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
202 | - => ConstraintCheckerServices::getUniqueValueChecker( $services ), |
|
203 | - $config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
204 | - => ConstraintCheckerServices::getFormatChecker( $services ), |
|
205 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
206 | - => ConstraintCheckerServices::getCommonsLinkChecker( $services ), |
|
207 | - $config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
208 | - => ConstraintCheckerServices::getOneOfChecker( $services ), |
|
209 | - $config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
210 | - => ConstraintCheckerServices::getValueOnlyChecker( $services ), |
|
211 | - $config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
212 | - => ConstraintCheckerServices::getReferenceChecker( $services ), |
|
213 | - $config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
214 | - => ConstraintCheckerServices::getNoBoundsChecker( $services ), |
|
215 | - $config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
216 | - => ConstraintCheckerServices::getAllowedUnitsChecker( $services ), |
|
217 | - $config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
|
218 | - => ConstraintCheckerServices::getSingleBestValueChecker( $services ), |
|
219 | - $config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
|
220 | - => ConstraintCheckerServices::getEntityTypeChecker( $services ), |
|
221 | - $config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
|
222 | - => ConstraintCheckerServices::getNoneOfChecker( $services ), |
|
223 | - $config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
|
224 | - => ConstraintCheckerServices::getIntegerChecker( $services ), |
|
225 | - $config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
|
226 | - => ConstraintCheckerServices::getCitationNeededChecker( $services ), |
|
227 | - $config->get( 'WBQualityConstraintsPropertyScopeConstraintId' ) |
|
228 | - => ConstraintCheckerServices::getPropertyScopeChecker( $services ), |
|
229 | - $config->get( 'WBQualityConstraintsContemporaryConstraintId' ) |
|
230 | - => ConstraintCheckerServices::getContemporaryChecker( $services ), |
|
231 | - $config->get( 'WBQualityConstraintsLexemeLanguageConstraintId' ) |
|
232 | - => ConstraintCheckerServices::getLexemeLanguageChecker( $services ), |
|
233 | - $config->get( 'WBQualityConstraintsLabelInLanguageConstraintId' ) |
|
234 | - => ConstraintCheckerServices::getLabelInLanguageChecker( $services ), |
|
173 | + $config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
174 | + => ConstraintCheckerServices::getConflictsWithChecker($services), |
|
175 | + $config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
176 | + => ConstraintCheckerServices::getItemChecker($services), |
|
177 | + $config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
178 | + => ConstraintCheckerServices::getTargetRequiredClaimChecker($services), |
|
179 | + $config->get('WBQualityConstraintsSymmetricConstraintId') |
|
180 | + => ConstraintCheckerServices::getSymmetricChecker($services), |
|
181 | + $config->get('WBQualityConstraintsInverseConstraintId') |
|
182 | + => ConstraintCheckerServices::getInverseChecker($services), |
|
183 | + $config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
184 | + => ConstraintCheckerServices::getQualifierChecker($services), |
|
185 | + $config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
186 | + => ConstraintCheckerServices::getQualifiersChecker($services), |
|
187 | + $config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
188 | + => ConstraintCheckerServices::getMandatoryQualifiersChecker($services), |
|
189 | + $config->get('WBQualityConstraintsRangeConstraintId') |
|
190 | + => ConstraintCheckerServices::getRangeChecker($services), |
|
191 | + $config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
192 | + => ConstraintCheckerServices::getDiffWithinRangeChecker($services), |
|
193 | + $config->get('WBQualityConstraintsTypeConstraintId') |
|
194 | + => ConstraintCheckerServices::getTypeChecker($services), |
|
195 | + $config->get('WBQualityConstraintsValueTypeConstraintId') |
|
196 | + => ConstraintCheckerServices::getValueTypeChecker($services), |
|
197 | + $config->get('WBQualityConstraintsSingleValueConstraintId') |
|
198 | + => ConstraintCheckerServices::getSingleValueChecker($services), |
|
199 | + $config->get('WBQualityConstraintsMultiValueConstraintId') |
|
200 | + => ConstraintCheckerServices::getMultiValueChecker($services), |
|
201 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
202 | + => ConstraintCheckerServices::getUniqueValueChecker($services), |
|
203 | + $config->get('WBQualityConstraintsFormatConstraintId') |
|
204 | + => ConstraintCheckerServices::getFormatChecker($services), |
|
205 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
206 | + => ConstraintCheckerServices::getCommonsLinkChecker($services), |
|
207 | + $config->get('WBQualityConstraintsOneOfConstraintId') |
|
208 | + => ConstraintCheckerServices::getOneOfChecker($services), |
|
209 | + $config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
210 | + => ConstraintCheckerServices::getValueOnlyChecker($services), |
|
211 | + $config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
212 | + => ConstraintCheckerServices::getReferenceChecker($services), |
|
213 | + $config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
214 | + => ConstraintCheckerServices::getNoBoundsChecker($services), |
|
215 | + $config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
216 | + => ConstraintCheckerServices::getAllowedUnitsChecker($services), |
|
217 | + $config->get('WBQualityConstraintsSingleBestValueConstraintId') |
|
218 | + => ConstraintCheckerServices::getSingleBestValueChecker($services), |
|
219 | + $config->get('WBQualityConstraintsAllowedEntityTypesConstraintId') |
|
220 | + => ConstraintCheckerServices::getEntityTypeChecker($services), |
|
221 | + $config->get('WBQualityConstraintsNoneOfConstraintId') |
|
222 | + => ConstraintCheckerServices::getNoneOfChecker($services), |
|
223 | + $config->get('WBQualityConstraintsIntegerConstraintId') |
|
224 | + => ConstraintCheckerServices::getIntegerChecker($services), |
|
225 | + $config->get('WBQualityConstraintsCitationNeededConstraintId') |
|
226 | + => ConstraintCheckerServices::getCitationNeededChecker($services), |
|
227 | + $config->get('WBQualityConstraintsPropertyScopeConstraintId') |
|
228 | + => ConstraintCheckerServices::getPropertyScopeChecker($services), |
|
229 | + $config->get('WBQualityConstraintsContemporaryConstraintId') |
|
230 | + => ConstraintCheckerServices::getContemporaryChecker($services), |
|
231 | + $config->get('WBQualityConstraintsLexemeLanguageConstraintId') |
|
232 | + => ConstraintCheckerServices::getLexemeLanguageChecker($services), |
|
233 | + $config->get('WBQualityConstraintsLabelInLanguageConstraintId') |
|
234 | + => ConstraintCheckerServices::getLabelInLanguageChecker($services), |
|
235 | 235 | ]; |
236 | 236 | |
237 | 237 | return new DelegatingConstraintChecker( |
238 | - WikibaseServices::getEntityLookup( $services ), |
|
238 | + WikibaseServices::getEntityLookup($services), |
|
239 | 239 | $checkerMap, |
240 | - ConstraintsServices::getConstraintLookup( $services ), |
|
241 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
240 | + ConstraintsServices::getConstraintLookup($services), |
|
241 | + ConstraintsServices::getConstraintParameterParser($services), |
|
242 | 242 | $statementGuidParser, |
243 | - ConstraintsServices::getLoggingHelper( $services ), |
|
244 | - $config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
245 | - $config->get( 'WBQualityConstraintsCheckReferences' ), |
|
246 | - $config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
243 | + ConstraintsServices::getLoggingHelper($services), |
|
244 | + $config->get('WBQualityConstraintsCheckQualifiers'), |
|
245 | + $config->get('WBQualityConstraintsCheckReferences'), |
|
246 | + $config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
247 | 247 | ); |
248 | 248 | }, |
249 | 249 | |
250 | - ConstraintsServices::RESULTS_SOURCE => static function ( MediaWikiServices $services ) { |
|
250 | + ConstraintsServices::RESULTS_SOURCE => static function(MediaWikiServices $services) { |
|
251 | 251 | $config = $services->getMainConfig(); |
252 | 252 | $resultsSource = new CheckingResultsSource( |
253 | - ConstraintsServices::getDelegatingConstraintChecker( $services ) |
|
253 | + ConstraintsServices::getDelegatingConstraintChecker($services) |
|
254 | 254 | ); |
255 | 255 | |
256 | 256 | $cacheCheckConstraintsResults = false; |
257 | 257 | |
258 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
258 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
259 | 259 | $cacheCheckConstraintsResults = true; |
260 | 260 | // check that we can use getLocalRepoWikiPageMetaDataAccessor() |
261 | 261 | // TODO we should always be able to cache constraint check results (T244726) |
262 | - $entitySources = WikibaseRepo::getEntitySourceDefinitions( $services )->getSources(); |
|
263 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
262 | + $entitySources = WikibaseRepo::getEntitySourceDefinitions($services)->getSources(); |
|
263 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
264 | 264 | |
265 | - foreach ( $entitySources as $entitySource ) { |
|
266 | - if ( $entitySource->getSourceName() !== $localEntitySourceName ) { |
|
267 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' )->warning( |
|
268 | - 'Cannot cache constraint check results for non-local source: ' . |
|
265 | + foreach ($entitySources as $entitySource) { |
|
266 | + if ($entitySource->getSourceName() !== $localEntitySourceName) { |
|
267 | + LoggerFactory::getInstance('WikibaseQualityConstraints')->warning( |
|
268 | + 'Cannot cache constraint check results for non-local source: '. |
|
269 | 269 | $entitySource->getSourceName() |
270 | 270 | ); |
271 | 271 | $cacheCheckConstraintsResults = false; |
@@ -274,28 +274,28 @@ discard block |
||
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
277 | - if ( $cacheCheckConstraintsResults ) { |
|
277 | + if ($cacheCheckConstraintsResults) { |
|
278 | 278 | $possiblyStaleConstraintTypes = [ |
279 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
280 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
281 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
282 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
279 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
280 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
281 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
282 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
283 | 283 | ]; |
284 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
284 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
285 | 285 | $wikiPageEntityMetaDataAccessor = WikibaseRepo::getLocalRepoWikiPageMetaDataAccessor( |
286 | 286 | $services ); |
287 | 287 | |
288 | 288 | $resultsSource = new CachingResultsSource( |
289 | 289 | $resultsSource, |
290 | 290 | ResultsCache::getDefaultInstance(), |
291 | - ConstraintsServices::getCheckResultSerializer( $services ), |
|
292 | - ConstraintsServices::getCheckResultDeserializer( $services ), |
|
291 | + ConstraintsServices::getCheckResultSerializer($services), |
|
292 | + ConstraintsServices::getCheckResultDeserializer($services), |
|
293 | 293 | $wikiPageEntityMetaDataAccessor, |
294 | 294 | $entityIdParser, |
295 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
295 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
296 | 296 | $possiblyStaleConstraintTypes, |
297 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
298 | - ConstraintsServices::getLoggingHelper( $services ) |
|
297 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
298 | + ConstraintsServices::getLoggingHelper($services) |
|
299 | 299 | ); |
300 | 300 | } |
301 | 301 |
@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | use WikiMap; |
19 | 19 | |
20 | 20 | // @codeCoverageIgnoreStart |
21 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
22 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
21 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
22 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
23 | 23 | |
24 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
24 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
25 | 25 | // @codeCoverageIgnoreEnd |
26 | 26 | |
27 | 27 | /** |
@@ -60,20 +60,20 @@ discard block |
||
60 | 60 | parent::__construct(); |
61 | 61 | |
62 | 62 | $this->addDescription( |
63 | - 'Import entities needed for constraint checks ' . |
|
63 | + 'Import entities needed for constraint checks '. |
|
64 | 64 | 'from Wikidata into the local repository.' |
65 | 65 | ); |
66 | 66 | $this->addOption( |
67 | 67 | 'config-format', |
68 | - 'The format in which the resulting configuration will be omitted: ' . |
|
69 | - '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' . |
|
68 | + 'The format in which the resulting configuration will be omitted: '. |
|
69 | + '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '. |
|
70 | 70 | 'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.' |
71 | 71 | ); |
72 | 72 | $this->addOption( |
73 | 73 | 'dry-run', |
74 | 74 | 'Don’t actually import entities, just print which ones would be imported.' |
75 | 75 | ); |
76 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
76 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | */ |
82 | 82 | private function setupServices() { |
83 | 83 | $services = MediaWikiServices::getInstance(); |
84 | - $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer( $services ); |
|
85 | - $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer( $services ); |
|
86 | - $this->entityStore = WikibaseRepo::getEntityStore( $services ); |
|
84 | + $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer($services); |
|
85 | + $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer($services); |
|
86 | + $this->entityStore = WikibaseRepo::getEntityStore($services); |
|
87 | 87 | $this->httpRequestFactory = $services->getHttpRequestFactory(); |
88 | - if ( !$this->getOption( 'dry-run', false ) ) { |
|
89 | - $this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' ); |
|
88 | + if (!$this->getOption('dry-run', false)) { |
|
89 | + $this->user = User::newSystemUser('WikibaseQualityConstraints importer'); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -95,21 +95,21 @@ discard block |
||
95 | 95 | |
96 | 96 | $configUpdates = []; |
97 | 97 | |
98 | - $extensionJsonFile = __DIR__ . '/../extension.json'; |
|
99 | - $extensionJsonText = file_get_contents( $extensionJsonFile ); |
|
100 | - $extensionJson = json_decode( $extensionJsonText, /* assoc = */ true ); |
|
98 | + $extensionJsonFile = __DIR__.'/../extension.json'; |
|
99 | + $extensionJsonText = file_get_contents($extensionJsonFile); |
|
100 | + $extensionJson = json_decode($extensionJsonText, /* assoc = */ true); |
|
101 | 101 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
102 | - $wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() ); |
|
102 | + $wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig()); |
|
103 | 103 | |
104 | - foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) { |
|
105 | - $localEntityId = $this->importEntityFromWikidata( $wikidataEntityId ); |
|
104 | + foreach ($wikidataEntityIds as $key => $wikidataEntityId) { |
|
105 | + $localEntityId = $this->importEntityFromWikidata($wikidataEntityId); |
|
106 | 106 | $configUpdates[$key] = [ |
107 | 107 | 'wikidata' => $wikidataEntityId, |
108 | 108 | 'local' => $localEntityId, |
109 | 109 | ]; |
110 | 110 | } |
111 | 111 | |
112 | - $this->outputConfigUpdates( $configUpdates ); |
|
112 | + $this->outputConfigUpdates($configUpdates); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | * @param Config $wikiConfig |
118 | 118 | * @return string[] |
119 | 119 | */ |
120 | - private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) { |
|
120 | + private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) { |
|
121 | 121 | $wikidataEntityIds = []; |
122 | 122 | |
123 | - foreach ( $extensionJsonConfig as $key => $value ) { |
|
124 | - if ( !preg_match( '/Id$/', $key ) ) { |
|
123 | + foreach ($extensionJsonConfig as $key => $value) { |
|
124 | + if (!preg_match('/Id$/', $key)) { |
|
125 | 125 | continue; |
126 | 126 | } |
127 | 127 | |
128 | 128 | $wikidataEntityId = $value['value']; |
129 | - $localEntityId = $wikiConfig->get( $key ); |
|
129 | + $localEntityId = $wikiConfig->get($key); |
|
130 | 130 | |
131 | - if ( $localEntityId === $wikidataEntityId ) { |
|
131 | + if ($localEntityId === $wikidataEntityId) { |
|
132 | 132 | $wikidataEntityIds[$key] = $wikidataEntityId; |
133 | 133 | } |
134 | 134 | } |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | * @param string $wikidataEntityId |
141 | 141 | * @return string local entity ID |
142 | 142 | */ |
143 | - private function importEntityFromWikidata( $wikidataEntityId ) { |
|
143 | + private function importEntityFromWikidata($wikidataEntityId) { |
|
144 | 144 | $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json"; |
145 | - $wikidataEntitiesJson = $this->httpRequestFactory->get( $wikidataEntityUrl, [], __METHOD__ ); |
|
146 | - return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ); |
|
145 | + $wikidataEntitiesJson = $this->httpRequestFactory->get($wikidataEntityUrl, [], __METHOD__); |
|
146 | + return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,24 +151,24 @@ discard block |
||
151 | 151 | * @param string $wikidataEntitiesJson |
152 | 152 | * @return string local entity ID |
153 | 153 | */ |
154 | - private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) { |
|
154 | + private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) { |
|
155 | 155 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
156 | - $wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId]; |
|
157 | - $wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray ); |
|
156 | + $wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId]; |
|
157 | + $wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray); |
|
158 | 158 | |
159 | - $wikidataEntity->setId( null ); |
|
159 | + $wikidataEntity->setId(null); |
|
160 | 160 | |
161 | - if ( $wikidataEntity instanceof StatementListProvider ) { |
|
161 | + if ($wikidataEntity instanceof StatementListProvider) { |
|
162 | 162 | $wikidataEntity->getStatements()->clear(); |
163 | 163 | } |
164 | 164 | |
165 | - if ( $wikidataEntity instanceof Item ) { |
|
166 | - $wikidataEntity->setSiteLinkList( new SiteLinkList() ); |
|
165 | + if ($wikidataEntity instanceof Item) { |
|
166 | + $wikidataEntity->setSiteLinkList(new SiteLinkList()); |
|
167 | 167 | } |
168 | 168 | |
169 | - if ( $this->getOption( 'dry-run', false ) ) { |
|
170 | - $wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) ); |
|
171 | - $this->output( $wikidataEntityJson . "\n" ); |
|
169 | + if ($this->getOption('dry-run', false)) { |
|
170 | + $wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity)); |
|
171 | + $this->output($wikidataEntityJson."\n"); |
|
172 | 172 | return "-$wikidataEntityId"; |
173 | 173 | } |
174 | 174 | |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | )->getEntity(); |
182 | 182 | |
183 | 183 | return $localEntity->getId()->getSerialization(); |
184 | - } catch ( StorageException $storageException ) { |
|
185 | - return $this->storageExceptionToEntityId( $storageException ); |
|
184 | + } catch (StorageException $storageException) { |
|
185 | + return $this->storageExceptionToEntityId($storageException); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
189 | - private function storageExceptionToEntityId( StorageException $storageException ) { |
|
189 | + private function storageExceptionToEntityId(StorageException $storageException) { |
|
190 | 190 | $message = $storageException->getMessage(); |
191 | 191 | // example messages: |
192 | 192 | // * Item [[Item:Q475|Q475]] already has label "as references" |
@@ -196,25 +196,25 @@ discard block |
||
196 | 196 | // * Property [[Property:P694|P694]] already has label "instance of" |
197 | 197 | // associated with language code en. |
198 | 198 | $pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/'; |
199 | - if ( preg_match( $pattern, $message, $matches ) ) { |
|
199 | + if (preg_match($pattern, $message, $matches)) { |
|
200 | 200 | return $matches[1]; |
201 | 201 | } else { |
202 | 202 | throw $storageException; |
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | - private function outputConfigUpdates( array $configUpdates ) { |
|
207 | - $configFormat = $this->getOption( 'config-format', 'globals' ); |
|
208 | - switch ( $configFormat ) { |
|
206 | + private function outputConfigUpdates(array $configUpdates) { |
|
207 | + $configFormat = $this->getOption('config-format', 'globals'); |
|
208 | + switch ($configFormat) { |
|
209 | 209 | case 'globals': |
210 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
210 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
211 | 211 | break; |
212 | 212 | case 'wgConf': |
213 | - $this->outputConfigUpdatesWgConf( $configUpdates ); |
|
213 | + $this->outputConfigUpdatesWgConf($configUpdates); |
|
214 | 214 | break; |
215 | 215 | default: |
216 | - $this->error( "Invalid config format \"$configFormat\", using \"globals\"" ); |
|
217 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
216 | + $this->error("Invalid config format \"$configFormat\", using \"globals\""); |
|
217 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
218 | 218 | break; |
219 | 219 | } |
220 | 220 | } |
@@ -222,22 +222,22 @@ discard block |
||
222 | 222 | /** |
223 | 223 | * @param array[] $configUpdates |
224 | 224 | */ |
225 | - private function outputConfigUpdatesGlobals( array $configUpdates ) { |
|
226 | - foreach ( $configUpdates as $key => $value ) { |
|
227 | - $localValueCode = var_export( $value['local'], true ); |
|
228 | - $this->output( "\$wg$key = $localValueCode;\n" ); |
|
225 | + private function outputConfigUpdatesGlobals(array $configUpdates) { |
|
226 | + foreach ($configUpdates as $key => $value) { |
|
227 | + $localValueCode = var_export($value['local'], true); |
|
228 | + $this->output("\$wg$key = $localValueCode;\n"); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
233 | 233 | * @param array[] $configUpdates |
234 | 234 | */ |
235 | - private function outputConfigUpdatesWgConf( array $configUpdates ) { |
|
236 | - $wikiIdCode = var_export( WikiMap::getCurrentWikiId(), true ); |
|
237 | - foreach ( $configUpdates as $key => $value ) { |
|
238 | - $keyCode = var_export( "wg$key", true ); |
|
239 | - $wikidataValueCode = var_export( $value['wikidata'], true ); |
|
240 | - $localValueCode = var_export( $value['local'], true ); |
|
235 | + private function outputConfigUpdatesWgConf(array $configUpdates) { |
|
236 | + $wikiIdCode = var_export(WikiMap::getCurrentWikiId(), true); |
|
237 | + foreach ($configUpdates as $key => $value) { |
|
238 | + $keyCode = var_export("wg$key", true); |
|
239 | + $wikidataValueCode = var_export($value['wikidata'], true); |
|
240 | + $localValueCode = var_export($value['local'], true); |
|
241 | 241 | $block = <<< EOF |
242 | 242 | $keyCode => [ |
243 | 243 | 'default' => $wikidataValueCode, |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | |
247 | 247 | |
248 | 248 | EOF; |
249 | - $this->output( $block ); |
|
249 | + $this->output($block); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 |
@@ -38,206 +38,206 @@ |
||
38 | 38 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker; |
39 | 39 | |
40 | 40 | return [ |
41 | - ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function ( MediaWikiServices $services ) { |
|
41 | + ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function(MediaWikiServices $services) { |
|
42 | 42 | return new ConflictsWithChecker( |
43 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
44 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
43 | + ConstraintsServices::getConstraintParameterParser($services), |
|
44 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
45 | 45 | ); |
46 | 46 | }, |
47 | 47 | |
48 | - ConstraintCheckerServices::ITEM_CHECKER => static function ( MediaWikiServices $services ) { |
|
48 | + ConstraintCheckerServices::ITEM_CHECKER => static function(MediaWikiServices $services) { |
|
49 | 49 | return new ItemChecker( |
50 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
51 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
50 | + ConstraintsServices::getConstraintParameterParser($services), |
|
51 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
52 | 52 | ); |
53 | 53 | }, |
54 | 54 | |
55 | - ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function ( MediaWikiServices $services ) { |
|
55 | + ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function(MediaWikiServices $services) { |
|
56 | 56 | return new TargetRequiredClaimChecker( |
57 | - WikibaseServices::getEntityLookup( $services ), |
|
58 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
59 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
57 | + WikibaseServices::getEntityLookup($services), |
|
58 | + ConstraintsServices::getConstraintParameterParser($services), |
|
59 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
60 | 60 | ); |
61 | 61 | }, |
62 | 62 | |
63 | - ConstraintCheckerServices::SYMMETRIC_CHECKER => static function ( MediaWikiServices $services ) { |
|
63 | + ConstraintCheckerServices::SYMMETRIC_CHECKER => static function(MediaWikiServices $services) { |
|
64 | 64 | return new SymmetricChecker( |
65 | - WikibaseServices::getEntityLookupWithoutCache( $services ), |
|
66 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
65 | + WikibaseServices::getEntityLookupWithoutCache($services), |
|
66 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
67 | 67 | ); |
68 | 68 | }, |
69 | 69 | |
70 | - ConstraintCheckerServices::INVERSE_CHECKER => static function ( MediaWikiServices $services ) { |
|
70 | + ConstraintCheckerServices::INVERSE_CHECKER => static function(MediaWikiServices $services) { |
|
71 | 71 | return new InverseChecker( |
72 | - WikibaseServices::getEntityLookup( $services ), |
|
73 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
74 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
72 | + WikibaseServices::getEntityLookup($services), |
|
73 | + ConstraintsServices::getConstraintParameterParser($services), |
|
74 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
75 | 75 | ); |
76 | 76 | }, |
77 | 77 | |
78 | - ConstraintCheckerServices::QUALIFIER_CHECKER => static function ( MediaWikiServices $services ) { |
|
78 | + ConstraintCheckerServices::QUALIFIER_CHECKER => static function(MediaWikiServices $services) { |
|
79 | 79 | return new QualifierChecker(); |
80 | 80 | }, |
81 | 81 | |
82 | - ConstraintCheckerServices::QUALIFIERS_CHECKER => static function ( MediaWikiServices $services ) { |
|
82 | + ConstraintCheckerServices::QUALIFIERS_CHECKER => static function(MediaWikiServices $services) { |
|
83 | 83 | return new QualifiersChecker( |
84 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
84 | + ConstraintsServices::getConstraintParameterParser($services) |
|
85 | 85 | ); |
86 | 86 | }, |
87 | 87 | |
88 | - ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function ( MediaWikiServices $services ) { |
|
88 | + ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function(MediaWikiServices $services) { |
|
89 | 89 | return new MandatoryQualifiersChecker( |
90 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
90 | + ConstraintsServices::getConstraintParameterParser($services) |
|
91 | 91 | ); |
92 | 92 | }, |
93 | 93 | |
94 | - ConstraintCheckerServices::RANGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
94 | + ConstraintCheckerServices::RANGE_CHECKER => static function(MediaWikiServices $services) { |
|
95 | 95 | return new RangeChecker( |
96 | - WikibaseServices::getPropertyDataTypeLookup( $services ), |
|
97 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
98 | - ConstraintsServices::getRangeCheckerHelper( $services ) |
|
96 | + WikibaseServices::getPropertyDataTypeLookup($services), |
|
97 | + ConstraintsServices::getConstraintParameterParser($services), |
|
98 | + ConstraintsServices::getRangeCheckerHelper($services) |
|
99 | 99 | ); |
100 | 100 | }, |
101 | 101 | |
102 | - ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
102 | + ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function(MediaWikiServices $services) { |
|
103 | 103 | return new DiffWithinRangeChecker( |
104 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
105 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
104 | + ConstraintsServices::getConstraintParameterParser($services), |
|
105 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
106 | 106 | $services->getMainConfig() |
107 | 107 | ); |
108 | 108 | }, |
109 | 109 | |
110 | - ConstraintCheckerServices::TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
110 | + ConstraintCheckerServices::TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
111 | 111 | return new TypeChecker( |
112 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
113 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
112 | + ConstraintsServices::getConstraintParameterParser($services), |
|
113 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
114 | 114 | $services->getMainConfig() |
115 | 115 | ); |
116 | 116 | }, |
117 | 117 | |
118 | - ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
118 | + ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
119 | 119 | return new ValueTypeChecker( |
120 | - WikibaseServices::getEntityLookup( $services ), |
|
121 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
122 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
120 | + WikibaseServices::getEntityLookup($services), |
|
121 | + ConstraintsServices::getConstraintParameterParser($services), |
|
122 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
123 | 123 | $services->getMainConfig() |
124 | 124 | ); |
125 | 125 | }, |
126 | 126 | |
127 | - ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
127 | + ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
128 | 128 | return new SingleValueChecker( |
129 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
129 | + ConstraintsServices::getConstraintParameterParser($services) |
|
130 | 130 | ); |
131 | 131 | }, |
132 | 132 | |
133 | - ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
133 | + ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
134 | 134 | return new MultiValueChecker( |
135 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
135 | + ConstraintsServices::getConstraintParameterParser($services) |
|
136 | 136 | ); |
137 | 137 | }, |
138 | 138 | |
139 | - ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
139 | + ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
140 | 140 | // TODO return a different, dummy implementation if SPARQL is not available |
141 | 141 | return new UniqueValueChecker( |
142 | - ConstraintsServices::getSparqlHelper( $services ), |
|
143 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
142 | + ConstraintsServices::getSparqlHelper($services), |
|
143 | + ConstraintsServices::getConstraintParameterParser($services) |
|
144 | 144 | ); |
145 | 145 | }, |
146 | 146 | |
147 | - ConstraintCheckerServices::FORMAT_CHECKER => static function ( MediaWikiServices $services ) { |
|
147 | + ConstraintCheckerServices::FORMAT_CHECKER => static function(MediaWikiServices $services) { |
|
148 | 148 | // TODO return a different, dummy implementation if SPARQL is not available |
149 | 149 | return new FormatChecker( |
150 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
150 | + ConstraintsServices::getConstraintParameterParser($services), |
|
151 | 151 | $services->getMainConfig(), |
152 | - ConstraintsServices::getSparqlHelper( $services ), |
|
152 | + ConstraintsServices::getSparqlHelper($services), |
|
153 | 153 | $services->getShellboxClientFactory() |
154 | 154 | ); |
155 | 155 | }, |
156 | 156 | |
157 | - ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function ( MediaWikiServices $services ) { |
|
157 | + ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function(MediaWikiServices $services) { |
|
158 | 158 | $pageNameNormalizer = new MediaWikiPageNameNormalizer(); |
159 | 159 | return new CommonsLinkChecker( |
160 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
160 | + ConstraintsServices::getConstraintParameterParser($services), |
|
161 | 161 | $pageNameNormalizer, |
162 | - WikibaseRepo::getPropertyDataTypeLookup( $services ) |
|
162 | + WikibaseRepo::getPropertyDataTypeLookup($services) |
|
163 | 163 | ); |
164 | 164 | }, |
165 | 165 | |
166 | - ConstraintCheckerServices::ONE_OF_CHECKER => static function ( MediaWikiServices $services ) { |
|
166 | + ConstraintCheckerServices::ONE_OF_CHECKER => static function(MediaWikiServices $services) { |
|
167 | 167 | return new OneOfChecker( |
168 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
168 | + ConstraintsServices::getConstraintParameterParser($services) |
|
169 | 169 | ); |
170 | 170 | }, |
171 | 171 | |
172 | - ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function ( MediaWikiServices $services ) { |
|
172 | + ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function(MediaWikiServices $services) { |
|
173 | 173 | return new ValueOnlyChecker(); |
174 | 174 | }, |
175 | 175 | |
176 | - ConstraintCheckerServices::REFERENCE_CHECKER => static function ( MediaWikiServices $services ) { |
|
176 | + ConstraintCheckerServices::REFERENCE_CHECKER => static function(MediaWikiServices $services) { |
|
177 | 177 | return new ReferenceChecker(); |
178 | 178 | }, |
179 | 179 | |
180 | - ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function ( MediaWikiServices $services ) { |
|
180 | + ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function(MediaWikiServices $services) { |
|
181 | 181 | return new NoBoundsChecker(); |
182 | 182 | }, |
183 | 183 | |
184 | - ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function ( MediaWikiServices $services ) { |
|
184 | + ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function(MediaWikiServices $services) { |
|
185 | 185 | return new AllowedUnitsChecker( |
186 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
187 | - WikibaseRepo::getUnitConverter( $services ) |
|
186 | + ConstraintsServices::getConstraintParameterParser($services), |
|
187 | + WikibaseRepo::getUnitConverter($services) |
|
188 | 188 | ); |
189 | 189 | }, |
190 | 190 | |
191 | - ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
191 | + ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
192 | 192 | return new SingleBestValueChecker( |
193 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
193 | + ConstraintsServices::getConstraintParameterParser($services) |
|
194 | 194 | ); |
195 | 195 | }, |
196 | 196 | |
197 | - ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
197 | + ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
198 | 198 | return new EntityTypeChecker( |
199 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
199 | + ConstraintsServices::getConstraintParameterParser($services) |
|
200 | 200 | ); |
201 | 201 | }, |
202 | 202 | |
203 | - ConstraintCheckerServices::NONE_OF_CHECKER => static function ( MediaWikiServices $services ) { |
|
203 | + ConstraintCheckerServices::NONE_OF_CHECKER => static function(MediaWikiServices $services) { |
|
204 | 204 | return new NoneOfChecker( |
205 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
205 | + ConstraintsServices::getConstraintParameterParser($services) |
|
206 | 206 | ); |
207 | 207 | }, |
208 | 208 | |
209 | - ConstraintCheckerServices::INTEGER_CHECKER => static function ( MediaWikiServices $services ) { |
|
209 | + ConstraintCheckerServices::INTEGER_CHECKER => static function(MediaWikiServices $services) { |
|
210 | 210 | return new IntegerChecker(); |
211 | 211 | }, |
212 | 212 | |
213 | - ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function ( MediaWikiServices $services ) { |
|
213 | + ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function(MediaWikiServices $services) { |
|
214 | 214 | return new CitationNeededChecker(); |
215 | 215 | }, |
216 | 216 | |
217 | - ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
217 | + ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function(MediaWikiServices $services) { |
|
218 | 218 | return new PropertyScopeChecker( |
219 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
219 | + ConstraintsServices::getConstraintParameterParser($services) |
|
220 | 220 | ); |
221 | 221 | }, |
222 | 222 | |
223 | - ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function ( MediaWikiServices $services ) { |
|
223 | + ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function(MediaWikiServices $services) { |
|
224 | 224 | return new ContemporaryChecker( |
225 | - WikibaseServices::getEntityLookup( $services ), |
|
226 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
225 | + WikibaseServices::getEntityLookup($services), |
|
226 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
227 | 227 | $services->getMainConfig() |
228 | 228 | ); |
229 | 229 | }, |
230 | 230 | |
231 | - ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
231 | + ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function(MediaWikiServices $services) { |
|
232 | 232 | return new LanguageChecker( |
233 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
234 | - WikibaseServices::getEntityLookup( $services ) |
|
233 | + ConstraintsServices::getConstraintParameterParser($services), |
|
234 | + WikibaseServices::getEntityLookup($services) |
|
235 | 235 | ); |
236 | 236 | }, |
237 | 237 | |
238 | - ConstraintCheckerServices::LABEL_IN_LANGUAGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
238 | + ConstraintCheckerServices::LABEL_IN_LANGUAGE_CHECKER => static function(MediaWikiServices $services) { |
|
239 | 239 | return new LabelInLanguageChecker( |
240 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
240 | + ConstraintsServices::getConstraintParameterParser($services) |
|
241 | 241 | ); |
242 | 242 | }, |
243 | 243 | ]; |
@@ -200,73 +200,73 @@ discard block |
||
200 | 200 | $this->defaultUserAgent = $defaultUserAgent; |
201 | 201 | $this->requestFactory = $requestFactory; |
202 | 202 | $this->entityPrefixes = []; |
203 | - foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) { |
|
204 | - $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName ); |
|
203 | + foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) { |
|
204 | + $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName); |
|
205 | 205 | } |
206 | 206 | |
207 | - $this->endpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
208 | - $this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
209 | - $this->instanceOfId = $config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
210 | - $this->subclassOfId = $config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
211 | - $this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
207 | + $this->endpoint = $config->get('WBQualityConstraintsSparqlEndpoint'); |
|
208 | + $this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
209 | + $this->instanceOfId = $config->get('WBQualityConstraintsInstanceOfId'); |
|
210 | + $this->subclassOfId = $config->get('WBQualityConstraintsSubclassOfId'); |
|
211 | + $this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
212 | 212 | $this->timeoutExceptionClasses = $config->get( |
213 | 213 | 'WBQualityConstraintsSparqlTimeoutExceptionClasses' |
214 | 214 | ); |
215 | 215 | $this->sparqlHasWikibaseSupport = $config->get( |
216 | 216 | 'WBQualityConstraintsSparqlHasWikibaseSupport' |
217 | 217 | ); |
218 | - $this->sparqlThrottlingFallbackDuration = (int)$config->get( |
|
218 | + $this->sparqlThrottlingFallbackDuration = (int) $config->get( |
|
219 | 219 | 'WBQualityConstraintsSparqlThrottlingFallbackDuration' |
220 | 220 | ); |
221 | 221 | |
222 | - $this->prefixes = $this->getQueryPrefixes( $rdfVocabulary ); |
|
222 | + $this->prefixes = $this->getQueryPrefixes($rdfVocabulary); |
|
223 | 223 | } |
224 | 224 | |
225 | - private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ) { |
|
225 | + private function getQueryPrefixes(RdfVocabulary $rdfVocabulary) { |
|
226 | 226 | // TODO: it would probably be smarter that RdfVocubulary exposed these prefixes somehow |
227 | 227 | $prefixes = ''; |
228 | - foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) { |
|
228 | + foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) { |
|
229 | 229 | $prefixes .= <<<END |
230 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
230 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
231 | 231 | END; |
232 | 232 | } |
233 | 233 | $prefixes .= <<<END |
234 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
235 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>\n |
|
234 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
235 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>\n |
|
236 | 236 | END; |
237 | 237 | |
238 | - foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) { |
|
238 | + foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) { |
|
239 | 239 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM]; |
240 | 240 | $prefixes .= <<<END |
241 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
241 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
242 | 242 | END; |
243 | 243 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM]; |
244 | 244 | $prefixes .= <<<END |
245 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
245 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
246 | 246 | END; |
247 | 247 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT]; |
248 | 248 | $prefixes .= <<<END |
249 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
249 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
250 | 250 | END; |
251 | 251 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER]; |
252 | 252 | $prefixes .= <<<END |
253 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
253 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
254 | 254 | END; |
255 | 255 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE]; |
256 | 256 | $prefixes .= <<<END |
257 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
257 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
258 | 258 | END; |
259 | 259 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE]; |
260 | 260 | $prefixes .= <<<END |
261 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
261 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
262 | 262 | END; |
263 | 263 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE]; |
264 | 264 | $prefixes .= <<<END |
265 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
265 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
266 | 266 | END; |
267 | 267 | } |
268 | 268 | $prefixes .= <<<END |
269 | -PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>\n |
|
269 | +PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>\n |
|
270 | 270 | END; |
271 | 271 | return $prefixes; |
272 | 272 | } |
@@ -278,21 +278,20 @@ discard block |
||
278 | 278 | * @return CachedBool |
279 | 279 | * @throws SparqlHelperException if the query times out or some other error occurs |
280 | 280 | */ |
281 | - public function hasType( $id, array $classes ) { |
|
281 | + public function hasType($id, array $classes) { |
|
282 | 282 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
283 | 283 | $gearingHint = $this->sparqlHasWikibaseSupport ? |
284 | - ' hint:Prior hint:gearing "forward".' : |
|
285 | - ''; |
|
284 | + ' hint:Prior hint:gearing "forward".' : ''; |
|
286 | 285 | |
287 | 286 | $metadatas = []; |
288 | 287 | |
289 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
290 | - $classesValues = implode( ' ', array_map( |
|
291 | - static function ( $class ) { |
|
292 | - return 'wd:' . $class; |
|
288 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
289 | + $classesValues = implode(' ', array_map( |
|
290 | + static function($class) { |
|
291 | + return 'wd:'.$class; |
|
293 | 292 | }, |
294 | 293 | $classesChunk |
295 | - ) ); |
|
294 | + )); |
|
296 | 295 | |
297 | 296 | $query = <<<EOF |
298 | 297 | ASK { |
@@ -302,19 +301,19 @@ discard block |
||
302 | 301 | } |
303 | 302 | EOF; |
304 | 303 | |
305 | - $result = $this->runQuery( $query ); |
|
304 | + $result = $this->runQuery($query); |
|
306 | 305 | $metadatas[] = $result->getMetadata(); |
307 | - if ( $result->getArray()['boolean'] ) { |
|
306 | + if ($result->getArray()['boolean']) { |
|
308 | 307 | return new CachedBool( |
309 | 308 | true, |
310 | - Metadata::merge( $metadatas ) |
|
309 | + Metadata::merge($metadatas) |
|
311 | 310 | ); |
312 | 311 | } |
313 | 312 | } |
314 | 313 | |
315 | 314 | return new CachedBool( |
316 | 315 | false, |
317 | - Metadata::merge( $metadatas ) |
|
316 | + Metadata::merge($metadatas) |
|
318 | 317 | ); |
319 | 318 | } |
320 | 319 | |
@@ -325,7 +324,7 @@ discard block |
||
325 | 324 | * @param PropertyId $separator |
326 | 325 | * @return string |
327 | 326 | */ |
328 | - private function nestedSeparatorFilter( PropertyId $separator ) { |
|
327 | + private function nestedSeparatorFilter(PropertyId $separator) { |
|
329 | 328 | $filter = <<<EOF |
330 | 329 | MINUS { |
331 | 330 | ?statement pq:$separator ?qualifier. |
@@ -367,10 +366,10 @@ discard block |
||
367 | 366 | array $separators |
368 | 367 | ) { |
369 | 368 | $pid = $statement->getPropertyId()->serialize(); |
370 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
369 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
371 | 370 | |
372 | - $separatorFilters = array_map( [ $this, 'nestedSeparatorFilter' ], $separators ); |
|
373 | - $finalSeparatorFilter = implode( "\n", $separatorFilters ); |
|
371 | + $separatorFilters = array_map([$this, 'nestedSeparatorFilter'], $separators); |
|
372 | + $finalSeparatorFilter = implode("\n", $separatorFilters); |
|
374 | 373 | |
375 | 374 | $query = <<<EOF |
376 | 375 | SELECT DISTINCT ?otherEntity WHERE { |
@@ -388,9 +387,9 @@ discard block |
||
388 | 387 | LIMIT 10 |
389 | 388 | EOF; |
390 | 389 | |
391 | - $result = $this->runQuery( $query ); |
|
390 | + $result = $this->runQuery($query); |
|
392 | 391 | |
393 | - return $this->getOtherEntities( $result ); |
|
392 | + return $this->getOtherEntities($result); |
|
394 | 393 | } |
395 | 394 | |
396 | 395 | /** |
@@ -415,16 +414,15 @@ discard block |
||
415 | 414 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
416 | 415 | $snak->getPropertyId() |
417 | 416 | ); |
418 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
419 | - if ( $isFullValue ) { |
|
417 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
418 | + if ($isFullValue) { |
|
420 | 419 | $prefix .= 'v'; |
421 | 420 | } |
422 | 421 | $path = $type === Context::TYPE_QUALIFIER ? |
423 | - "$prefix:$pid" : |
|
424 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
422 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
425 | 423 | |
426 | 424 | $deprecatedFilter = ''; |
427 | - if ( $ignoreDeprecatedStatements ) { |
|
425 | + if ($ignoreDeprecatedStatements) { |
|
428 | 426 | $deprecatedFilter = <<< EOF |
429 | 427 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
430 | 428 | EOF; |
@@ -444,9 +442,9 @@ discard block |
||
444 | 442 | LIMIT 10 |
445 | 443 | EOF; |
446 | 444 | |
447 | - $result = $this->runQuery( $query ); |
|
445 | + $result = $this->runQuery($query); |
|
448 | 446 | |
449 | - return $this->getOtherEntities( $result ); |
|
447 | + return $this->getOtherEntities($result); |
|
450 | 448 | } |
451 | 449 | |
452 | 450 | /** |
@@ -456,8 +454,8 @@ discard block |
||
456 | 454 | * |
457 | 455 | * @return string |
458 | 456 | */ |
459 | - private function stringLiteral( $text ) { |
|
460 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
457 | + private function stringLiteral($text) { |
|
458 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
461 | 459 | } |
462 | 460 | |
463 | 461 | /** |
@@ -467,18 +465,18 @@ discard block |
||
467 | 465 | * |
468 | 466 | * @return CachedEntityIds |
469 | 467 | */ |
470 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
471 | - return new CachedEntityIds( array_map( |
|
472 | - function ( $resultBindings ) { |
|
468 | + private function getOtherEntities(CachedQueryResults $results) { |
|
469 | + return new CachedEntityIds(array_map( |
|
470 | + function($resultBindings) { |
|
473 | 471 | $entityIRI = $resultBindings['otherEntity']['value']; |
474 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
475 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
476 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
472 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
473 | + $entityPrefixLength = strlen($entityPrefix); |
|
474 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
477 | 475 | try { |
478 | 476 | return $this->entityIdParser->parse( |
479 | - substr( $entityIRI, $entityPrefixLength ) |
|
477 | + substr($entityIRI, $entityPrefixLength) |
|
480 | 478 | ); |
481 | - } catch ( EntityIdParsingException $e ) { |
|
479 | + } catch (EntityIdParsingException $e) { |
|
482 | 480 | // fall through |
483 | 481 | } |
484 | 482 | } |
@@ -489,7 +487,7 @@ discard block |
||
489 | 487 | return null; |
490 | 488 | }, |
491 | 489 | $results->getArray()['results']['bindings'] |
492 | - ), $results->getMetadata() ); |
|
490 | + ), $results->getMetadata()); |
|
493 | 491 | } |
494 | 492 | |
495 | 493 | // phpcs:disable Generic.Metrics.CyclomaticComplexity,Squiz.WhiteSpace.FunctionSpacing |
@@ -502,50 +500,50 @@ discard block |
||
502 | 500 | * @return array the literal or IRI as a string in SPARQL syntax, |
503 | 501 | * and a boolean indicating whether it refers to a full value node or not |
504 | 502 | */ |
505 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
506 | - switch ( $dataType ) { |
|
503 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
504 | + switch ($dataType) { |
|
507 | 505 | case 'string': |
508 | 506 | case 'external-id': |
509 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
507 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
510 | 508 | case 'commonsMedia': |
511 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
512 | - return [ '<' . $url . '>', false ]; |
|
509 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
510 | + return ['<'.$url.'>', false]; |
|
513 | 511 | case 'geo-shape': |
514 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
515 | - return [ '<' . $url . '>', false ]; |
|
512 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
513 | + return ['<'.$url.'>', false]; |
|
516 | 514 | case 'tabular-data': |
517 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
518 | - return [ '<' . $url . '>', false ]; |
|
515 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
516 | + return ['<'.$url.'>', false]; |
|
519 | 517 | case 'url': |
520 | 518 | $url = $dataValue->getValue(); |
521 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
519 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
522 | 520 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
523 | 521 | // such an URL should never reach us, so just throw |
524 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
522 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
525 | 523 | } |
526 | - return [ '<' . $url . '>', false ]; |
|
524 | + return ['<'.$url.'>', false]; |
|
527 | 525 | case 'wikibase-item': |
528 | 526 | case 'wikibase-property': |
529 | 527 | /** @var EntityIdValue $dataValue */ |
530 | 528 | '@phan-var EntityIdValue $dataValue'; |
531 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
529 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
532 | 530 | case 'monolingualtext': |
533 | 531 | /** @var MonolingualTextValue $dataValue */ |
534 | 532 | '@phan-var MonolingualTextValue $dataValue'; |
535 | 533 | $lang = $dataValue->getLanguageCode(); |
536 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
534 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
537 | 535 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
538 | 536 | // such a language tag should never reach us, so just throw |
539 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
537 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
540 | 538 | } |
541 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
539 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
542 | 540 | case 'globe-coordinate': |
543 | 541 | case 'quantity': |
544 | 542 | case 'time': |
545 | 543 | // @phan-suppress-next-line PhanUndeclaredMethod |
546 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
544 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
547 | 545 | default: |
548 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
546 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
549 | 547 | } |
550 | 548 | } |
551 | 549 | // phpcs:enable |
@@ -558,43 +556,43 @@ discard block |
||
558 | 556 | * @throws SparqlHelperException if the query times out or some other error occurs |
559 | 557 | * @throws ConstraintParameterException if the $regex is invalid |
560 | 558 | */ |
561 | - public function matchesRegularExpression( $text, $regex ) { |
|
559 | + public function matchesRegularExpression($text, $regex) { |
|
562 | 560 | // caching wrapper around matchesRegularExpressionWithSparql |
563 | 561 | |
564 | - $textHash = hash( 'sha256', $text ); |
|
562 | + $textHash = hash('sha256', $text); |
|
565 | 563 | $cacheKey = $this->cache->makeKey( |
566 | 564 | 'WikibaseQualityConstraints', // extension |
567 | 565 | 'regex', // action |
568 | 566 | 'WDQS-Java', // regex flavor |
569 | - hash( 'sha256', $regex ) |
|
567 | + hash('sha256', $regex) |
|
570 | 568 | ); |
571 | 569 | |
572 | 570 | $cacheMapArray = $this->cache->getWithSetCallback( |
573 | 571 | $cacheKey, |
574 | 572 | WANObjectCache::TTL_DAY, |
575 | - function ( $cacheMapArray ) use ( $text, $regex, $textHash ) { |
|
573 | + function($cacheMapArray) use ($text, $regex, $textHash) { |
|
576 | 574 | // Initialize the cache map if not set |
577 | - if ( $cacheMapArray === false ) { |
|
575 | + if ($cacheMapArray === false) { |
|
578 | 576 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
579 | - $this->dataFactory->increment( $key ); |
|
577 | + $this->dataFactory->increment($key); |
|
580 | 578 | return []; |
581 | 579 | } |
582 | 580 | |
583 | 581 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
584 | - $this->dataFactory->increment( $key ); |
|
585 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize ); |
|
586 | - if ( $cacheMap->has( $textHash ) ) { |
|
582 | + $this->dataFactory->increment($key); |
|
583 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize); |
|
584 | + if ($cacheMap->has($textHash)) { |
|
587 | 585 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
588 | - $this->dataFactory->increment( $key ); |
|
589 | - $cacheMap->get( $textHash ); // ping cache |
|
586 | + $this->dataFactory->increment($key); |
|
587 | + $cacheMap->get($textHash); // ping cache |
|
590 | 588 | } else { |
591 | 589 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
592 | - $this->dataFactory->increment( $key ); |
|
590 | + $this->dataFactory->increment($key); |
|
593 | 591 | try { |
594 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
595 | - } catch ( ConstraintParameterException $e ) { |
|
596 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
597 | - } catch ( SparqlHelperException $e ) { |
|
592 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
593 | + } catch (ConstraintParameterException $e) { |
|
594 | + $matches = $this->serializeConstraintParameterException($e); |
|
595 | + } catch (SparqlHelperException $e) { |
|
598 | 596 | // don’t cache this |
599 | 597 | return $cacheMap->toArray(); |
600 | 598 | } |
@@ -618,42 +616,42 @@ discard block |
||
618 | 616 | ] |
619 | 617 | ); |
620 | 618 | |
621 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
619 | + if (isset($cacheMapArray[$textHash])) { |
|
622 | 620 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
623 | - $this->dataFactory->increment( $key ); |
|
621 | + $this->dataFactory->increment($key); |
|
624 | 622 | $matches = $cacheMapArray[$textHash]; |
625 | - if ( is_bool( $matches ) ) { |
|
623 | + if (is_bool($matches)) { |
|
626 | 624 | return $matches; |
627 | - } elseif ( is_array( $matches ) && |
|
628 | - $matches['type'] == ConstraintParameterException::class ) { |
|
629 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
625 | + } elseif (is_array($matches) && |
|
626 | + $matches['type'] == ConstraintParameterException::class) { |
|
627 | + throw $this->deserializeConstraintParameterException($matches); |
|
630 | 628 | } else { |
631 | 629 | throw new MWException( |
632 | - 'Value of unknown type in object cache (' . |
|
633 | - 'cache key: ' . $cacheKey . ', ' . |
|
634 | - 'cache map key: ' . $textHash . ', ' . |
|
635 | - 'value type: ' . gettype( $matches ) . ')' |
|
630 | + 'Value of unknown type in object cache ('. |
|
631 | + 'cache key: '.$cacheKey.', '. |
|
632 | + 'cache map key: '.$textHash.', '. |
|
633 | + 'value type: '.gettype($matches).')' |
|
636 | 634 | ); |
637 | 635 | } |
638 | 636 | } else { |
639 | 637 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
640 | - $this->dataFactory->increment( $key ); |
|
641 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
638 | + $this->dataFactory->increment($key); |
|
639 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
642 | 640 | } |
643 | 641 | } |
644 | 642 | |
645 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
643 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
646 | 644 | return [ |
647 | 645 | 'type' => ConstraintParameterException::class, |
648 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
646 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
649 | 647 | ]; |
650 | 648 | } |
651 | 649 | |
652 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
650 | + private function deserializeConstraintParameterException(array $serialization) { |
|
653 | 651 | $message = $this->violationMessageDeserializer->deserialize( |
654 | 652 | $serialization['violationMessage'] |
655 | 653 | ); |
656 | - return new ConstraintParameterException( $message ); |
|
654 | + return new ConstraintParameterException($message); |
|
657 | 655 | } |
658 | 656 | |
659 | 657 | /** |
@@ -667,25 +665,25 @@ discard block |
||
667 | 665 | * @throws SparqlHelperException if the query times out or some other error occurs |
668 | 666 | * @throws ConstraintParameterException if the $regex is invalid |
669 | 667 | */ |
670 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
671 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
672 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
668 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
669 | + $textStringLiteral = $this->stringLiteral($text); |
|
670 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
673 | 671 | |
674 | 672 | $query = <<<EOF |
675 | 673 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
676 | 674 | EOF; |
677 | 675 | |
678 | - $result = $this->runQuery( $query, false ); |
|
676 | + $result = $this->runQuery($query, false); |
|
679 | 677 | |
680 | 678 | $vars = $result->getArray()['results']['bindings'][0]; |
681 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
679 | + if (array_key_exists('matches', $vars)) { |
|
682 | 680 | // true or false ⇒ regex okay, text matches or not |
683 | 681 | return $vars['matches']['value'] === 'true'; |
684 | 682 | } else { |
685 | 683 | // empty result: regex broken |
686 | 684 | throw new ConstraintParameterException( |
687 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
688 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
685 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
686 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
689 | 687 | ); |
690 | 688 | } |
691 | 689 | } |
@@ -697,14 +695,14 @@ discard block |
||
697 | 695 | * |
698 | 696 | * @return boolean |
699 | 697 | */ |
700 | - public function isTimeout( $responseContent ) { |
|
701 | - $timeoutRegex = implode( '|', array_map( |
|
702 | - static function ( $fqn ) { |
|
703 | - return preg_quote( $fqn, '/' ); |
|
698 | + public function isTimeout($responseContent) { |
|
699 | + $timeoutRegex = implode('|', array_map( |
|
700 | + static function($fqn) { |
|
701 | + return preg_quote($fqn, '/'); |
|
704 | 702 | }, |
705 | 703 | $this->timeoutExceptionClasses |
706 | - ) ); |
|
707 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
704 | + )); |
|
705 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
708 | 706 | } |
709 | 707 | |
710 | 708 | /** |
@@ -716,17 +714,17 @@ discard block |
||
716 | 714 | * @return int|boolean the max-age (in seconds) |
717 | 715 | * or a plain boolean if no max-age can be determined |
718 | 716 | */ |
719 | - public function getCacheMaxAge( $responseHeaders ) { |
|
717 | + public function getCacheMaxAge($responseHeaders) { |
|
720 | 718 | if ( |
721 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
722 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
719 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
720 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
723 | 721 | ) { |
724 | 722 | $maxage = []; |
725 | 723 | if ( |
726 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
727 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
724 | + array_key_exists('cache-control', $responseHeaders) && |
|
725 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
728 | 726 | ) { |
729 | - return intval( $maxage[1] ); |
|
727 | + return intval($maxage[1]); |
|
730 | 728 | } else { |
731 | 729 | return true; |
732 | 730 | } |
@@ -747,34 +745,34 @@ discard block |
||
747 | 745 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
748 | 746 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
749 | 747 | */ |
750 | - public function getThrottling( MWHttpRequest $request ) { |
|
751 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
752 | - if ( $retryAfterValue === null ) { |
|
748 | + public function getThrottling(MWHttpRequest $request) { |
|
749 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
750 | + if ($retryAfterValue === null) { |
|
753 | 751 | return self::NO_RETRY_AFTER; |
754 | 752 | } |
755 | 753 | |
756 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
757 | - if ( empty( $trimmedRetryAfterValue ) ) { |
|
754 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
755 | + if (empty($trimmedRetryAfterValue)) { |
|
758 | 756 | return self::EMPTY_RETRY_AFTER; |
759 | 757 | } |
760 | 758 | |
761 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
762 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
763 | - if ( $delaySeconds >= 0 ) { |
|
764 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
759 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
760 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
761 | + if ($delaySeconds >= 0) { |
|
762 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
765 | 763 | } |
766 | 764 | } else { |
767 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
768 | - if ( !empty( $return ) ) { |
|
769 | - return new ConvertibleTimestamp( $return ); |
|
765 | + $return = strtotime($trimmedRetryAfterValue); |
|
766 | + if (!empty($return)) { |
|
767 | + return new ConvertibleTimestamp($return); |
|
770 | 768 | } |
771 | 769 | } |
772 | 770 | return self::INVALID_RETRY_AFTER; |
773 | 771 | } |
774 | 772 | |
775 | - private function getTimestampInFuture( DateInterval $delta ) { |
|
773 | + private function getTimestampInFuture(DateInterval $delta) { |
|
776 | 774 | $now = new ConvertibleTimestamp(); |
777 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
775 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
778 | 776 | } |
779 | 777 | |
780 | 778 | /** |
@@ -788,65 +786,64 @@ discard block |
||
788 | 786 | * |
789 | 787 | * @throws SparqlHelperException if the query times out or some other error occurs |
790 | 788 | */ |
791 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
789 | + public function runQuery($query, $needsPrefixes = true) { |
|
792 | 790 | |
793 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
794 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
791 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
792 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
795 | 793 | throw new TooManySparqlRequestsException(); |
796 | 794 | } |
797 | 795 | |
798 | - if ( $this->sparqlHasWikibaseSupport ) { |
|
796 | + if ($this->sparqlHasWikibaseSupport) { |
|
799 | 797 | $needsPrefixes = false; |
800 | 798 | } |
801 | 799 | |
802 | - if ( $needsPrefixes ) { |
|
803 | - $query = $this->prefixes . $query; |
|
800 | + if ($needsPrefixes) { |
|
801 | + $query = $this->prefixes.$query; |
|
804 | 802 | } |
805 | - $query = "#wbqc\n" . $query; |
|
803 | + $query = "#wbqc\n".$query; |
|
806 | 804 | |
807 | - $url = $this->endpoint . '?' . http_build_query( |
|
805 | + $url = $this->endpoint.'?'.http_build_query( |
|
808 | 806 | [ |
809 | 807 | 'query' => $query, |
810 | 808 | 'format' => 'json', |
811 | 809 | 'maxQueryTimeMillis' => $this->maxQueryTimeMillis, |
812 | 810 | ], |
813 | - null, ini_get( 'arg_separator.output' ), |
|
811 | + null, ini_get('arg_separator.output'), |
|
814 | 812 | // encode spaces with %20, not + |
815 | 813 | PHP_QUERY_RFC3986 |
816 | 814 | ); |
817 | 815 | |
818 | 816 | $options = [ |
819 | 817 | 'method' => 'GET', |
820 | - 'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ), |
|
818 | + 'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000), |
|
821 | 819 | 'connectTimeout' => 'default', |
822 | 820 | 'userAgent' => $this->defaultUserAgent, |
823 | 821 | ]; |
824 | - $request = $this->requestFactory->create( $url, $options, __METHOD__ ); |
|
825 | - $startTime = microtime( true ); |
|
822 | + $request = $this->requestFactory->create($url, $options, __METHOD__); |
|
823 | + $startTime = microtime(true); |
|
826 | 824 | $requestStatus = $request->execute(); |
827 | - $endTime = microtime( true ); |
|
825 | + $endTime = microtime(true); |
|
828 | 826 | $this->dataFactory->timing( |
829 | 827 | 'wikibase.quality.constraints.sparql.timing', |
830 | - ( $endTime - $startTime ) * 1000 |
|
828 | + ($endTime - $startTime) * 1000 |
|
831 | 829 | ); |
832 | 830 | |
833 | - $this->guardAgainstTooManyRequestsError( $request ); |
|
831 | + $this->guardAgainstTooManyRequestsError($request); |
|
834 | 832 | |
835 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
836 | - if ( $maxAge ) { |
|
837 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
833 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
834 | + if ($maxAge) { |
|
835 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
838 | 836 | } |
839 | 837 | |
840 | - if ( $requestStatus->isOK() ) { |
|
838 | + if ($requestStatus->isOK()) { |
|
841 | 839 | $json = $request->getContent(); |
842 | - $jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
|
843 | - if ( $jsonStatus->isOK() ) { |
|
840 | + $jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC); |
|
841 | + if ($jsonStatus->isOK()) { |
|
844 | 842 | return new CachedQueryResults( |
845 | 843 | $jsonStatus->getValue(), |
846 | 844 | Metadata::ofCachingMetadata( |
847 | 845 | $maxAge ? |
848 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
849 | - CachingMetadata::fresh() |
|
846 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
850 | 847 | ) |
851 | 848 | ); |
852 | 849 | } else { |
@@ -863,9 +860,9 @@ discard block |
||
863 | 860 | // fall through to general error handling |
864 | 861 | } |
865 | 862 | |
866 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
863 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
867 | 864 | |
868 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
865 | + if ($this->isTimeout($request->getContent())) { |
|
869 | 866 | $this->dataFactory->increment( |
870 | 867 | 'wikibase.quality.constraints.sparql.error.timeout' |
871 | 868 | ); |
@@ -880,29 +877,29 @@ discard block |
||
880 | 877 | * @param MWHttpRequest $request |
881 | 878 | * @throws TooManySparqlRequestsException |
882 | 879 | */ |
883 | - private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void { |
|
884 | - if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) { |
|
880 | + private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void { |
|
881 | + if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) { |
|
885 | 882 | return; |
886 | 883 | } |
887 | 884 | |
888 | 885 | $fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration; |
889 | 886 | |
890 | - if ( $fallbackBlockDuration < 0 ) { |
|
891 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' . |
|
892 | - $fallbackBlockDuration ); |
|
887 | + if ($fallbackBlockDuration < 0) { |
|
888 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
889 | + $fallbackBlockDuration); |
|
893 | 890 | } |
894 | 891 | |
895 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
896 | - $throttlingUntil = $this->getThrottling( $request ); |
|
897 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
898 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
892 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
893 | + $throttlingUntil = $this->getThrottling($request); |
|
894 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
895 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
899 | 896 | $this->throttlingLock->lock( |
900 | 897 | self::EXPIRY_LOCK_ID, |
901 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
898 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
902 | 899 | ); |
903 | 900 | } else { |
904 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
905 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
901 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
902 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
906 | 903 | } |
907 | 904 | throw new TooManySparqlRequestsException(); |
908 | 905 | } |
@@ -23,15 +23,15 @@ discard block |
||
23 | 23 | // no parent::__construct() call |
24 | 24 | } |
25 | 25 | |
26 | - public function hasType( $id, array $classes ) { |
|
27 | - throw new LogicException( 'methods of this class should never be called' ); |
|
26 | + public function hasType($id, array $classes) { |
|
27 | + throw new LogicException('methods of this class should never be called'); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | public function findEntitiesWithSameStatement( |
31 | 31 | Statement $statement, |
32 | 32 | array $separators |
33 | 33 | ) { |
34 | - throw new LogicException( 'methods of this class should never be called' ); |
|
34 | + throw new LogicException('methods of this class should never be called'); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function findEntitiesWithSameQualifierOrReference( |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | $type, |
41 | 41 | $ignoreDeprecatedStatements |
42 | 42 | ) { |
43 | - throw new LogicException( 'methods of this class should never be called' ); |
|
43 | + throw new LogicException('methods of this class should never be called'); |
|
44 | 44 | } |
45 | 45 | |
46 | - public function matchesRegularExpression( $text, $regex ) { |
|
47 | - throw new LogicException( 'methods of this class should never be called' ); |
|
46 | + public function matchesRegularExpression($text, $regex) { |
|
47 | + throw new LogicException('methods of this class should never be called'); |
|
48 | 48 | } |
49 | 49 | |
50 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
51 | - throw new LogicException( 'methods of this class should never be called' ); |
|
50 | + public function runQuery($query, $needsPrefixes = true) { |
|
51 | + throw new LogicException('methods of this class should never be called'); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
@@ -76,29 +76,29 @@ discard block |
||
76 | 76 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
77 | 77 | * @return CheckResult |
78 | 78 | */ |
79 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
80 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
81 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
79 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
80 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
81 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
82 | 82 | } |
83 | 83 | $parameters = []; |
84 | 84 | |
85 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
85 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
86 | 86 | |
87 | 87 | $separators = $this->constraintParameterParser->parseSeparatorsParameter( |
88 | 88 | $constraint->getConstraintParameters() |
89 | 89 | ); |
90 | 90 | $parameters['separator'] = $separators; |
91 | 91 | |
92 | - if ( $context->getType() === 'statement' ) { |
|
92 | + if ($context->getType() === 'statement') { |
|
93 | 93 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
94 | 94 | $context->getSnakStatement(), |
95 | 95 | $separators |
96 | 96 | ); |
97 | 97 | } else { |
98 | 98 | $snak = $context->getSnak(); |
99 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
99 | + if (!$snak instanceof PropertyValueSnak) { |
|
100 | 100 | // nothing to check |
101 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
101 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
102 | 102 | } |
103 | 103 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
104 | 104 | $context->getEntity()->getId(), |
@@ -111,32 +111,32 @@ discard block |
||
111 | 111 | $otherEntities = $result->getArray(); |
112 | 112 | $metadata = $result->getMetadata(); |
113 | 113 | |
114 | - if ( $otherEntities === [] ) { |
|
114 | + if ($otherEntities === []) { |
|
115 | 115 | $status = CheckResult::STATUS_COMPLIANCE; |
116 | 116 | $message = null; |
117 | 117 | } else { |
118 | - $otherEntities = array_values( array_filter( $otherEntities ) ); // remove nulls |
|
118 | + $otherEntities = array_values(array_filter($otherEntities)); // remove nulls |
|
119 | 119 | $status = CheckResult::STATUS_VIOLATION; |
120 | - $message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) ) |
|
121 | - ->withEntityIdList( $otherEntities, Role::SUBJECT ); |
|
120 | + $message = (new ViolationMessage('wbqc-violation-message-unique-value')) |
|
121 | + ->withEntityIdList($otherEntities, Role::SUBJECT); |
|
122 | 122 | } |
123 | 123 | } else { |
124 | 124 | $status = CheckResult::STATUS_TODO; |
125 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
126 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
125 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
126 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
127 | 127 | $metadata = Metadata::blank(); |
128 | 128 | } |
129 | 129 | |
130 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
131 | - ->withMetadata( $metadata ); |
|
130 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
131 | + ->withMetadata($metadata); |
|
132 | 132 | } |
133 | 133 | |
134 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
134 | + public function checkConstraintParameters(Constraint $constraint) { |
|
135 | 135 | $constraintParameters = $constraint->getConstraintParameters(); |
136 | 136 | $exceptions = []; |
137 | 137 | try { |
138 | - $this->constraintParameterParser->parseSeparatorsParameter( $constraintParameters ); |
|
139 | - } catch ( ConstraintParameterException $e ) { |
|
138 | + $this->constraintParameterParser->parseSeparatorsParameter($constraintParameters); |
|
139 | + } catch (ConstraintParameterException $e) { |
|
140 | 140 | $exceptions[] = $e; |
141 | 141 | } |
142 | 142 | return $exceptions; |