<commit_before><?php
/**
 * NoFramework
 *
 * @author <NAME> <<EMAIL>>
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 * @link http://noframework.com
 */

namespace NoFramework\Error;

class Handler
{
    protected $error_types = -1;
    protected $is_preload_exception = true;

    public function __construct($error_types = false)
    {
        if (false !== $error_types) {
            $this->error_types = $error_types;
        }
    }

    public function getErrorClass()
    {
        $return = [];

        foreach ([
            E_USER_ERROR => 'Recoverable',
            E_RECOVERABLE_ERROR => 'Recoverable',
            E_USER_WARNING => 'Warning',
            E_WARNING => 'Warning',
            E_USER_NOTICE => 'Notice',
            E_NOTICE => 'Notice',
            E_STRICT => 'Strict',
            E_USER_DEPRECATED => 'Deprecated',
            E_DEPRECATED => 'Deprecated'
        ] as $errno => $errclass) {
            $return[$errno] = __NAMESPACE__ . '\Exception\\' . $errclass;
        }

        return $return;
    }

    public function __invoke($errno, $errstr, $errfile, $errline, $errcontext)
    {
        if (0 !== error_reporting()) {
            $class = $this->getErrorClass()[$errno];
            throw new $class($errno, $errstr, $errfile, $errline, $errcontext);
        }

        return true;
    }

    public function register()
    {
        if ($this->is_preload_exception) {
            foreach (array_unique($this->getErrorClass()) as $class) {
                spl_autoload_call($class);
            }
        }

        return set_error_handler($this, $this->error_types);
    }

    public static function restorePrevious()
    {
        return restore_error_handler();
    }

    public static function restoreBuiltin()
    {
        return set_error_handler(null);
    }
}

<commit_msg>refactored and simplified error handler<commit_after><?php
/**
 * NoFramework
 *
 * @author <NAME> <<EMAIL>>
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 * @link http://noframework.com
 */

namespace NoFramework;

class ErrorHandler
{
    protected $error_types = -1;

    const ERROR = 5;
    const WARNING = 4;
    const NOTICE = 3;
    const STRICT = 2;
    const DEPRECATED = 1;

    public function __construct($error_types = -1)
    {
        $this->error_types = $this->error_types;
    }

    public function __invoke($errno, $errstr, $errfile, $errline)
    {
        if (0 !== error_reporting()) { // respect @
            $severity = [
                E_RECOVERABLE_ERROR => [self::ERROR, 'Error'],
                E_USER_ERROR => [self::ERROR, 'Error'],
                E_WARNING => [self::WARNING, 'Warning'],
                E_USER_WARNING => [self::WARNING, 'Warning'],
                E_NOTICE => [self::NOTICE, 'Notice'],
                E_USER_NOTICE => [self::NOTICE, 'Notice'],
                E_STRICT => [self::STRICT, 'Strict'],
                E_DEPRECATED => [self::DEPRECATED, 'Deprecated'],
                E_USER_DEPRECATED => [self::DEPRECATED, 'Deprecated'],
            ][$errno];

            throw new \ErrorException(
                sprintf('[%s] %s', $severity[1], $errstr),
                $errno,
                $severity[0],
                $errfile,
                $errline
            );
        }

        return true;
    }

    public function register()
    {
        set_error_handler($this, $this->error_types);

        return $this;
    }
}


{'fraction_non_alphanumeric': 0.1371757925072046, 'fraction_numerical': 0.00345821325648415, 'mean_word_length': 1.9896640826873384, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5583119', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1028, 'n_words': 208}