| Conditions | 12 |
| Paths | 24 |
| Total Lines | 49 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 25 |
| CRAP Score | 12.1769 |
| 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 |
||
| 82 | 228 | public static function export($var, int $maxDepth) |
|
| 83 | { |
||
| 84 | 228 | $return = null; |
|
| 85 | 228 | $isObj = is_object($var); |
|
| 86 | |||
| 87 | 228 | if ($var instanceof Collection) { |
|
| 88 | $var = $var->toArray(); |
||
| 89 | } |
||
| 90 | |||
| 91 | 228 | if ($maxDepth === 0) { |
|
| 92 | 38 | return is_object($var) ? get_class($var) |
|
| 93 | 38 | : (is_array($var) ? 'Array(' . count($var) . ')' : $var); |
|
| 94 | } |
||
| 95 | |||
| 96 | 228 | if (is_array($var)) { |
|
| 97 | 76 | $return = []; |
|
| 98 | |||
| 99 | 76 | foreach ($var as $k => $v) { |
|
| 100 | 76 | $return[$k] = self::export($v, $maxDepth - 1); |
|
| 101 | } |
||
| 102 | |||
| 103 | 76 | return $return; |
|
| 104 | } |
||
| 105 | |||
| 106 | 228 | if (! $isObj) { |
|
| 107 | 171 | return $var; |
|
| 108 | } |
||
| 109 | |||
| 110 | 152 | $return = new stdClass(); |
|
| 111 | 152 | if ($var instanceof DateTimeInterface) { |
|
| 112 | 57 | $return->__CLASS__ = get_class($var); |
|
| 113 | 57 | $return->date = $var->format('c'); |
|
| 114 | 57 | $return->timezone = $var->getTimezone()->getName(); |
|
| 115 | |||
| 116 | 57 | return $return; |
|
| 117 | } |
||
| 118 | |||
| 119 | 95 | $return->__CLASS__ = self::getClass($var); |
|
| 120 | |||
| 121 | 95 | if ($var instanceof Proxy) { |
|
| 122 | $return->__IS_PROXY__ = true; |
||
| 123 | $return->__PROXY_INITIALIZED__ = $var->__isInitialized(); |
||
| 124 | } |
||
| 125 | |||
| 126 | 95 | if ($var instanceof ArrayObject || $var instanceof ArrayIterator) { |
|
| 127 | 19 | $return->__STORAGE__ = self::export($var->getArrayCopy(), $maxDepth - 1); |
|
| 128 | } |
||
| 129 | |||
| 130 | 95 | return self::fillReturnWithClassAttributes($var, $return, $maxDepth); |
|
|
1 ignored issue
–
show
|
|||
| 131 | } |
||
| 178 |