@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( function_exists( 'wfLoadExtension' ) ) { |
|
4 | - wfLoadExtension( 'WikibaseQualityConstraints', __DIR__ . '/extension.json' ); |
|
3 | +if (function_exists('wfLoadExtension')) { |
|
4 | + wfLoadExtension('WikibaseQualityConstraints', __DIR__.'/extension.json'); |
|
5 | 5 | // Keep i18n globals so mergeMessageFileList.php doesn't break |
6 | - $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__ . '/i18n'; |
|
7 | - $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__ . '/WikibaseQualityConstraints.alias.php'; |
|
6 | + $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__.'/i18n'; |
|
7 | + $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__.'/WikibaseQualityConstraints.alias.php'; |
|
8 | 8 | /* wfWarn( |
9 | 9 | 'Deprecated PHP entry point used for WikibaseQualityConstraints extension. ' . |
10 | 10 | 'Please use wfLoadExtension instead, ' . |
@@ -12,5 +12,5 @@ discard block |
||
12 | 12 | ); */ |
13 | 13 | return; |
14 | 14 | } else { |
15 | - die( 'This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+' ); |
|
15 | + die('This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+'); |
|
16 | 16 | } |
@@ -10,5 +10,5 @@ |
||
10 | 10 | |
11 | 11 | /** English (English) */ |
12 | 12 | $specialPageAliases['en'] = [ |
13 | - 'ConstraintReport' => [ 'ConstraintReport', 'Constraint Report' ], |
|
13 | + 'ConstraintReport' => ['ConstraintReport', 'Constraint Report'], |
|
14 | 14 | ]; |
@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | use WikibaseQuality\ConstraintReport\UpdateConstraintsTableJob; |
9 | 9 | use Wikibase\Repo\WikibaseRepo; |
10 | 10 | |
11 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
12 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
11 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
12 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
13 | 13 | |
14 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
14 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Runs {@link UpdateConstraintsTableJob} once for every property. |
@@ -23,23 +23,23 @@ discard block |
||
23 | 23 | public function __construct() { |
24 | 24 | parent::__construct(); |
25 | 25 | |
26 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
26 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public function execute() { |
30 | - if ( !MediaWikiServices::getInstance()->getMainConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
31 | - $this->error( 'Constraint statements are not enabled. Aborting.', 1 ); |
|
30 | + if (!MediaWikiServices::getInstance()->getMainConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
31 | + $this->error('Constraint statements are not enabled. Aborting.', 1); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $propertyInfoLookup = WikibaseRepo::getDefaultInstance()->getStore()->getPropertyInfoLookup(); |
35 | - foreach ( $propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info ) { |
|
36 | - $this->output( sprintf( 'Importing constraint statements for % 6s... ', $propertyIdSerialization ), $propertyIdSerialization ); |
|
37 | - $startTime = microtime( true ); |
|
38 | - $job = UpdateConstraintsTableJob::newFromGlobalState( Title::newMainPage(), [ 'propertyId' => $propertyIdSerialization ] ); |
|
35 | + foreach ($propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info) { |
|
36 | + $this->output(sprintf('Importing constraint statements for % 6s... ', $propertyIdSerialization), $propertyIdSerialization); |
|
37 | + $startTime = microtime(true); |
|
38 | + $job = UpdateConstraintsTableJob::newFromGlobalState(Title::newMainPage(), ['propertyId' => $propertyIdSerialization]); |
|
39 | 39 | $job->run(); |
40 | - $endTime = microtime( true ); |
|
41 | - $millis = ( $endTime - $startTime ) * 1000; |
|
42 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
40 | + $endTime = microtime(true); |
|
41 | + $millis = ($endTime - $startTime) * 1000; |
|
42 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 |
@@ -14,6 +14,6 @@ |
||
14 | 14 | * |
15 | 15 | * @return Constraint[] |
16 | 16 | */ |
17 | - public function queryConstraintsForProperty( PropertyId $propertyId ); |
|
17 | + public function queryConstraintsForProperty(PropertyId $propertyId); |
|
18 | 18 | |
19 | 19 | } |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | |
27 | 27 | const BATCH_SIZE = 10; |
28 | 28 | |
29 | - public static function newFromGlobalState( Title $title, array $params ) { |
|
30 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
29 | + public static function newFromGlobalState(Title $title, array $params) { |
|
30 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
31 | 31 | $repo = WikibaseRepo::getDefaultInstance(); |
32 | 32 | return new UpdateConstraintsTableJob( |
33 | 33 | $title, |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | EntityLookup $entityLookup, |
84 | 84 | Serializer $snakSerializer |
85 | 85 | ) { |
86 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
86 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
87 | 87 | |
88 | 88 | $this->propertyId = $propertyId; |
89 | 89 | $this->config = $config; |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | $this->snakSerializer = $snakSerializer; |
93 | 93 | } |
94 | 94 | |
95 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
95 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
96 | 96 | $parameters = []; |
97 | - foreach ( $qualifiers as $qualifier ) { |
|
97 | + foreach ($qualifiers as $qualifier) { |
|
98 | 98 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
99 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
99 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
100 | 100 | $parameters[$qualifierId][] = $paramSerialization; |
101 | 101 | } |
102 | 102 | return $parameters; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | ) { |
109 | 109 | $constraintId = $constraintStatement->getGuid(); |
110 | 110 | $constraintTypeQid = $constraintStatement->getMainSnak()->getDataValue()->getEntityId()->getSerialization(); |
111 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
111 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
112 | 112 | return new Constraint( |
113 | 113 | $constraintId, |
114 | 114 | $propertyId, |
@@ -122,16 +122,16 @@ discard block |
||
122 | 122 | ConstraintRepository $constraintRepo, |
123 | 123 | PropertyId $propertyConstraintPropertyId |
124 | 124 | ) { |
125 | - $constraintsStatements = $property->getStatements()->getByPropertyId( $propertyConstraintPropertyId ); |
|
125 | + $constraintsStatements = $property->getStatements()->getByPropertyId($propertyConstraintPropertyId); |
|
126 | 126 | $constraints = []; |
127 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
128 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
129 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
130 | - $constraintRepo->insertBatch( $constraints ); |
|
127 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
128 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
129 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
130 | + $constraintRepo->insertBatch($constraints); |
|
131 | 131 | $constraints = []; |
132 | 132 | } |
133 | 133 | } |
134 | - $constraintRepo->insertBatch( $constraints ); |
|
134 | + $constraintRepo->insertBatch($constraints); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | public function run() { |
143 | 143 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
144 | 144 | |
145 | - $propertyId = new PropertyId( $this->propertyId ); |
|
146 | - $this->constraintRepo->deleteForPropertyWhereConstraintIdIsStatementId( $propertyId ); |
|
145 | + $propertyId = new PropertyId($this->propertyId); |
|
146 | + $this->constraintRepo->deleteForPropertyWhereConstraintIdIsStatementId($propertyId); |
|
147 | 147 | |
148 | - $property = $this->entityLookup->getEntity( $propertyId ); |
|
148 | + $property = $this->entityLookup->getEntity($propertyId); |
|
149 | 149 | $this->importConstraintsForProperty( |
150 | 150 | $property, |
151 | 151 | $this->constraintRepo, |
152 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
152 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
153 | 153 | ); |
154 | 154 | |
155 | 155 | return true; |
@@ -20,23 +20,23 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return Constraint[] |
22 | 22 | */ |
23 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
24 | - $db = wfGetDB( DB_REPLICA ); |
|
23 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
24 | + $db = wfGetDB(DB_REPLICA); |
|
25 | 25 | |
26 | 26 | $results = $db->select( |
27 | 27 | 'wbqc_constraints', |
28 | 28 | '*', |
29 | - [ 'pid' => $propertyId->getNumericId() ] |
|
29 | + ['pid' => $propertyId->getNumericId()] |
|
30 | 30 | ); |
31 | 31 | |
32 | - return $this->convertToConstraints( $results ); |
|
32 | + return $this->convertToConstraints($results); |
|
33 | 33 | } |
34 | 34 | |
35 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
36 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
35 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
36 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
37 | 37 | |
38 | - if ( strlen( $json ) > 50000 ) { |
|
39 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
38 | + if (strlen($json) > 50000) { |
|
39 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | return $json; |
@@ -48,21 +48,21 @@ discard block |
||
48 | 48 | * @throws DBUnexpectedError |
49 | 49 | * @return bool |
50 | 50 | */ |
51 | - public function insertBatch( array $constraints ) { |
|
51 | + public function insertBatch(array $constraints) { |
|
52 | 52 | $accumulator = array_map( |
53 | - function ( Constraint $constraint ) { |
|
53 | + function(Constraint $constraint) { |
|
54 | 54 | return [ |
55 | 55 | 'constraint_guid' => $constraint->getConstraintId(), |
56 | 56 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
57 | 57 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
58 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
58 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
59 | 59 | ]; |
60 | 60 | }, |
61 | 61 | $constraints |
62 | 62 | ); |
63 | 63 | |
64 | - $db = wfGetDB( DB_MASTER ); |
|
65 | - return $db->insert( 'wbqc_constraints', $accumulator ); |
|
64 | + $db = wfGetDB(DB_MASTER); |
|
65 | + return $db->insert('wbqc_constraints', $accumulator); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return array |
72 | 72 | */ |
73 | - private function uuidPattern( LikeMatch $any ) { |
|
73 | + private function uuidPattern(LikeMatch $any) { |
|
74 | 74 | return array_merge( |
75 | - array_fill( 0, 8, $any ), [ '-' ], |
|
76 | - array_fill( 0, 4, $any ), [ '-' ], |
|
77 | - array_fill( 0, 4, $any ), [ '-' ], |
|
78 | - array_fill( 0, 4, $any ), [ '-' ], |
|
79 | - array_fill( 0, 12, $any ) |
|
75 | + array_fill(0, 8, $any), ['-'], |
|
76 | + array_fill(0, 4, $any), ['-'], |
|
77 | + array_fill(0, 4, $any), ['-'], |
|
78 | + array_fill(0, 4, $any), ['-'], |
|
79 | + array_fill(0, 12, $any) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | * @throws DBUnexpectedError |
88 | 88 | */ |
89 | 89 | public function deleteWhereConstraintIdIsUuid() { |
90 | - $db = wfGetDB( DB_MASTER ); |
|
90 | + $db = wfGetDB(DB_MASTER); |
|
91 | 91 | $db->delete( |
92 | 92 | 'wbqc_constraints', |
93 | 93 | // WHERE constraint_guid LIKE ________-____-____-____-____________ |
94 | - 'constraint_guid ' . $db->buildLike( $this->uuidPattern( $db->anyChar() ) ) |
|
94 | + 'constraint_guid '.$db->buildLike($this->uuidPattern($db->anyChar())) |
|
95 | 95 | ); |
96 | 96 | } |
97 | 97 | |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @throws DBUnexpectedError |
103 | 103 | */ |
104 | - public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) { |
|
105 | - $db = wfGetDB( DB_MASTER ); |
|
104 | + public function deleteForPropertyWhereConstraintIdIsStatementId(PropertyId $propertyId) { |
|
105 | + $db = wfGetDB(DB_MASTER); |
|
106 | 106 | $db->delete( |
107 | 107 | 'wbqc_constraints', |
108 | 108 | [ |
109 | 109 | 'pid' => $propertyId->getNumericId(), |
110 | 110 | // AND constraint_guid LIKE %$________-____-____-____-____________ |
111 | - 'constraint_guid ' . $db->buildLike( array_merge( [ $db->anyString(), '$' ], $this->uuidPattern( $db->anyChar() ) ) ) |
|
111 | + 'constraint_guid '.$db->buildLike(array_merge([$db->anyString(), '$'], $this->uuidPattern($db->anyChar()))) |
|
112 | 112 | ] |
113 | 113 | ); |
114 | 114 | } |
@@ -119,20 +119,20 @@ discard block |
||
119 | 119 | * @throws InvalidArgumentException |
120 | 120 | * @throws DBUnexpectedError |
121 | 121 | */ |
122 | - public function deleteAll( $batchSize = 1000 ) { |
|
123 | - if ( !is_int( $batchSize ) ) { |
|
122 | + public function deleteAll($batchSize = 1000) { |
|
123 | + if (!is_int($batchSize)) { |
|
124 | 124 | throw new InvalidArgumentException(); |
125 | 125 | } |
126 | - $db = wfGetDB( DB_MASTER ); |
|
127 | - if ( $db->getType() === 'sqlite' ) { |
|
128 | - $db->delete( 'wbqc_constraints', '*' ); |
|
126 | + $db = wfGetDB(DB_MASTER); |
|
127 | + if ($db->getType() === 'sqlite') { |
|
128 | + $db->delete('wbqc_constraints', '*'); |
|
129 | 129 | } else { |
130 | 130 | do { |
131 | - $db->commit( __METHOD__, 'flush' ); |
|
131 | + $db->commit(__METHOD__, 'flush'); |
|
132 | 132 | wfGetLBFactory()->waitForReplication(); |
133 | - $table = $db->tableName( 'wbqc_constraints' ); |
|
134 | - $db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) ); |
|
135 | - } while ( $db->affectedRows() > 0 ); |
|
133 | + $table = $db->tableName('wbqc_constraints'); |
|
134 | + $db->query(sprintf('DELETE FROM %s LIMIT %d', $table, $batchSize)); |
|
135 | + } while ($db->affectedRows() > 0); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -141,26 +141,26 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return Constraint[] |
143 | 143 | */ |
144 | - private function convertToConstraints( ResultWrapper $results ) { |
|
144 | + private function convertToConstraints(ResultWrapper $results) { |
|
145 | 145 | $constraints = []; |
146 | - foreach ( $results as $result ) { |
|
146 | + foreach ($results as $result) { |
|
147 | 147 | $constraintTypeItemId = $result->constraint_type_qid; |
148 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
148 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
149 | 149 | |
150 | - if ( $constraintParameters === null ) { |
|
150 | + if ($constraintParameters === null) { |
|
151 | 151 | // T171295 |
152 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ) |
|
153 | - ->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
152 | + LoggerFactory::getInstance('WikibaseQualityConstraints') |
|
153 | + ->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
154 | 154 | 'method' => __METHOD__, |
155 | 155 | 'constraintId' => $result->constraint_guid, |
156 | 156 | 'constraintParameters' => $result->constraint_parameters, |
157 | - ] ); |
|
158 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
157 | + ]); |
|
158 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | $constraints[] = new Constraint( |
162 | 162 | $result->constraint_guid, |
163 | - PropertyId::newFromNumber( $result->pid ), |
|
163 | + PropertyId::newFromNumber($result->pid), |
|
164 | 164 | $constraintTypeItemId, |
165 | 165 | $constraintParameters |
166 | 166 | ); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @var ConstraintLookup $lookup The lookup to which all queries are delegated. |
28 | 28 | */ |
29 | - public function __construct( ConstraintLookup $lookup ) { |
|
29 | + public function __construct(ConstraintLookup $lookup) { |
|
30 | 30 | $this->lookup = $lookup; |
31 | 31 | } |
32 | 32 | |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return Constraint[] |
37 | 37 | */ |
38 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
38 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
39 | 39 | $id = $propertyId->getSerialization(); |
40 | - if ( !array_key_exists( $id, $this->cache ) ) { |
|
41 | - $this->cache[$id] = $this->lookup->queryConstraintsForProperty( $propertyId ); |
|
40 | + if (!array_key_exists($id, $this->cache)) { |
|
41 | + $this->cache[$id] = $this->lookup->queryConstraintsForProperty($propertyId); |
|
42 | 42 | } |
43 | 43 | return $this->cache[$id]; |
44 | 44 | } |
@@ -60,20 +60,20 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return string HTML |
62 | 62 | */ |
63 | - public function formatValue( $value ) { |
|
64 | - if ( is_string( $value ) ) { |
|
63 | + public function formatValue($value) { |
|
64 | + if (is_string($value)) { |
|
65 | 65 | // Cases like 'Format' 'pattern' or 'minimum'/'maximum' values, which we have stored as |
66 | 66 | // strings |
67 | - return htmlspecialchars( $value ); |
|
68 | - } elseif ( $value instanceof EntityId ) { |
|
67 | + return htmlspecialchars($value); |
|
68 | + } elseif ($value instanceof EntityId) { |
|
69 | 69 | // Cases like 'Conflicts with' 'property', to which we can link |
70 | - return $this->formatEntityId( $value ); |
|
71 | - } elseif ( $value instanceof ItemIdSnakValue ) { |
|
70 | + return $this->formatEntityId($value); |
|
71 | + } elseif ($value instanceof ItemIdSnakValue) { |
|
72 | 72 | // Cases like EntityId but can also be somevalue or novalue |
73 | - return $this->formatItemIdSnakValue( $value ); |
|
73 | + return $this->formatItemIdSnakValue($value); |
|
74 | 74 | } else { |
75 | 75 | // Cases where we format a DataValue |
76 | - return $this->formatDataValue( $value ); |
|
76 | + return $this->formatDataValue($value); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
@@ -84,23 +84,23 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return string HTML |
86 | 86 | */ |
87 | - public function formatParameters( $parameters ) { |
|
88 | - if ( $parameters === null || count( $parameters ) == 0 ) { |
|
87 | + public function formatParameters($parameters) { |
|
88 | + if ($parameters === null || count($parameters) == 0) { |
|
89 | 89 | return null; |
90 | 90 | } |
91 | 91 | |
92 | - $valueFormatter = function ( $value ) { |
|
93 | - return $this->formatValue( $value ); |
|
92 | + $valueFormatter = function($value) { |
|
93 | + return $this->formatValue($value); |
|
94 | 94 | }; |
95 | 95 | |
96 | 96 | $formattedParameters = []; |
97 | - foreach ( $parameters as $parameterName => $parameterValue ) { |
|
98 | - $formattedParameterValues = implode( ', ', |
|
99 | - $this->limitArrayLength( array_map( $valueFormatter, $parameterValue ) ) ); |
|
100 | - $formattedParameters[] = sprintf( '%s: %s', $parameterName, $formattedParameterValues ); |
|
97 | + foreach ($parameters as $parameterName => $parameterValue) { |
|
98 | + $formattedParameterValues = implode(', ', |
|
99 | + $this->limitArrayLength(array_map($valueFormatter, $parameterValue))); |
|
100 | + $formattedParameters[] = sprintf('%s: %s', $parameterName, $formattedParameterValues); |
|
101 | 101 | } |
102 | 102 | |
103 | - return implode( '; ', $formattedParameters ); |
|
103 | + return implode('; ', $formattedParameters); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return array |
112 | 112 | */ |
113 | - private function limitArrayLength( array $array ) { |
|
114 | - if ( count( $array ) > self::MAX_PARAMETER_ARRAY_LENGTH ) { |
|
115 | - $array = array_slice( $array, 0, self::MAX_PARAMETER_ARRAY_LENGTH ); |
|
116 | - array_push( $array, '...' ); |
|
113 | + private function limitArrayLength(array $array) { |
|
114 | + if (count($array) > self::MAX_PARAMETER_ARRAY_LENGTH) { |
|
115 | + $array = array_slice($array, 0, self::MAX_PARAMETER_ARRAY_LENGTH); |
|
116 | + array_push($array, '...'); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | return $array; |
@@ -126,12 +126,12 @@ discard block |
||
126 | 126 | * @param string $value HTML |
127 | 127 | * @return string HTML |
128 | 128 | */ |
129 | - public static function formatByRole( $role, $value ) { |
|
130 | - if ( $role === null ) { |
|
129 | + public static function formatByRole($role, $value) { |
|
130 | + if ($role === null) { |
|
131 | 131 | return $value; |
132 | 132 | } |
133 | 133 | |
134 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' |
|
134 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">' |
|
135 | 135 | . $value |
136 | 136 | . '</span>'; |
137 | 137 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @param string|null $role one of the Role constants or null |
142 | 142 | * @return string HTML |
143 | 143 | */ |
144 | - public function formatDataValue( DataValue $value, $role = null ) { |
|
145 | - return self::formatByRole( $role, |
|
146 | - $this->dataValueFormatter->format( $value ) ); |
|
144 | + public function formatDataValue(DataValue $value, $role = null) { |
|
145 | + return self::formatByRole($role, |
|
146 | + $this->dataValueFormatter->format($value)); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,9 +151,9 @@ discard block |
||
151 | 151 | * @param string|null $role one of the Role constants or null |
152 | 152 | * @return string HTML |
153 | 153 | */ |
154 | - public function formatEntityId( EntityId $entityId, $role = null ) { |
|
155 | - return self::formatByRole( $role, |
|
156 | - $this->entityIdLabelFormatter->formatEntityId( $entityId ) ); |
|
154 | + public function formatEntityId(EntityId $entityId, $role = null) { |
|
155 | + return self::formatByRole($role, |
|
156 | + $this->entityIdLabelFormatter->formatEntityId($entityId)); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -165,18 +165,18 @@ discard block |
||
165 | 165 | * @param string|null $role one of the Role constants or null |
166 | 166 | * @return string HTML |
167 | 167 | */ |
168 | - public function formatPropertyId( $propertyId, $role = null ) { |
|
169 | - if ( $propertyId instanceof PropertyId ) { |
|
170 | - return $this->formatEntityId( $propertyId, $role ); |
|
171 | - } elseif ( is_string( $propertyId ) ) { |
|
168 | + public function formatPropertyId($propertyId, $role = null) { |
|
169 | + if ($propertyId instanceof PropertyId) { |
|
170 | + return $this->formatEntityId($propertyId, $role); |
|
171 | + } elseif (is_string($propertyId)) { |
|
172 | 172 | try { |
173 | - return $this->formatEntityId( new PropertyId( $propertyId ), $role ); |
|
174 | - } catch ( InvalidArgumentException $e ) { |
|
175 | - return self::formatByRole( $role, |
|
176 | - htmlspecialchars( $propertyId ) ); |
|
173 | + return $this->formatEntityId(new PropertyId($propertyId), $role); |
|
174 | + } catch (InvalidArgumentException $e) { |
|
175 | + return self::formatByRole($role, |
|
176 | + htmlspecialchars($propertyId)); |
|
177 | 177 | } |
178 | 178 | } else { |
179 | - throw new InvalidArgumentException( '$propertyId must be either PropertyId or string' ); |
|
179 | + throw new InvalidArgumentException('$propertyId must be either PropertyId or string'); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
@@ -189,18 +189,18 @@ discard block |
||
189 | 189 | * @param string|null $role one of the Role constants or null |
190 | 190 | * @return string HTML |
191 | 191 | */ |
192 | - public function formatItemId( $itemId, $role = null ) { |
|
193 | - if ( $itemId instanceof ItemId ) { |
|
194 | - return $this->formatEntityId( $itemId, $role ); |
|
195 | - } elseif ( is_string( $itemId ) ) { |
|
192 | + public function formatItemId($itemId, $role = null) { |
|
193 | + if ($itemId instanceof ItemId) { |
|
194 | + return $this->formatEntityId($itemId, $role); |
|
195 | + } elseif (is_string($itemId)) { |
|
196 | 196 | try { |
197 | - return $this->formatEntityId( new ItemId( $itemId ), $role ); |
|
198 | - } catch ( InvalidArgumentException $e ) { |
|
199 | - return self::formatByRole( $role, |
|
200 | - htmlspecialchars( $itemId ) ); |
|
197 | + return $this->formatEntityId(new ItemId($itemId), $role); |
|
198 | + } catch (InvalidArgumentException $e) { |
|
199 | + return self::formatByRole($role, |
|
200 | + htmlspecialchars($itemId)); |
|
201 | 201 | } |
202 | 202 | } else { |
203 | - throw new InvalidArgumentException( '$itemId must be either ItemId or string' ); |
|
203 | + throw new InvalidArgumentException('$itemId must be either ItemId or string'); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
@@ -211,20 +211,20 @@ discard block |
||
211 | 211 | * @param string|null $role one of the Role constants or null |
212 | 212 | * @return string HTML |
213 | 213 | */ |
214 | - public function formatItemIdSnakValue( ItemIdSnakValue $value, $role = null ) { |
|
215 | - switch ( true ) { |
|
214 | + public function formatItemIdSnakValue(ItemIdSnakValue $value, $role = null) { |
|
215 | + switch (true) { |
|
216 | 216 | case $value->isValue(): |
217 | - return $this->formatEntityId( $value->getItemId(), $role ); |
|
217 | + return $this->formatEntityId($value->getItemId(), $role); |
|
218 | 218 | case $value->isSomeValue(): |
219 | - return self::formatByRole( $role, |
|
219 | + return self::formatByRole($role, |
|
220 | 220 | '<span class="wikibase-snakview-variation-somevaluesnak">' |
221 | - . wfMessage( 'wikibase-snakview-snaktypeselector-somevalue' )->escaped() |
|
222 | - . '</span>' ); |
|
221 | + . wfMessage('wikibase-snakview-snaktypeselector-somevalue')->escaped() |
|
222 | + . '</span>'); |
|
223 | 223 | case $value->isNoValue(): |
224 | - return self::formatByRole( $role, |
|
224 | + return self::formatByRole($role, |
|
225 | 225 | '<span class="wikibase-snakview-variation-novaluesnak">' |
226 | - . wfMessage( 'wikibase-snakview-snaktypeselector-novalue' )->escaped() |
|
227 | - . '</span>' ); |
|
226 | + . wfMessage('wikibase-snakview-snaktypeselector-novalue')->escaped() |
|
227 | + . '</span>'); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
@@ -238,15 +238,15 @@ discard block |
||
238 | 238 | * @param string|null $role one of the Role constants or null |
239 | 239 | * @return string[] HTML |
240 | 240 | */ |
241 | - public function formatPropertyIdList( array $propertyIds, $role = null ) { |
|
242 | - if ( empty( $propertyIds ) ) { |
|
243 | - return [ '<ul></ul>' ]; |
|
241 | + public function formatPropertyIdList(array $propertyIds, $role = null) { |
|
242 | + if (empty($propertyIds)) { |
|
243 | + return ['<ul></ul>']; |
|
244 | 244 | } |
245 | - $propertyIds = $this->limitArrayLength( $propertyIds ); |
|
246 | - $formattedPropertyIds = array_map( [ $this, "formatPropertyId" ], $propertyIds, array_fill( 0, count( $propertyIds ), $role ) ); |
|
245 | + $propertyIds = $this->limitArrayLength($propertyIds); |
|
246 | + $formattedPropertyIds = array_map([$this, "formatPropertyId"], $propertyIds, array_fill(0, count($propertyIds), $role)); |
|
247 | 247 | array_unshift( |
248 | 248 | $formattedPropertyIds, |
249 | - '<ul><li>' . implode( '</li><li>', $formattedPropertyIds ) . '</li></ul>' |
|
249 | + '<ul><li>'.implode('</li><li>', $formattedPropertyIds).'</li></ul>' |
|
250 | 250 | ); |
251 | 251 | return $formattedPropertyIds; |
252 | 252 | } |
@@ -261,15 +261,15 @@ discard block |
||
261 | 261 | * @param string|null $role one of the Role constants or null |
262 | 262 | * @return string[] HTML |
263 | 263 | */ |
264 | - public function formatItemIdList( array $itemIds, $role = null ) { |
|
265 | - if ( empty( $itemIds ) ) { |
|
266 | - return [ '<ul></ul>' ]; |
|
264 | + public function formatItemIdList(array $itemIds, $role = null) { |
|
265 | + if (empty($itemIds)) { |
|
266 | + return ['<ul></ul>']; |
|
267 | 267 | } |
268 | - $itemIds = $this->limitArrayLength( $itemIds ); |
|
269 | - $formattedItemIds = array_map( [ $this, "formatItemId" ], $itemIds, array_fill( 0, count( $itemIds ), $role ) ); |
|
268 | + $itemIds = $this->limitArrayLength($itemIds); |
|
269 | + $formattedItemIds = array_map([$this, "formatItemId"], $itemIds, array_fill(0, count($itemIds), $role)); |
|
270 | 270 | array_unshift( |
271 | 271 | $formattedItemIds, |
272 | - '<ul><li>' . implode( '</li><li>', $formattedItemIds ) . '</li></ul>' |
|
272 | + '<ul><li>'.implode('</li><li>', $formattedItemIds).'</li></ul>' |
|
273 | 273 | ); |
274 | 274 | return $formattedItemIds; |
275 | 275 | } |
@@ -284,23 +284,23 @@ discard block |
||
284 | 284 | * @param string|null $role one of the Role constants or null |
285 | 285 | * @return string[] HTML |
286 | 286 | */ |
287 | - public function formatEntityIdList( array $entityIds, $role = null ) { |
|
288 | - if ( empty( $entityIds ) ) { |
|
289 | - return [ '<ul></ul>' ]; |
|
287 | + public function formatEntityIdList(array $entityIds, $role = null) { |
|
288 | + if (empty($entityIds)) { |
|
289 | + return ['<ul></ul>']; |
|
290 | 290 | } |
291 | 291 | $formattedEntityIds = []; |
292 | - foreach ( $entityIds as $entityId ) { |
|
293 | - if ( count( $formattedEntityIds ) >= self::MAX_PARAMETER_ARRAY_LENGTH ) { |
|
292 | + foreach ($entityIds as $entityId) { |
|
293 | + if (count($formattedEntityIds) >= self::MAX_PARAMETER_ARRAY_LENGTH) { |
|
294 | 294 | $formattedEntityIds[] = '...'; |
295 | 295 | break; |
296 | 296 | } |
297 | - if ( $entityId !== null ) { |
|
298 | - $formattedEntityIds[] = $this->formatEntityId( $entityId, $role ); |
|
297 | + if ($entityId !== null) { |
|
298 | + $formattedEntityIds[] = $this->formatEntityId($entityId, $role); |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | array_unshift( |
302 | 302 | $formattedEntityIds, |
303 | - '<ul><li>' . implode( '</li><li>', $formattedEntityIds ) . '</li></ul>' |
|
303 | + '<ul><li>'.implode('</li><li>', $formattedEntityIds).'</li></ul>' |
|
304 | 304 | ); |
305 | 305 | return $formattedEntityIds; |
306 | 306 | } |
@@ -315,24 +315,24 @@ discard block |
||
315 | 315 | * @param string|null $role one of the Role constants or null |
316 | 316 | * @return string[] HTML |
317 | 317 | */ |
318 | - public function formatItemIdSnakValueList( array $values, $role = null ) { |
|
319 | - if ( empty( $values ) ) { |
|
320 | - return [ '<ul></ul>' ]; |
|
318 | + public function formatItemIdSnakValueList(array $values, $role = null) { |
|
319 | + if (empty($values)) { |
|
320 | + return ['<ul></ul>']; |
|
321 | 321 | } |
322 | - $values = $this->limitArrayLength( $values ); |
|
322 | + $values = $this->limitArrayLength($values); |
|
323 | 323 | $formattedValues = array_map( |
324 | - function( $value ) use ( $role ) { |
|
325 | - if ( $value === '...' ) { |
|
324 | + function($value) use ($role) { |
|
325 | + if ($value === '...') { |
|
326 | 326 | return '...'; |
327 | 327 | } else { |
328 | - return $this->formatItemIdSnakValue( $value, $role ); |
|
328 | + return $this->formatItemIdSnakValue($value, $role); |
|
329 | 329 | } |
330 | 330 | }, |
331 | 331 | $values |
332 | 332 | ); |
333 | 333 | array_unshift( |
334 | 334 | $formattedValues, |
335 | - '<ul><li>' . implode( '</li><li>', $formattedValues ) . '</li></ul>' |
|
335 | + '<ul><li>'.implode('</li><li>', $formattedValues).'</li></ul>' |
|
336 | 336 | ); |
337 | 337 | return $formattedValues; |
338 | 338 | } |
@@ -72,7 +72,7 @@ |
||
72 | 72 | * @codeCoverageIgnore |
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 | } |