@@ -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 | |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @throws DBUnexpectedError |
105 | 105 | */ |
106 | - public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) { |
|
107 | - $db = wfGetDB( DB_MASTER ); |
|
106 | + public function deleteForPropertyWhereConstraintIdIsStatementId(PropertyId $propertyId) { |
|
107 | + $db = wfGetDB(DB_MASTER); |
|
108 | 108 | $db->delete( |
109 | 109 | 'wbqc_constraints', |
110 | 110 | [ |
111 | 111 | 'pid' => $propertyId->getNumericId(), |
112 | 112 | // AND constraint_guid LIKE %$________-____-____-____-____________ |
113 | - 'constraint_guid ' . $db->buildLike( array_merge( [ $db->anyString(), '$' ], $this->uuidPattern( $db->anyChar() ) ) ) |
|
113 | + 'constraint_guid '.$db->buildLike(array_merge([$db->anyString(), '$'], $this->uuidPattern($db->anyChar()))) |
|
114 | 114 | ] |
115 | 115 | ); |
116 | 116 | } |
@@ -121,20 +121,20 @@ discard block |
||
121 | 121 | * @throws InvalidArgumentException |
122 | 122 | * @throws DBUnexpectedError |
123 | 123 | */ |
124 | - public function deleteAll( $batchSize = 1000 ) { |
|
125 | - if ( !is_int( $batchSize ) ) { |
|
124 | + public function deleteAll($batchSize = 1000) { |
|
125 | + if (!is_int($batchSize)) { |
|
126 | 126 | throw new InvalidArgumentException(); |
127 | 127 | } |
128 | - $db = wfGetDB( DB_MASTER ); |
|
129 | - if ( $db->getType() === 'sqlite' ) { |
|
130 | - $db->delete( 'wbqc_constraints', '*' ); |
|
128 | + $db = wfGetDB(DB_MASTER); |
|
129 | + if ($db->getType() === 'sqlite') { |
|
130 | + $db->delete('wbqc_constraints', '*'); |
|
131 | 131 | } else { |
132 | 132 | do { |
133 | - $db->commit( __METHOD__, 'flush' ); |
|
133 | + $db->commit(__METHOD__, 'flush'); |
|
134 | 134 | wfGetLBFactory()->waitForReplication(); |
135 | - $table = $db->tableName( 'wbqc_constraints' ); |
|
136 | - $db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) ); |
|
137 | - } while ( $db->affectedRows() > 0 ); |
|
135 | + $table = $db->tableName('wbqc_constraints'); |
|
136 | + $db->query(sprintf('DELETE FROM %s LIMIT %d', $table, $batchSize)); |
|
137 | + } while ($db->affectedRows() > 0); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -143,26 +143,26 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @return Constraint[] |
145 | 145 | */ |
146 | - private function convertToConstraints( IResultWrapper $results ) { |
|
146 | + private function convertToConstraints(IResultWrapper $results) { |
|
147 | 147 | $constraints = []; |
148 | - foreach ( $results as $result ) { |
|
148 | + foreach ($results as $result) { |
|
149 | 149 | $constraintTypeItemId = $result->constraint_type_qid; |
150 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
150 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
151 | 151 | |
152 | - if ( $constraintParameters === null ) { |
|
152 | + if ($constraintParameters === null) { |
|
153 | 153 | // T171295 |
154 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ) |
|
155 | - ->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
154 | + LoggerFactory::getInstance('WikibaseQualityConstraints') |
|
155 | + ->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
156 | 156 | 'method' => __METHOD__, |
157 | 157 | 'constraintId' => $result->constraint_guid, |
158 | 158 | 'constraintParameters' => $result->constraint_parameters, |
159 | - ] ); |
|
160 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
159 | + ]); |
|
160 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | $constraints[] = new Constraint( |
164 | 164 | $result->constraint_guid, |
165 | - PropertyId::newFromNumber( $result->pid ), |
|
165 | + PropertyId::newFromNumber($result->pid), |
|
166 | 166 | $constraintTypeItemId, |
167 | 167 | $constraintParameters |
168 | 168 | ); |