Conditions | 13 |
Paths | 44 |
Total Lines | 18 |
Code Lines | 15 |
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 |
||
17 | public function throwMoreConcreteException(PDOException $exception) { |
||
18 | $errorInfo = $exception->errorInfo; |
||
19 | /** @link http://php.net/manual/en/class.exception.php#Hcom115813 (cHao's comment) */ |
||
20 | $code = is_array($errorInfo) && isset($errorInfo[1]) ? ((int) $errorInfo[1]) : ((int) $exception->getCode()); |
||
21 | $message = (string) $exception->getMessage(); |
||
22 | switch($code) { |
||
23 | case 2006: throw new DatabaseHasGoneAwayException($message, $code, $exception); |
||
24 | case 1213: throw new SqlDeadLockException($message, $code, $exception); |
||
25 | case 1205: throw new LockWaitTimeoutExceededException($message, $code, $exception); |
||
26 | case 1022: |
||
27 | case 1062: |
||
28 | case 1169: |
||
29 | case 1586: throw new DuplicateUniqueKeyException($message, $code, $exception); |
||
30 | case 1216: |
||
31 | case 1217: |
||
32 | case 1452: throw new IntegrityConstraintViolationException($message, $code, $exception); |
||
33 | } |
||
34 | throw new SqlException($message, $code, $exception); |
||
35 | } |
||
37 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.