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