<commit_before><?php

namespace lb\applications\swoole;

use lb\components\error_handlers\HttpException;
use lb\components\error_handlers\ParamException;
use lb\components\error_handlers\VariableException;
use lb\Lb;
use lb\SwooleLb;
use Monolog\Logger;

class App extends SwooleLb
{
    protected function handleException($exception)
    {
        Lb::app()->log($exception->getTraceAsString(), [], Logger::ERROR);
        $status_code = $exception->getCode();
        Lb::app()->redirect(Lb::app()->createAbsoluteUrl('/web/action/error', [
            'err_msg' => implode(':', [$status_code, $exception->getMessage()]),
            'tpl_name' => 'error',
            'status_code' => $status_code
        ]));
    }

    protected function exitException(\Exception $exception)
    {
        Lb::app()->log($exception->getTraceAsString(), [], Logger::ERROR);
        $this->response->getSwooleResponse()->end(implode(':', [$exception->getCode(), $exception->getMessage()]));
    }

    public function run()
    {
        if (strtolower(php_sapi_name()) === 'cli') {
            // Start App
            if (class_exists('\Throwable')) {
                // if php version >= 7.0.0
                try {
                    parent::run();
                } catch (HttpException $httpException) {
                    $this->handleException($httpException);
                } catch (VariableException $variableException) {
                    $this->exitException($variableException);
                } catch (ParamException $paramException) {
                    $this->exitException($paramException);
                } catch (\Throwable $throwable) {
                    $this->handleException($throwable);
                }
            } else {
                // if php version < 7.0.0
                try {
                    parent::run();
                } catch (HttpException $httpException) {
                    $this->handleException($httpException);
                } catch (VariableException $variableException) {
                    $this->exitException($variableException);
                } catch (ParamException $paramException) {
                    $this->exitException($paramException);
                } catch (\Exception $e) {
                    $this->handleException($e);
                }
            }
        } else {
            $this->response->getSwooleResponse()->end('Unsupported running mode.');
        }
    }
}
<commit_msg>refactor<commit_after><?php

namespace lb\applications\swoole;

use lb\components\error_handlers\HttpException;
use lb\components\error_handlers\ParamException;
use lb\components\error_handlers\VariableException;
use lb\Lb;
use lb\SwooleLb;
use Monolog\Logger;

class App extends SwooleLb
{
    protected function handleException($exception)
    {
        Lb::app()->error($exception->getTraceAsString());
        $status_code = $exception->getCode();
        Lb::app()->redirect(Lb::app()->createAbsoluteUrl('/web/action/error', [
            'err_msg' => implode(':', [$status_code, $exception->getMessage()]),
            'tpl_name' => 'error',
            'status_code' => $status_code
        ]));
    }

    protected function exitException(\Exception $exception)
    {
        Lb::app()->error($exception->getTraceAsString());
        $this->response->getSwooleResponse()->end(implode(':', [$exception->getCode(), $exception->getMessage()]));
    }

    public function run()
    {
        if (strtolower(php_sapi_name()) === 'cli') {
            // Start App
            if (class_exists('\Throwable')) {
                // if php version >= 7.0.0
                try {
                    parent::run();
                } catch (HttpException $httpException) {
                    $this->handleException($httpException);
                } catch (VariableException $variableException) {
                    $this->exitException($variableException);
                } catch (ParamException $paramException) {
                    $this->exitException($paramException);
                } catch (\Throwable $throwable) {
                    $this->handleException($throwable);
                }
            } else {
                // if php version < 7.0.0
                try {
                    parent::run();
                } catch (HttpException $httpException) {
                    $this->handleException($httpException);
                } catch (VariableException $variableException) {
                    $this->exitException($variableException);
                } catch (ParamException $paramException) {
                    $this->exitException($paramException);
                } catch (\Exception $e) {
                    $this->handleException($e);
                }
            }
        } else {
            $this->response->getSwooleResponse()->end('Unsupported running mode.');
        }
    }
}

{'fraction_non_alphanumeric': 0.13884906819578127, 'fraction_numerical': 0.0024575056317837395, 'mean_word_length': 1.9054134443783461, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5256944', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1231, 'n_words': 204}