Conditions | 15 |
Paths | 3 |
Total Lines | 32 |
Code Lines | 22 |
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 | $res .= "defined('$key') or define('$key', $var);\n"; |
||
18 | } |
||
19 | |||
20 | return $res; |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * Returns PHP-executable string representation of given value. |
||
25 | * Uses Riimu/Kit-PHPEncoder based `var_export` alternative. |
||
26 | * And Opis/Closure to dump closures as PHP code. |
||
27 | * @param mixed $value |
||
28 | * @return string |
||
29 | * @throws \ReflectionException |
||
30 | */ |
||
31 | public static function exportVar($value): string |
||
32 | { |
||
33 | return static::getEncoder()->encode($value); |
||
34 | } |
||
35 | |||
36 | private static $encoder; |
||
37 | |||
38 | private static function getEncoder() |
||
39 | { |
||
40 | if (self::$encoder === null) { |
||
41 | self::$encoder = static::createEncoder(); |
||
42 | } |
||
43 | |||
44 | return self::$encoder; |
||
45 | } |
||
46 | |||
47 | private static function createEncoder() |
||
48 | { |
||
49 | $encoder = new PHPEncoder([ |
||
57 |