| Conditions | 11 |
| Paths | 192 |
| Total Lines | 108 |
| Code Lines | 49 |
| 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 |
||
| 113 | public function setErrorHandler($errNo=null, $errStr=null, $errFile=null, $errLine=null, $errContext=null) |
||
| 114 | {
|
||
| 115 | // in case of a deficiency, |
||
| 116 | // we need to boot our general needs to be needed for the exception. |
||
| 117 | Dependencies::loadBootstrapperNeedsForException(); |
||
| 118 | |||
| 119 | // in general we will use the exception class |
||
| 120 | // in the store/config directory to make it possible |
||
| 121 | // to change the user-based exceptions. |
||
| 122 | $this->data['exception'] = $this->exception; |
||
| 123 | |||
| 124 | //constant object as default |
||
| 125 | $this->data['errType'] = 'Undefined'; |
||
| 126 | $this->data['errStrReal'] = $errStr; |
||
| 127 | $this->data['errorClassNamespace'] = null; |
||
| 128 | $this->data['errFile'] = $errFile; |
||
| 129 | $this->data['errLine'] = $errLine; |
||
| 130 | $this->data['errNo'] = $errNo; |
||
| 131 | |||
| 132 | // catch exception via preg match |
||
| 133 | // and then clear the Uncaught statement from inside. |
||
| 134 | $this->getUncaughtProcess(); |
||
| 135 | |||
| 136 | $this->getStatusFromContext(); |
||
| 137 | |||
| 138 | if(is_array($meta=config('response.meta'))){
|
||
| 139 | |||
| 140 | //set as the success object is false |
||
| 141 | $this->data['appExceptionSuccess']=[]; |
||
| 142 | } |
||
| 143 | else{
|
||
| 144 | |||
| 145 | //set as the success object is false |
||
| 146 | $this->data['appExceptionSuccess']=['success'=>(bool)false,'status'=>$this->data['status']]; |
||
| 147 | } |
||
| 148 | |||
| 149 | //get lang message for exception |
||
| 150 | $this->getLangMessageForException(); |
||
| 151 | |||
| 152 | if(property_exists(core(),'exceptiontrace')){
|
||
| 153 | |||
| 154 | $customExceptionTrace=core()->exceptiontrace; |
||
| 155 | $this->data['errFile']=$customExceptionTrace['file']; |
||
| 156 | $this->data['errLine']=$customExceptionTrace['line']; |
||
| 157 | } |
||
| 158 | |||
| 159 | $environment = $this->getEnvironmentStatus(); |
||
| 160 | |||
| 161 | $vendorDirectory = str_replace(root.''.DIRECTORY_SEPARATOR.'','',$this->data['errFile']); |
||
| 162 | |||
| 163 | if(Str::startsWith($vendorDirectory,'vendor') |
||
| 164 | && Str::startsWith($vendorDirectory,'vendor/php-resta')===false) |
||
| 165 | {
|
||
| 166 | $externalMessage = ($environment==="production") ? |
||
| 167 | 'An unexpected external error has occurred' : |
||
| 168 | $this->data['errStrReal']; |
||
| 169 | |||
| 170 | $appException=$this->getAppException($environment,$externalMessage); |
||
| 171 | |||
| 172 | |||
| 173 | //Get or Set the HTTP response code |
||
| 174 | http_response_code(500); |
||
| 175 | $this->app->terminate('responseStatus');
|
||
| 176 | $this->app->register('responseStatus',500);
|
||
| 177 | |||
| 178 | |||
| 179 | } |
||
| 180 | else{
|
||
| 181 | |||
| 182 | $appException=$this->getAppException($environment,$this->data['errStrReal']); |
||
| 183 | |||
| 184 | //Get or Set the HTTP response code |
||
| 185 | http_response_code($this->data['status']); |
||
| 186 | } |
||
| 187 | |||
| 188 | |||
| 189 | if($environment==="production"){
|
||
| 190 | |||
| 191 | $productionLogMessage = $this->getAppException('local',$this->data['errStrReal']);
|
||
| 192 | $this->app->register('productionLogMessage',core()->out->outputFormatter($productionLogMessage));
|
||
| 193 | } |
||
| 194 | |||
| 195 | if(app()->has('requestExpected') && config('app.requestWithError')===true){
|
||
| 196 | $appException['request']['expected'] = app()->get('requestExpected');
|
||
| 197 | } |
||
| 198 | |||
| 199 | |||
| 200 | //set json app exception |
||
| 201 | core()->routerResult=$appException; |
||
| 202 | |||
| 203 | $restaOutHandle = null; |
||
| 204 | |||
| 205 | if(!defined('responseApp')){
|
||
| 206 | |||
| 207 | $restaOutHandle=core()->out->handle(); |
||
| 208 | } |
||
| 209 | |||
| 210 | if($restaOutHandle===null){
|
||
| 211 | |||
| 212 | //header set and symfony response call |
||
| 213 | header('Content-type:application/json;charset=utf-8');
|
||
| 214 | |||
| 215 | echo json_encode(core()->out->outputFormatter($appException)); |
||
| 216 | exit(); |
||
| 217 | } |
||
| 218 | else{
|
||
| 219 | echo $restaOutHandle; |
||
| 220 | exit(); |
||
| 221 | } |
||
| 364 | } |