@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | * @param array[] &$container |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - protected function &getClaimsArray( array &$container ) { |
|
30 | + protected function &getClaimsArray(array &$container) { |
|
31 | 31 | $entityId = $this->getEntityId(); |
32 | 32 | |
33 | - if ( !array_key_exists( $entityId, $container ) ) { |
|
33 | + if (!array_key_exists($entityId, $container)) { |
|
34 | 34 | $container[$entityId] = []; |
35 | 35 | } |
36 | 36 | $entityContainer = &$container[$entityId]; |
37 | 37 | |
38 | - if ( !array_key_exists( 'claims', $entityContainer ) ) { |
|
38 | + if (!array_key_exists('claims', $entityContainer)) { |
|
39 | 39 | $entityContainer['claims'] = []; |
40 | 40 | } |
41 | 41 | $claimsArray = &$entityContainer['claims']; |
@@ -49,25 +49,25 @@ discard block |
||
49 | 49 | * @param array[] &$container |
50 | 50 | * @return array |
51 | 51 | */ |
52 | - protected function &getStatementArray( array &$container ) { |
|
52 | + protected function &getStatementArray(array &$container) { |
|
53 | 53 | $statementPropertyId = $this->getStatementPropertyId(); |
54 | 54 | $statementGuid = $this->getStatementGuid(); |
55 | 55 | |
56 | - $claimsContainer = &$this->getClaimsArray( $container ); |
|
56 | + $claimsContainer = &$this->getClaimsArray($container); |
|
57 | 57 | |
58 | - if ( !array_key_exists( $statementPropertyId, $claimsContainer ) ) { |
|
58 | + if (!array_key_exists($statementPropertyId, $claimsContainer)) { |
|
59 | 59 | $claimsContainer[$statementPropertyId] = []; |
60 | 60 | } |
61 | 61 | $propertyContainer = &$claimsContainer[$statementPropertyId]; |
62 | 62 | |
63 | - foreach ( $propertyContainer as &$statement ) { |
|
64 | - if ( $statement['id'] === $statementGuid ) { |
|
63 | + foreach ($propertyContainer as &$statement) { |
|
64 | + if ($statement['id'] === $statementGuid) { |
|
65 | 65 | $statementArray = &$statement; |
66 | 66 | break; |
67 | 67 | } |
68 | 68 | } |
69 | - if ( !isset( $statementArray ) ) { |
|
70 | - $statementArray = [ 'id' => $statementGuid ]; |
|
69 | + if (!isset($statementArray)) { |
|
70 | + $statementArray = ['id' => $statementGuid]; |
|
71 | 71 | $propertyContainer[] = &$statementArray; |
72 | 72 | } |
73 | 73 | |
@@ -82,19 +82,19 @@ discard block |
||
82 | 82 | * @param array[] &$container |
83 | 83 | * @return array |
84 | 84 | */ |
85 | - abstract protected function &getMainArray( array &$container ); |
|
85 | + abstract protected function &getMainArray(array &$container); |
|
86 | 86 | |
87 | 87 | /** |
88 | 88 | * @param ?array $result |
89 | 89 | * @param array[] &$container |
90 | 90 | */ |
91 | - public function storeCheckResultInArray( ?array $result, array &$container ) { |
|
92 | - $mainArray = &$this->getMainArray( $container ); |
|
93 | - if ( !array_key_exists( 'results', $mainArray ) ) { |
|
91 | + public function storeCheckResultInArray(?array $result, array &$container) { |
|
92 | + $mainArray = &$this->getMainArray($container); |
|
93 | + if (!array_key_exists('results', $mainArray)) { |
|
94 | 94 | $mainArray['results'] = []; |
95 | 95 | } |
96 | 96 | |
97 | - if ( $result !== null ) { |
|
97 | + if ($result !== null) { |
|
98 | 98 | $mainArray['results'][] = $result; |
99 | 99 | } |
100 | 100 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param ItemId $itemId |
45 | 45 | * @return self |
46 | 46 | */ |
47 | - public static function fromItemId( ItemId $itemId ) { |
|
47 | + public static function fromItemId(ItemId $itemId) { |
|
48 | 48 | $ret = new self; |
49 | 49 | $ret->itemId = $itemId; |
50 | 50 | return $ret; |
@@ -80,14 +80,14 @@ discard block |
||
80 | 80 | * @throws InvalidArgumentException |
81 | 81 | * @return self |
82 | 82 | */ |
83 | - public static function fromSnak( Snak $snak ) { |
|
84 | - switch ( true ) { |
|
83 | + public static function fromSnak(Snak $snak) { |
|
84 | + switch (true) { |
|
85 | 85 | case $snak instanceof PropertyValueSnak: |
86 | 86 | $dataValue = $snak->getDataValue(); |
87 | - if ( $dataValue instanceof EntityIdValue ) { |
|
87 | + if ($dataValue instanceof EntityIdValue) { |
|
88 | 88 | $itemId = $dataValue->getEntityId(); |
89 | - if ( $itemId instanceof ItemId ) { |
|
90 | - return self::fromItemId( $itemId ); |
|
89 | + if ($itemId instanceof ItemId) { |
|
90 | + return self::fromItemId($itemId); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | break; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | return self::noValue(); |
98 | 98 | } |
99 | 99 | |
100 | - throw new InvalidArgumentException( 'Snak must contain item ID value or be a somevalue / novalue snak' ); |
|
100 | + throw new InvalidArgumentException('Snak must contain item ID value or be a somevalue / novalue snak'); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | * @return ItemId |
136 | 136 | */ |
137 | 137 | public function getItemId() { |
138 | - if ( !$this->isValue() ) { |
|
139 | - throw new DomainException( 'This value does not contain an item ID.' ); |
|
138 | + if (!$this->isValue()) { |
|
139 | + throw new DomainException('This value does not contain an item ID.'); |
|
140 | 140 | } |
141 | 141 | return $this->itemId; |
142 | 142 | } |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | * @param Snak $snak |
149 | 149 | * @return bool |
150 | 150 | */ |
151 | - public function matchesSnak( Snak $snak ) { |
|
152 | - switch ( true ) { |
|
151 | + public function matchesSnak(Snak $snak) { |
|
152 | + switch (true) { |
|
153 | 153 | case $snak instanceof PropertyValueSnak: |
154 | 154 | $dataValue = $snak->getDataValue(); |
155 | 155 | return $this->isValue() && |
156 | 156 | $dataValue instanceof EntityIdValue && |
157 | 157 | $dataValue->getEntityId() instanceof ItemId && |
158 | - $dataValue->getEntityId()->equals( $this->getItemId() ); |
|
158 | + $dataValue->getEntityId()->equals($this->getItemId()); |
|
159 | 159 | case $snak instanceof PropertySomeValueSnak: |
160 | 160 | return $this->isSomeValue(); |
161 | 161 | case $snak instanceof PropertyNoValueSnak: |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | EntityIdLookup $entityIdLookup, |
48 | 48 | RdfVocabulary $rdfVocabulary |
49 | 49 | ) { |
50 | - parent::__construct( $page, $context ); |
|
50 | + parent::__construct($page, $context); |
|
51 | 51 | $this->resultsSource = $resultsSource; |
52 | 52 | $this->entityIdLookup = $entityIdLookup; |
53 | 53 | $this->rdfVocabulary = $rdfVocabulary; |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * @param string $guid |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - private function cleanupGuid( $guid ) { |
|
112 | - return preg_replace( '/[^\w-]/', '-', $guid ); |
|
111 | + private function cleanupGuid($guid) { |
|
112 | + return preg_replace('/[^\w-]/', '-', $guid); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -121,60 +121,60 @@ discard block |
||
121 | 121 | $response = $this->getRequest()->response(); |
122 | 122 | $this->getOutput()->disable(); |
123 | 123 | |
124 | - if ( !$this->resultsSource instanceof CachingResultsSource ) { |
|
124 | + if (!$this->resultsSource instanceof CachingResultsSource) { |
|
125 | 125 | // TODO: make configurable whether only cached results are returned |
126 | - $response->statusHeader( 501 ); // Not Implemented |
|
126 | + $response->statusHeader(501); // Not Implemented |
|
127 | 127 | return null; |
128 | 128 | } |
129 | 129 | |
130 | - $entityId = $this->entityIdLookup->getEntityIdForTitle( $this->getTitle() ); |
|
131 | - if ( $entityId === null ) { |
|
132 | - $response->statusHeader( 404 ); // Not Found |
|
130 | + $entityId = $this->entityIdLookup->getEntityIdForTitle($this->getTitle()); |
|
131 | + if ($entityId === null) { |
|
132 | + $response->statusHeader(404); // Not Found |
|
133 | 133 | return null; |
134 | 134 | } |
135 | - $revId = $this->getRequest()->getInt( 'revision' ); |
|
135 | + $revId = $this->getRequest()->getInt('revision'); |
|
136 | 136 | |
137 | - $results = $this->resultsSource->getStoredResults( $entityId, $revId ); |
|
138 | - if ( $results === null ) { |
|
139 | - $response->statusHeader( 204 ); // No Content |
|
137 | + $results = $this->resultsSource->getStoredResults($entityId, $revId); |
|
138 | + if ($results === null) { |
|
139 | + $response->statusHeader(204); // No Content |
|
140 | 140 | return null; |
141 | 141 | } |
142 | 142 | |
143 | 143 | $format = 'ttl'; // TODO: make format an option |
144 | 144 | |
145 | 145 | $writerFactory = new RdfWriterFactory(); |
146 | - $formatName = $writerFactory->getFormatName( $format ); |
|
147 | - $contentType = $writerFactory->getMimeTypes( $formatName )[0]; |
|
146 | + $formatName = $writerFactory->getFormatName($format); |
|
147 | + $contentType = $writerFactory->getMimeTypes($formatName)[0]; |
|
148 | 148 | |
149 | - $writer = $writerFactory->getWriter( $formatName ); |
|
150 | - foreach ( [ RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY ] as $ns ) { |
|
151 | - $writer->prefix( $ns, $this->rdfVocabulary->getNamespaceURI( $ns ) ); |
|
149 | + $writer = $writerFactory->getWriter($formatName); |
|
150 | + foreach ([RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY] as $ns) { |
|
151 | + $writer->prefix($ns, $this->rdfVocabulary->getNamespaceURI($ns)); |
|
152 | 152 | } |
153 | 153 | $writer->start(); |
154 | 154 | $writtenAny = false; |
155 | 155 | |
156 | - foreach ( $results->getArray() as $checkResult ) { |
|
157 | - if ( $checkResult instanceof NullResult ) { |
|
156 | + foreach ($results->getArray() as $checkResult) { |
|
157 | + if ($checkResult instanceof NullResult) { |
|
158 | 158 | continue; |
159 | 159 | } |
160 | - if ( $checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS ) { |
|
160 | + if ($checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS) { |
|
161 | 161 | continue; |
162 | 162 | } |
163 | 163 | $writtenAny = true; |
164 | - $writer->about( RdfVocabulary::NS_STATEMENT, |
|
165 | - $this->cleanupGuid( $checkResult->getContextCursor()->getStatementGuid() ) ) |
|
166 | - ->say( RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint' ) |
|
167 | - ->is( RdfVocabulary::NS_STATEMENT, |
|
168 | - $this->cleanupGuid( $checkResult->getConstraint()->getConstraintId() ) ); |
|
164 | + $writer->about(RdfVocabulary::NS_STATEMENT, |
|
165 | + $this->cleanupGuid($checkResult->getContextCursor()->getStatementGuid())) |
|
166 | + ->say(RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint') |
|
167 | + ->is(RdfVocabulary::NS_STATEMENT, |
|
168 | + $this->cleanupGuid($checkResult->getConstraint()->getConstraintId())); |
|
169 | 169 | } |
170 | 170 | $writer->finish(); |
171 | - if ( $writtenAny ) { |
|
172 | - $response->header( "Content-Type: $contentType; charset=UTF-8" ); |
|
171 | + if ($writtenAny) { |
|
172 | + $response->header("Content-Type: $contentType; charset=UTF-8"); |
|
173 | 173 | echo $writer->drain(); |
174 | 174 | } else { |
175 | 175 | // Do not output RDF if we haven't written any actual statements. Output 204 instead |
176 | 176 | $writer->drain(); |
177 | - $response->statusHeader( 204 ); // No Content |
|
177 | + $response->statusHeader(204); // No Content |
|
178 | 178 | } |
179 | 179 | return null; |
180 | 180 | } |
@@ -37,25 +37,25 @@ discard block |
||
37 | 37 | * @param Title $title |
38 | 38 | * @param string[] $params should contain 'entityId' => 'Q1234' |
39 | 39 | */ |
40 | - public function __construct( Title $title, array $params ) { |
|
41 | - parent::__construct( self::COMMAND, $title, $params ); |
|
40 | + public function __construct(Title $title, array $params) { |
|
41 | + parent::__construct(self::COMMAND, $title, $params); |
|
42 | 42 | $this->removeDuplicates = true; |
43 | 43 | |
44 | - Assert::parameterType( 'string', $params['entityId'], '$params[\'entityId\']' ); |
|
44 | + Assert::parameterType('string', $params['entityId'], '$params[\'entityId\']'); |
|
45 | 45 | |
46 | - $resultSource = ConstraintsServices::getResultsSource( MediaWikiServices::getInstance() ); |
|
46 | + $resultSource = ConstraintsServices::getResultsSource(MediaWikiServices::getInstance()); |
|
47 | 47 | '@phan-var CachingResultsSource $resultSource'; |
48 | 48 | // This job should only ever be used when caching result sources are used. |
49 | - $this->setResultsSource( $resultSource ); |
|
49 | + $this->setResultsSource($resultSource); |
|
50 | 50 | |
51 | - $this->setEntityIdParser( WikibaseRepo::getEntityIdParser() ); |
|
51 | + $this->setEntityIdParser(WikibaseRepo::getEntityIdParser()); |
|
52 | 52 | } |
53 | 53 | |
54 | - public function setResultsSource( CachingResultsSource $resultsSource ) { |
|
54 | + public function setResultsSource(CachingResultsSource $resultsSource) { |
|
55 | 55 | $this->resultsSource = $resultsSource; |
56 | 56 | } |
57 | 57 | |
58 | - public function setEntityIdParser( EntityIdParser $parser ) { |
|
58 | + public function setEntityIdParser(EntityIdParser $parser) { |
|
59 | 59 | $this->entityIdParser = $parser; |
60 | 60 | } |
61 | 61 | |
@@ -66,19 +66,19 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function run() { |
68 | 68 | try { |
69 | - $entityId = $this->entityIdParser->parse( $this->params['entityId'] ); |
|
70 | - } catch ( EntityIdParsingException $e ) { |
|
69 | + $entityId = $this->entityIdParser->parse($this->params['entityId']); |
|
70 | + } catch (EntityIdParsingException $e) { |
|
71 | 71 | return false; |
72 | 72 | } |
73 | 73 | |
74 | - $this->checkConstraints( $entityId ); |
|
74 | + $this->checkConstraints($entityId); |
|
75 | 75 | |
76 | 76 | return true; |
77 | 77 | } |
78 | 78 | |
79 | - private function checkConstraints( EntityId $entityId ) { |
|
79 | + private function checkConstraints(EntityId $entityId) { |
|
80 | 80 | $this->resultsSource->getResults( |
81 | - [ $entityId ], |
|
81 | + [$entityId], |
|
82 | 82 | [], |
83 | 83 | null, |
84 | 84 | [] |
@@ -20,35 +20,35 @@ |
||
20 | 20 | public const PROPERTY_DATA_TYPE_LOOKUP = 'WBQC_PropertyDataTypeLookup'; |
21 | 21 | public const ENTITY_LOOKUP_WITHOUT_CACHE = 'WBQC_EntityLookupWithoutCache'; |
22 | 22 | |
23 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
24 | - if ( $services === null ) { |
|
23 | + private static function getService(?MediaWikiServices $services, $name) { |
|
24 | + if ($services === null) { |
|
25 | 25 | $services = MediaWikiServices::getInstance(); |
26 | 26 | } |
27 | - return $services->getService( $name ); |
|
27 | + return $services->getService($name); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @param MediaWikiServices|null $services |
32 | 32 | * @return EntityLookup |
33 | 33 | */ |
34 | - public static function getEntityLookup( MediaWikiServices $services = null ) { |
|
35 | - return self::getService( $services, self::ENTITY_LOOKUP ); |
|
34 | + public static function getEntityLookup(MediaWikiServices $services = null) { |
|
35 | + return self::getService($services, self::ENTITY_LOOKUP); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @param MediaWikiServices|null $services |
40 | 40 | * @return PropertyDataTypeLookup |
41 | 41 | */ |
42 | - public static function getPropertyDataTypeLookup( MediaWikiServices $services = null ) { |
|
43 | - return self::getService( $services, self::PROPERTY_DATA_TYPE_LOOKUP ); |
|
42 | + public static function getPropertyDataTypeLookup(MediaWikiServices $services = null) { |
|
43 | + return self::getService($services, self::PROPERTY_DATA_TYPE_LOOKUP); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param MediaWikiServices|null $services |
48 | 48 | * @return EntityLookup |
49 | 49 | */ |
50 | - public static function getEntityLookupWithoutCache( MediaWikiServices $services = null ) { |
|
51 | - return self::getService( $services, self::ENTITY_LOOKUP_WITHOUT_CACHE ); |
|
50 | + public static function getEntityLookupWithoutCache(MediaWikiServices $services = null) { |
|
51 | + return self::getService($services, self::ENTITY_LOOKUP_WITHOUT_CACHE); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
@@ -11,10 +11,10 @@ discard block |
||
11 | 11 | use Wikimedia\Rdbms\ILBFactory; |
12 | 12 | |
13 | 13 | // @codeCoverageIgnoreStart |
14 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
15 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
14 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
15 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
16 | 16 | |
17 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
17 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
18 | 18 | // @codeCoverageIgnoreEnd |
19 | 19 | |
20 | 20 | /** |
@@ -46,57 +46,57 @@ discard block |
||
46 | 46 | |
47 | 47 | public function __construct() { |
48 | 48 | parent::__construct(); |
49 | - $this->newUpdateConstraintsTableJob = static function ( $propertyIdSerialization ) { |
|
49 | + $this->newUpdateConstraintsTableJob = static function($propertyIdSerialization) { |
|
50 | 50 | return UpdateConstraintsTableJob::newFromGlobalState( |
51 | 51 | Title::newMainPage(), |
52 | - [ 'propertyId' => $propertyIdSerialization ] |
|
52 | + ['propertyId' => $propertyIdSerialization] |
|
53 | 53 | ); |
54 | 54 | }; |
55 | 55 | |
56 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
57 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
58 | - $this->setBatchSize( 10 ); |
|
56 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
57 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
58 | + $this->setBatchSize(10); |
|
59 | 59 | |
60 | 60 | // Wikibase classes are not yet loaded, so setup services in a callback run in execute |
61 | 61 | // that can be overridden in tests. |
62 | - $this->setupServices = function () { |
|
62 | + $this->setupServices = function() { |
|
63 | 63 | $services = MediaWikiServices::getInstance(); |
64 | - $this->propertyInfoLookup = WikibaseRepo::getStore( $services )->getPropertyInfoLookup(); |
|
64 | + $this->propertyInfoLookup = WikibaseRepo::getStore($services)->getPropertyInfoLookup(); |
|
65 | 65 | $this->lbFactory = $services->getDBLoadBalancerFactory(); |
66 | 66 | }; |
67 | 67 | } |
68 | 68 | |
69 | 69 | public function execute() { |
70 | - ( $this->setupServices )(); |
|
71 | - if ( !$this->getConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
72 | - $this->error( 'Constraint statements are not enabled. Aborting.' ); |
|
70 | + ($this->setupServices)(); |
|
71 | + if (!$this->getConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
72 | + $this->error('Constraint statements are not enabled. Aborting.'); |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | 76 | $propertyInfos = $this->propertyInfoLookup->getAllPropertyInfo(); |
77 | - $propertyIds = array_keys( $propertyInfos ); |
|
77 | + $propertyIds = array_keys($propertyInfos); |
|
78 | 78 | |
79 | - foreach ( array_chunk( $propertyIds, $this->getBatchSize() ) as $propertyIdsChunk ) { |
|
80 | - foreach ( $propertyIdsChunk as $propertyIdSerialization ) { |
|
81 | - $this->output( sprintf( |
|
79 | + foreach (array_chunk($propertyIds, $this->getBatchSize()) as $propertyIdsChunk) { |
|
80 | + foreach ($propertyIdsChunk as $propertyIdSerialization) { |
|
81 | + $this->output(sprintf( |
|
82 | 82 | 'Importing constraint statements for % 6s... ', |
83 | 83 | $propertyIdSerialization ), |
84 | 84 | $propertyIdSerialization |
85 | 85 | ); |
86 | - $startTime = microtime( true ); |
|
87 | - $job = call_user_func( $this->newUpdateConstraintsTableJob, $propertyIdSerialization ); |
|
86 | + $startTime = microtime(true); |
|
87 | + $job = call_user_func($this->newUpdateConstraintsTableJob, $propertyIdSerialization); |
|
88 | 88 | $job->run(); |
89 | - $endTime = microtime( true ); |
|
90 | - $millis = ( $endTime - $startTime ) * 1000; |
|
91 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
89 | + $endTime = microtime(true); |
|
90 | + $millis = ($endTime - $startTime) * 1000; |
|
91 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
92 | 92 | } |
93 | 93 | |
94 | - $this->output( 'Waiting for replication... ', 'waitForReplication' ); |
|
95 | - $startTime = microtime( true ); |
|
94 | + $this->output('Waiting for replication... ', 'waitForReplication'); |
|
95 | + $startTime = microtime(true); |
|
96 | 96 | $this->lbFactory->waitForReplication(); |
97 | - $endTime = microtime( true ); |
|
98 | - $millis = ( $endTime - $startTime ) * 1000; |
|
99 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), 'waitForReplication' ); |
|
97 | + $endTime = microtime(true); |
|
98 | + $millis = ($endTime - $startTime) * 1000; |
|
99 | + $this->output(sprintf('done in % 6.2f ms.', $millis), 'waitForReplication'); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | $this->dataFactory = $dataFactory; |
54 | 54 | $this->logger = $logger; |
55 | 55 | $this->constraintCheckDurationLimits = [ |
56 | - 'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ), |
|
57 | - 'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ), |
|
56 | + 'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'), |
|
57 | + 'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'), |
|
58 | 58 | ]; |
59 | 59 | $this->constraintCheckOnEntityDurationLimits = [ |
60 | - 'info' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationInfoSeconds' ), |
|
61 | - 'warning' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationWarningSeconds' ), |
|
60 | + 'info' => $config->get('WBQualityConstraintsCheckOnEntityDurationInfoSeconds'), |
|
61 | + 'warning' => $config->get('WBQualityConstraintsCheckOnEntityDurationWarningSeconds'), |
|
62 | 62 | ]; |
63 | 63 | } |
64 | 64 | |
@@ -69,23 +69,23 @@ discard block |
||
69 | 69 | * @param float $durationSeconds |
70 | 70 | * @return array [ $limitSeconds, $logLevel ] |
71 | 71 | */ |
72 | - private function findLimit( $limits, $durationSeconds ) { |
|
72 | + private function findLimit($limits, $durationSeconds) { |
|
73 | 73 | $limitSeconds = null; |
74 | 74 | $logLevel = null; |
75 | 75 | |
76 | - foreach ( $limits as $level => $limit ) { |
|
76 | + foreach ($limits as $level => $limit) { |
|
77 | 77 | if ( |
78 | 78 | // duration exceeds this limit |
79 | - isset( $limit ) && $durationSeconds > $limit && |
|
79 | + isset($limit) && $durationSeconds > $limit && |
|
80 | 80 | // this limit is longer than previous longest limit |
81 | - ( $limitSeconds === null || $limit > $limitSeconds ) |
|
81 | + ($limitSeconds === null || $limit > $limitSeconds) |
|
82 | 82 | ) { |
83 | 83 | $limitSeconds = $limit; |
84 | 84 | $logLevel = $level; |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - return [ $limitSeconds, $logLevel ]; |
|
88 | + return [$limitSeconds, $logLevel]; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -110,31 +110,31 @@ discard block |
||
110 | 110 | $durationSeconds, |
111 | 111 | $method |
112 | 112 | ) { |
113 | - $constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 ); |
|
113 | + $constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1); |
|
114 | 114 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
115 | 115 | |
116 | 116 | $this->dataFactory->timing( |
117 | - 'wikibase.quality.constraints.check.timing.' . |
|
118 | - $constraintTypeItemId . '-' . |
|
117 | + 'wikibase.quality.constraints.check.timing.'. |
|
118 | + $constraintTypeItemId.'-'. |
|
119 | 119 | $constraintCheckerClassShortName, |
120 | 120 | $durationSeconds * 1000 |
121 | 121 | ); |
122 | 122 | |
123 | 123 | // find the longest limit (and associated log level) that the duration exceeds |
124 | - list( $limitSeconds, $logLevel ) = $this->findLimit( |
|
124 | + list($limitSeconds, $logLevel) = $this->findLimit( |
|
125 | 125 | $this->constraintCheckDurationLimits, |
126 | 126 | $durationSeconds |
127 | 127 | ); |
128 | - if ( $limitSeconds === null ) { |
|
128 | + if ($limitSeconds === null) { |
|
129 | 129 | return; |
130 | 130 | } |
131 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
131 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
132 | 132 | // TODO log less details but still log something |
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | $resultMessage = $result->getMessage(); |
137 | - if ( $resultMessage !== null ) { |
|
137 | + if ($resultMessage !== null) { |
|
138 | 138 | $resultMessageKey = $resultMessage->getMessageKey(); |
139 | 139 | } else { |
140 | 140 | $resultMessageKey = null; |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | |
143 | 143 | $this->logger->log( |
144 | 144 | $logLevel, |
145 | - 'Constraint check with {constraintCheckerClassShortName} ' . |
|
146 | - 'took longer than {limitSeconds} second(s) ' . |
|
145 | + 'Constraint check with {constraintCheckerClassShortName} '. |
|
146 | + 'took longer than {limitSeconds} second(s) '. |
|
147 | 147 | '(duration: {durationSeconds} seconds).', |
148 | 148 | [ |
149 | 149 | 'method' => $method, |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | 'constraintId' => $constraint->getConstraintId(), |
154 | 154 | 'constraintPropertyId' => $constraint->getPropertyId()->getSerialization(), |
155 | 155 | 'constraintTypeItemId' => $constraintTypeItemId, |
156 | - 'constraintParameters' => json_encode( $constraint->getConstraintParameters() ), |
|
156 | + 'constraintParameters' => json_encode($constraint->getConstraintParameters()), |
|
157 | 157 | 'constraintCheckerClass' => $constraintCheckerClass, |
158 | 158 | 'constraintCheckerClassShortName' => $constraintCheckerClassShortName, |
159 | 159 | 'entityId' => $context->getEntity()->getId()->getSerialization(), |
160 | 160 | 'statementGuid' => $context->getSnakStatement()->getGuid(), |
161 | 161 | 'resultStatus' => $result->getStatus(), |
162 | - 'resultParameters' => json_encode( $result->getParameters() ), |
|
162 | + 'resultParameters' => json_encode($result->getParameters()), |
|
163 | 163 | 'resultMessage' => $resultMessageKey, |
164 | 164 | ] |
165 | 165 | ); |
@@ -189,18 +189,18 @@ discard block |
||
189 | 189 | ); |
190 | 190 | |
191 | 191 | // find the longest limit (and associated log level) that the duration exceeds |
192 | - list( $limitSeconds, $logLevel ) = $this->findLimit( |
|
192 | + list($limitSeconds, $logLevel) = $this->findLimit( |
|
193 | 193 | $this->constraintCheckOnEntityDurationLimits, |
194 | 194 | $durationSeconds |
195 | 195 | ); |
196 | - if ( $limitSeconds === null ) { |
|
196 | + if ($limitSeconds === null) { |
|
197 | 197 | return; |
198 | 198 | } |
199 | 199 | |
200 | 200 | $this->logger->log( |
201 | 201 | $logLevel, |
202 | - 'Full constraint check on {entityId} ' . |
|
203 | - 'took longer than {limitSeconds} second(s) ' . |
|
202 | + 'Full constraint check on {entityId} '. |
|
203 | + 'took longer than {limitSeconds} second(s) '. |
|
204 | 204 | '(duration: {durationSeconds} seconds).', |
205 | 205 | [ |
206 | 206 | 'method' => $method, |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @param EntityId $entityId |
220 | 220 | */ |
221 | - public function logCheckConstraintsCacheHit( EntityId $entityId ) { |
|
221 | + public function logCheckConstraintsCacheHit(EntityId $entityId) { |
|
222 | 222 | $this->dataFactory->increment( |
223 | 223 | 'wikibase.quality.constraints.cache.entity.hit' |
224 | 224 | ); |
@@ -229,10 +229,10 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @param EntityId[] $entityIds |
231 | 231 | */ |
232 | - public function logCheckConstraintsCacheMisses( array $entityIds ) { |
|
232 | + public function logCheckConstraintsCacheMisses(array $entityIds) { |
|
233 | 233 | $this->dataFactory->updateCount( |
234 | 234 | 'wikibase.quality.constraints.cache.entity.miss', |
235 | - count( $entityIds ) |
|
235 | + count($entityIds) |
|
236 | 236 | ); |
237 | 237 | } |
238 | 238 | |
@@ -259,17 +259,17 @@ discard block |
||
259 | 259 | * @param EntityId[] $entityIds |
260 | 260 | * @param int $maxRevisionIds |
261 | 261 | */ |
262 | - public function logHugeDependencyMetadata( array $entityIds, $maxRevisionIds ) { |
|
262 | + public function logHugeDependencyMetadata(array $entityIds, $maxRevisionIds) { |
|
263 | 263 | $this->logger->log( |
264 | 264 | 'warning', |
265 | - 'Dependency metadata for constraint check result has huge set of entity IDs ' . |
|
266 | - '(count ' . count( $entityIds ) . ', limit ' . $maxRevisionIds . '); ' . |
|
265 | + 'Dependency metadata for constraint check result has huge set of entity IDs '. |
|
266 | + '(count '.count($entityIds).', limit '.$maxRevisionIds.'); '. |
|
267 | 267 | 'caching disabled for this check result.', |
268 | 268 | [ |
269 | 269 | 'loggingMethod' => __METHOD__, |
270 | 270 | 'entityIds' => json_encode( |
271 | 271 | array_map( |
272 | - static function ( EntityId $entityId ) { |
|
272 | + static function(EntityId $entityId) { |
|
273 | 273 | return $entityId->getSerialization(); |
274 | 274 | }, |
275 | 275 | $entityIds |
@@ -288,17 +288,17 @@ discard block |
||
288 | 288 | 'Sparql API replied with status 429 and a retry-after header. Requesting to retry after {retryAfterTime}', |
289 | 289 | [ |
290 | 290 | 'retryAfterTime' => $retryAfterTime, |
291 | - 'responseHeaders' => json_encode( $request->getResponseHeaders() ), |
|
291 | + 'responseHeaders' => json_encode($request->getResponseHeaders()), |
|
292 | 292 | 'responseContent' => $request->getContent(), |
293 | 293 | ] |
294 | 294 | ); |
295 | 295 | } |
296 | 296 | |
297 | - public function logSparqlHelperTooManyRequestsRetryAfterInvalid( MWHttpRequest $request ) { |
|
297 | + public function logSparqlHelperTooManyRequestsRetryAfterInvalid(MWHttpRequest $request) { |
|
298 | 298 | $this->logger->warning( |
299 | 299 | 'Sparql API replied with status 429 and no valid retry-after header.', |
300 | 300 | [ |
301 | - 'responseHeaders' => json_encode( $request->getResponseHeaders() ), |
|
301 | + 'responseHeaders' => json_encode($request->getResponseHeaders()), |
|
302 | 302 | 'responseContent' => $request->getContent(), |
303 | 303 | ] |
304 | 304 | ); |
@@ -20,13 +20,13 @@ |
||
20 | 20 | * @param PropertyId $propertyId |
21 | 21 | * @return int |
22 | 22 | */ |
23 | - public function getPropertyCount( array $snaks, PropertyId $propertyId ) { |
|
24 | - return count( array_filter( |
|
23 | + public function getPropertyCount(array $snaks, PropertyId $propertyId) { |
|
24 | + return count(array_filter( |
|
25 | 25 | $snaks, |
26 | - static function ( Snak $snak ) use ( $propertyId ) { |
|
27 | - return $snak->getPropertyId()->equals( $propertyId ); |
|
26 | + static function(Snak $snak) use ($propertyId) { |
|
27 | + return $snak->getPropertyId()->equals($propertyId); |
|
28 | 28 | } |
29 | - ) ); |
|
29 | + )); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | } |
@@ -75,12 +75,12 @@ discard block |
||
75 | 75 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
76 | 76 | * @return CheckResult |
77 | 77 | */ |
78 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
79 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
80 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
78 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
79 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
80 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
81 | 81 | } |
82 | - if ( $context->getType() === Context::TYPE_REFERENCE ) { |
|
83 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE ); |
|
82 | + if ($context->getType() === Context::TYPE_REFERENCE) { |
|
83 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | $parameters = []; |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | $constraintTypeItemId |
93 | 93 | ); |
94 | 94 | $parameters['class'] = array_map( |
95 | - static function ( $id ) { |
|
96 | - return new ItemId( $id ); |
|
95 | + static function($id) { |
|
96 | + return new ItemId($id); |
|
97 | 97 | }, |
98 | 98 | $classes |
99 | 99 | ); |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | $constraintTypeItemId |
104 | 104 | ); |
105 | 105 | $relationIds = []; |
106 | - if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) { |
|
107 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
106 | + if ($relation === 'instance' || $relation === 'instanceOrSubclass') { |
|
107 | + $relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
108 | 108 | } |
109 | - if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) { |
|
110 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
109 | + if ($relation === 'subclass' || $relation === 'instanceOrSubclass') { |
|
110 | + $relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
111 | 111 | } |
112 | - $parameters['relation'] = [ $relation ]; |
|
112 | + $parameters['relation'] = [$relation]; |
|
113 | 113 | |
114 | 114 | $result = $this->typeCheckerHelper->hasClassInRelation( |
115 | 115 | $context->getEntity()->getStatements(), |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $classes |
118 | 118 | ); |
119 | 119 | |
120 | - if ( $result->getBool() ) { |
|
120 | + if ($result->getBool()) { |
|
121 | 121 | $message = null; |
122 | 122 | $status = CheckResult::STATUS_COMPLIANCE; |
123 | 123 | } else { |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | $status = CheckResult::STATUS_VIOLATION; |
132 | 132 | } |
133 | 133 | |
134 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
135 | - ->withMetadata( $result->getMetadata() ); |
|
134 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
135 | + ->withMetadata($result->getMetadata()); |
|
136 | 136 | } |
137 | 137 | |
138 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
138 | + public function checkConstraintParameters(Constraint $constraint) { |
|
139 | 139 | $constraintParameters = $constraint->getConstraintParameters(); |
140 | 140 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
141 | 141 | $exceptions = []; |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $constraintParameters, |
145 | 145 | $constraintTypeItemId |
146 | 146 | ); |
147 | - } catch ( ConstraintParameterException $e ) { |
|
147 | + } catch (ConstraintParameterException $e) { |
|
148 | 148 | $exceptions[] = $e; |
149 | 149 | } |
150 | 150 | try { |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $constraintParameters, |
153 | 153 | $constraintTypeItemId |
154 | 154 | ); |
155 | - } catch ( ConstraintParameterException $e ) { |
|
155 | + } catch (ConstraintParameterException $e) { |
|
156 | 156 | $exceptions[] = $e; |
157 | 157 | } |
158 | 158 | return $exceptions; |