| Conditions | 8 |
| Paths | 40 |
| Total Lines | 55 |
| Code Lines | 39 |
| 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 |
||
| 86 | private function resolveMagicConstants(IFunctionDeclaration $declaration) |
||
| 87 | { |
||
| 88 | $reflection = $this->innerReflection; |
||
| 89 | $__FILE__ = $this->location->getFilePath(); |
||
| 90 | $__DIR__ = dirname($__FILE__); |
||
| 91 | $__NAMESPACE__ = $declaration->getNamespace() ?: ''; |
||
| 92 | $__TRAIT__ = ''; |
||
| 93 | $namespacePrefix = $__NAMESPACE__ === '' ? '' : $__NAMESPACE__ . '\\'; |
||
| 94 | |||
| 95 | if ($declaration->isWithinClass()) { |
||
| 96 | $__CLASS__ = $namespacePrefix . $declaration->getClass(); |
||
| 97 | $declarationType = $__CLASS__; |
||
| 98 | } elseif ($declaration->isWithinTrait()) { |
||
| 99 | $__TRAIT__ = $namespacePrefix . $declaration->getTrait(); |
||
| 100 | $declarationType = $__TRAIT__; |
||
| 101 | |||
| 102 | //If the function is method declared within a trait the __CLASS__ constant |
||
| 103 | //is programmed to be the class in which the trait is used in: https://bugs.php.net/bug.php?id=55214&edit=1 |
||
| 104 | //ReflectionMethod::getDeclaringClass() will resolve this. |
||
| 105 | if ($reflection instanceof \ReflectionMethod) { |
||
| 106 | $__CLASS__ = $reflection->getDeclaringClass()->getName(); |
||
|
|
|||
| 107 | } |
||
| 108 | //Else the function must be a closure declared in a trait, __CLASS__ will resolve to |
||
| 109 | //the scoped class e.g. get_called_class(). |
||
| 110 | else { |
||
| 111 | $__CLASS__ = $this->scope->getScopeType() ?: ''; |
||
| 112 | } |
||
| 113 | } else { |
||
| 114 | $__CLASS__ = ''; |
||
| 115 | $__TRAIT__ = ''; |
||
| 116 | $declarationType = null; |
||
| 117 | } |
||
| 118 | |||
| 119 | $__FUNCTION__ = $reflection->getName(); |
||
| 120 | $__FUNCTION__WithinClosure = $namespacePrefix . '{closure}'; |
||
| 121 | if ($declarationType === null) { |
||
| 122 | $__METHOD__ = $__FUNCTION__; |
||
| 123 | $__METHOD__WithinClosure = $__FUNCTION__WithinClosure; |
||
| 124 | } //__METHOD__ always uses declaration type |
||
| 125 | else { |
||
| 126 | $__METHOD__ = $declarationType . '::' . $__FUNCTION__; |
||
| 127 | $__METHOD__WithinClosure = $declarationType . '::' . $__FUNCTION__WithinClosure; |
||
| 128 | } |
||
| 129 | |||
| 130 | return new MagicConstants( |
||
| 131 | $__DIR__, |
||
| 132 | $__FILE__, |
||
| 133 | $__NAMESPACE__, |
||
| 134 | $__CLASS__, |
||
| 135 | $__TRAIT__, |
||
| 136 | $__FUNCTION__, |
||
| 137 | $__FUNCTION__WithinClosure, |
||
| 138 | $__METHOD__, |
||
| 139 | $__METHOD__WithinClosure); |
||
| 140 | } |
||
| 141 | |||
| 192 |