Conditions | 11 |
Paths | 35 |
Total Lines | 52 |
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 |
||
83 | public function handleError($level, $message, $file = null, $line = null) { |
||
84 | |||
85 | // Handle all fatals, exceptions etc. |
||
86 | if(in_array( |
||
87 | $level, |
||
88 | [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR] |
||
89 | )) { |
||
90 | $this->run->handleError($level, $message, $file, $line); |
||
91 | return false; |
||
92 | } |
||
93 | |||
94 | // If All Notices and Warnings should be skipped, then short-circuit |
||
95 | // error handler. |
||
96 | if($this->skipAllNoticesAndWarnings) { |
||
97 | return false; |
||
98 | } |
||
99 | |||
100 | // Watch for all plugins and Themes |
||
101 | if( empty($this->watchSpecificPlugins) && empty($this->watchSpecificThemes ) ) { |
||
102 | $this->run->handleError($level, $message, $file, $line); |
||
103 | return false; |
||
104 | } |
||
105 | |||
106 | $watchablePlugins = empty($this->watchSpecificPlugins) ? [] : array_map(function($pluginBaseFolder){ |
||
107 | return 'plugins/' . $pluginBaseFolder; |
||
108 | }, $this->watchSpecificPlugins); |
||
109 | |||
110 | $watchableThemes = empty($this->watchSpecificThemes) ? [] : array_map(function($themeBaseFolder){ |
||
111 | return 'themes/' . $themeBaseFolder; |
||
112 | }, $this->watchSpecificThemes); |
||
113 | |||
114 | $directoriesToWatchFor = array_merge($watchablePlugins, $watchableThemes); |
||
115 | $errorBelongsToWatchCriteria = false; |
||
116 | |||
117 | // We are creating an exception object because Inspector Class needs it. |
||
118 | $exception = new ErrorException($message, /*code*/ $level, /*severity*/ $level, $file, $line); |
||
119 | $frames = (new Inspector($exception))->getFrames(); |
||
|
|||
120 | foreach( $frames as $frame ) { |
||
121 | foreach($directoriesToWatchFor as $directory) { |
||
122 | if (strpos($frame->getFile(), $directory) !== false) { |
||
123 | $errorBelongsToWatchCriteria = true; |
||
124 | break 2; |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | |||
129 | if($errorBelongsToWatchCriteria) { |
||
130 | $this->run->handleError($level, $message, $file, $line); |
||
131 | } |
||
132 | |||
133 | return false; |
||
134 | } |
||
135 | } |
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: