| Conditions | 7 |
| Paths | 10 |
| Total Lines | 73 |
| Code Lines | 34 |
| 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 function onError($errno, $errstr, $errfile, $errline) |
||
| 50 | { |
||
| 51 | if (error_reporting() == 0) { |
||
| 52 | return; |
||
| 53 | } |
||
| 54 | $php = PHP_VERSION; |
||
| 55 | $os = php_uname(); |
||
| 56 | $phpmetrics = getVersion(); |
||
| 57 | $traces = debug_backtrace(0, 10); |
||
| 58 | $trace = ''; |
||
| 59 | foreach ($traces as $c) { |
||
| 60 | if (isset($c['file'])) { |
||
| 61 | $trace .= sprintf("+ %s (line %d)\n", $c['file'], $c['line']); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | $debug = ''; |
||
| 66 | foreach ($this->debug as $key => $value) { |
||
| 67 | if ($value instanceof Node || is_array($value)) { |
||
| 68 | $value = (new Standard())->prettyPrint($value); |
||
|
|
|||
| 69 | } |
||
| 70 | |||
| 71 | $debug .= sprintf("%s: %s\n", $key, $value); |
||
| 72 | } |
||
| 73 | |||
| 74 | $logfile = './phpmetrics-error.log'; |
||
| 75 | |||
| 76 | $message = <<<EOT |
||
| 77 | |||
| 78 | <error>We're sorry : an unexpected error occured.</error> |
||
| 79 | |||
| 80 | <question>Can you help us ?</question> Please open a new issue at https://github.com/phpmetrics/PhpMetrics/issues/new, and copy-paste the content |
||
| 81 | of this file: $logfile ? |
||
| 82 | |||
| 83 | Thanks for your help :) |
||
| 84 | |||
| 85 | EOT; |
||
| 86 | |||
| 87 | $log = <<<EOT |
||
| 88 | ## Title: $errstr |
||
| 89 | |||
| 90 | ## Message: |
||
| 91 | |||
| 92 | Hi, |
||
| 93 | |||
| 94 | This issue occured: |
||
| 95 | |||
| 96 | $errstr |
||
| 97 | |||
| 98 | **Environment** |
||
| 99 | |||
| 100 | + PHP: $php |
||
| 101 | + PhpMetrics: $phpmetrics |
||
| 102 | + Operating System: $os |
||
| 103 | + File: $errfile (line $errline) |
||
| 104 | |||
| 105 | <details> |
||
| 106 | <summary>Details</summary> |
||
| 107 | ``` |
||
| 108 | $trace |
||
| 109 | |||
| 110 | |||
| 111 | $debug |
||
| 112 | ``` |
||
| 113 | </details> |
||
| 114 | |||
| 115 | EOT; |
||
| 116 | |||
| 117 | $this->output->write($message); |
||
| 118 | |||
| 119 | $this->log($logfile, $log); |
||
| 120 | $this->terminate(1); |
||
| 121 | } |
||
| 122 | |||
| 176 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: