<commit_before><?php
namespace EngineWorks\DBAL\Traits;

use EngineWorks\DBAL\CommonTypes;
use EngineWorks\DBAL\Internal\NumericParser;

trait MethodSqlQuote
{
    /**
     * @param mixed $value
     * @param bool $asInteger
     * @return string
     */
    private function sqlQuoteParseNumber($value, $asInteger = true)
    {
        return (new NumericParser())->parseAsEnglish($value, $asInteger);
    }

    public function sqlQuote($variable, $commonType = CommonTypes::TTEXT, $includeNull = false)
    {
        if ($includeNull && is_null($variable)) {
            return 'NULL';
        }
        switch (strtoupper($commonType)) {
            case CommonTypes::TINT:
                return $this->sqlQuoteParseNumber($variable, true);
            case CommonTypes::TNUMBER:
                return $this->sqlQuoteParseNumber($variable, false);
            case CommonTypes::TBOOL:
                return ($variable) ? '1' : '0';
            case CommonTypes::TDATE:
                return "'" . date('Y-m-d', intval($variable, 10)) . "'";
            case CommonTypes::TTIME:
                return "'" . date('H:i:s', intval($variable, 10)) . "'";
            case CommonTypes::TDATETIME:
                return "'" . date('Y-m-d H:i:s', intval($variable, 10)) . "'";
            default:
                return "'" . $this->sqlString($variable) . "'";
        }
    }
}
<commit_msg>Refactor to if instead of switch case<commit_after><?php
namespace EngineWorks\DBAL\Traits;

use EngineWorks\DBAL\CommonTypes;
use EngineWorks\DBAL\Internal\NumericParser;

trait MethodSqlQuote
{
    /**
     * @param mixed $value
     * @param bool $asInteger
     * @return string
     */
    private function sqlQuoteParseNumber($value, $asInteger = true)
    {
        return (new NumericParser())->parseAsEnglish($value, $asInteger);
    }

    public function sqlQuote($variable, $commonType = CommonTypes::TTEXT, $includeNull = false)
    {
        if ($includeNull && null === $variable) {
            return 'NULL';
        }
        // CommonTypes::TTEXT is here because is the most common used type
        if ($commonType === CommonTypes::TTEXT) {
            return "'" . $this->sqlString($variable) . "'";
        }
        if ($commonType === CommonTypes::TINT) {
            return $this->sqlQuoteParseNumber($variable, true);
        }
        if ($commonType === CommonTypes::TNUMBER) {
            return $this->sqlQuoteParseNumber($variable, false);
        }
        if ($commonType === CommonTypes::TBOOL) {
            return ($variable) ? '1' : '0';
        }
        if ($commonType === CommonTypes::TDATE) {
            return "'" . date('Y-m-d', (int) $variable) . "'";
        }
        if ($commonType === CommonTypes::TTIME) {
            return "'" . date('H:i:s', intval($variable, 10)) . "'";
        }
        if ($commonType === CommonTypes::TDATETIME) {
            return "'" . date('Y-m-d H:i:s', intval($variable, 10)) . "'";
        }
        return "'" . $this->sqlString($variable) . "'";
    }
    }
}

{'fraction_non_alphanumeric': 0.15597235932872655, 'fraction_numerical': 0.004606778545574202, 'mean_word_length': 2.237486687965921, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '791459', 'n_tokens_mistral': 917, 'n_tokens_neox': 885, 'n_words': 181}