Conditions | 7 |
Paths | 6 |
Total Lines | 69 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
122 | public function handleChange( EntityChange $change, array $rootJobParams = [] ) { |
||
123 | $changeId = $this->getChangeIdForLog( $change ); |
||
124 | |||
125 | $this->logger->debug( |
||
126 | '{method}: handling change #{changeId} ({changeType})', |
||
127 | [ |
||
128 | 'method' => __METHOD__, |
||
129 | 'changeId' => $changeId, |
||
130 | 'changeType' => $change->getType(), |
||
131 | ] |
||
132 | ); |
||
133 | |||
134 | $usagesPerPage = $this->affectedPagesFinder->getAffectedUsagesByPage( $change ); |
||
135 | |||
136 | $this->logger->debug( |
||
137 | '{method}: updating {pageCount} page(s) for change #{changeId}.', |
||
138 | [ |
||
139 | 'method' => __METHOD__, |
||
140 | 'changeId' => $changeId, |
||
141 | 'pageCount' => count( $usagesPerPage ), |
||
142 | ] |
||
143 | ); |
||
144 | |||
145 | // if no usages we can abort early |
||
146 | if ( $usagesPerPage === [] ) { |
||
147 | return; |
||
148 | } |
||
149 | |||
150 | // Run all updates on all affected pages |
||
151 | $titlesToUpdate = $this->getTitlesForUsages( $usagesPerPage ); |
||
152 | |||
153 | // if no titles we can abort early |
||
154 | if ( $titlesToUpdate === [] ) { |
||
155 | return; |
||
156 | } |
||
157 | |||
158 | // NOTE: deduplicate |
||
159 | $titleBatchSignature = $this->getTitleBatchSignature( $titlesToUpdate ); |
||
160 | $rootJobParams['rootJobSignature'] = $titleBatchSignature; |
||
161 | |||
162 | if ( !isset( $rootJobParams['rootJobTimestamp'] ) ) { |
||
163 | $rootJobParams['rootJobTimestamp'] = wfTimestampNow(); |
||
164 | } |
||
165 | |||
166 | $this->updater->purgeWebCache( |
||
167 | $titlesToUpdate, |
||
168 | $rootJobParams, |
||
169 | $change->getAction(), |
||
170 | $change->hasField( 'user_id' ) ? 'uid:' . $change->getUserId() : 'uid:?' |
||
171 | ); |
||
172 | |||
173 | // Removing root job timestamp to make it work: T233520 |
||
174 | $refreshLinksRootParams = $rootJobParams; |
||
175 | unset( $refreshLinksRootParams['rootJobTimestamp'] ); |
||
176 | |||
177 | $this->updater->scheduleRefreshLinks( |
||
178 | $titlesToUpdate, |
||
179 | $refreshLinksRootParams, |
||
180 | $change->getAction(), |
||
181 | 'uid:' . ( $change->getUserId() ?: '?' ) |
||
182 | ); |
||
183 | |||
184 | // NOTE: signature depends on change ID, effectively disabling deduplication |
||
185 | $changeSignature = $this->getChangeSignature( $change ); |
||
186 | $rootJobParams['rootJobSignature'] = $titleBatchSignature . '&' . $changeSignature; |
||
187 | if ( $this->injectRecentChanges ) { |
||
188 | $this->updater->injectRCRecords( $titlesToUpdate, $change, $rootJobParams ); |
||
189 | } |
||
190 | } |
||
191 | |||
269 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: