| Conditions | 10 |
| Paths | 8 |
| Total Lines | 28 |
| Code Lines | 19 |
| 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 |
||
| 49 | public static function getCaller() |
||
| 50 | { |
||
| 51 | $backtraces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 7); |
||
| 52 | $nextIsCaller = false; |
||
| 53 | $caller = null; |
||
| 54 | foreach ($backtraces as $backtrace) { |
||
| 55 | if ( |
||
| 56 | isset($backtrace['file']) |
||
| 57 | && strpos($backtrace['file'], __FILE__) !== false |
||
| 58 | ) { |
||
| 59 | $nextIsCaller = true; |
||
| 60 | } elseif ( |
||
| 61 | $nextIsCaller |
||
| 62 | && ( |
||
| 63 | (isset($backtrace['file']) && strpos($backtrace['file'], __FILE__) === false) |
||
| 64 | || isset($backtrace['file']) === false |
||
| 65 | ) |
||
| 66 | ) { |
||
| 67 | $caller = $backtrace; |
||
| 68 | break; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | if ($nextIsCaller === false && count($backtraces) > 0) { |
||
| 72 | $caller = $backtraces[0]; |
||
| 73 | } |
||
| 74 | |||
| 75 | return $caller; |
||
| 76 | } |
||
| 77 | |||
| 111 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.