<commit_before><?php

use \Slim\Http\Response as Response;


class myexception extends Exception {

    const REDIRECT     = 101;
    const MESSAGE      = 102;
    const AJAXWARNING  = 103;
    const NOTFOUND     = 104;
    const RATELIMIT    = 105;
    const STOP         = 106;
    const REDIRECTOK   = 107;

    public function __construct( $code, $message = '' ) {
        $this->code    = $code;
        $this->message = $message;
    }

    public static function response( $code, $message, Response $response, $container ){

        /** @var abContainer $container */

        // check debug mode
        if( isset( $container->config[ 'app.debug' ] ) && $container->config[ 'app.debug' ] === true ) {
            $response = $response->withAddedHeader('X-myfw-page', sprintf("%.3f", defined('APP_START' ) ? (float)microtime(true) - APP_START : 0 ) );
            $response = $response->withAddedHeader('X-myfw-db', $container->db->getDebugsCounter() );
        }

        switch( $code ){
            case myexception::REDIRECT:
            case myexception::REDIRECTOK:

                if( $container->isajax ) {
                    return $response->withJson( $container->ajax->redirect( $message, '', 1000, $code == myexception::REDIRECTOK )
                                                          ->obj() );
                }else {
                    return $response->withRedirect( $message );
                }
                break;

            case myexception::AJAXWARNING:
                if( $container->isajax ) {
                    return $response->withJson( $container->ajax->msgWarning( $message )
                                                                ->obj() );
                }else{
                    return $response;
                }
                break;

            case myexception::NOTFOUND:
                return $response->withStatus(404 )
                                ->withHeader('Content-Type', 'text/html')
                                ->write('Page not found' );
                break;

            case myexception::RATELIMIT:
                if( $container->isajax ) {
                    return $response->withJson( $container->ajax->msgWarning( $message )
                                                                ->obj() );
                }else {
                    return $response->withStatus(429)
                                    ->withHeader('Content-Type', 'text/html')
                                    ->write( $message );
                }
                break;

            case myexception::STOP:
                if( $container->isajax ) {
                    return $response->withJson( $container->ajax->obj() );
                }else {
                    return $response->withHeader('Content-Type', 'text/html')
                                    ->write($message);
                }
                break;
        }

        return false;
    }
}<commit_msg>porting<commit_after><?php

use \Slim\Http\Response as Response;


class myexception extends Exception {

    const REDIRECT     = 101;
    const MESSAGE      = 102;
    const AJAXWARNING  = 103;
    const NOTFOUND     = 104;
    const RATELIMIT    = 105;
    const STOP         = 106;
    const REDIRECTOK   = 107;

    public function __construct( $code, $message = '' ) {
        $this->code    = $code;
        $this->message = $message;
    }

    public static function response( $code, $message, Response $response, $container ){

        /** @var abContainer $container */

        // check debug mode
        if( isset( $container->config[ 'app.debug' ] ) && $container->config[ 'app.debug' ] === true ) {
            $response = $response->withAddedHeader('X-myfw-page', sprintf("%.3f", defined('APP_START' ) ? (float)microtime(true) - APP_START : 0 ) );
            $response = $response->withAddedHeader('X-myfw-db', $container->db->getDebugsCounter() );
        }

        switch( $code ){
            case myexception::REDIRECT:
            case myexception::REDIRECTOK:

                if( $container->isajax ) {
                    return $response->withJson( $container->ajax->redirect( $message, '', 1000, $code == myexception::REDIRECTOK )
                                                          ->obj() );
                }else {
                    return $response->withRedirect( $message );
                }
                break;

            case myexception::AJAXWARNING:
                if( $container->isajax ) {
                    return $response->withJson( $container->ajax->msgWarning( $message )
                                                                ->obj() );
                }else{
                    return $response;
                }
                break;

            case myexception::NOTFOUND:
                return $response->withStatus(404 )
                                ->withHeader('Content-Type', 'text/html')
                                ->write('Page not found' );
                break;

            case myexception::RATELIMIT:
                if( $container->isajax ) {
                    return $response->withJson( $container->ajax->msgWarning( $message )
                                                                ->obj() );
                }else {
                    return $response->withStatus(429)
                                    ->withHeader('Content-Type', 'text/html')
                                    ->write( $message );
                }
                break;

            case myexception::STOP:
                if( $container->isajax ) {
                    return $response->withJson( $container->ajax->msgError( $message )
                                                                ->obj() );
                }else {
                    return $response->withHeader('Content-Type', 'text/html')
                                    ->write($message);
                }
                break;
        }

        return false;
    }
}
{'fraction_non_alphanumeric': 0.12039966694421315, 'fraction_numerical': 0.010990840965861781, 'mean_word_length': 1.1943734015345269, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3784746', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1402, 'n_words': 296}