<commit_before><?php

namespace CarbonPHP\Programs;

use CarbonPHP\CarbonPHP;
use CarbonPHP\Error\ErrorCatcher;
use CarbonPHP\Interfaces\iColorCode;

trait ColorCode
{

    public static bool $colorCodeBool = true;

    /**
     * @param string $message
     * @param string $color
     * @param bool $exit
     * @link https://www.php.net/manual/en/function.syslog.php
     */
    public static function colorCode(string $message, string $color = iColorCode::GREEN): void
    {
        if (false === self::$colorCodeBool) {

            print $message;

            return;

        }

        $colors = iColorCode::PRINTF_ANSI_COLOR;

        if (is_string($color) && !array_key_exists($color, $colors)) {

            $message = "Color provided to color code ($color) is invalid, message caught '$message'";

            $color = iColorCode::RED;

        }

        $message = sprintf($colors[$color], $message);

        if (CarbonPHP::$test) {

            /**
             * The code below doesn't seem to hold. print is needed to pass tests
             * @link https://stackoverflow.com/questions/21784240/is-there-any-way-to-expect-output-to-error-log-in-phpunit-tests
             * @noinspection ForgottenDebugOutputInspection
             * $current = ini_set('error_log', '/dev/stdout'); // use this rather than const as const is not defined in all run time envs
             * error_log($colorCodex);
             * ini_set('error_log', $current);
             */
            print $message . PHP_EOL;

            return;
        }

        /** @noinspection ForgottenDebugOutputInspection */
        error_log($message);    // do not double quote args passed here

        if (null === ErrorCatcher::$defaultLocation || '' === ErrorCatcher::$defaultLocation) {

            return;

        }

        $location = ini_get('error_log');

        if (false === touch(ErrorCatcher::$defaultLocation)) {

            $message .= "\n\nThe error log path (" . ErrorCatcher::$defaultLocation . ') might not exist on the system. Please create any nessicary directories to store logs correctly!' . PHP_EOL;

        }

        switch ($location) {
            case '':<commit_msg>updated color code<commit_after><?php

namespace CarbonPHP\Programs;

use CarbonPHP\CarbonPHP;
use CarbonPHP\Error\ErrorCatcher;
use CarbonPHP\Interfaces\iColorCode;

trait ColorCode
{

    public static bool $colorCodeBool = true;

    /**
     * @param string $message
     * @param string $color
     * @param bool $exit
     * @link https://www.php.net/manual/en/function.syslog.php
     */
    public static function colorCode(string $message, string $color = iColorCode::GREEN): void
    {
        if (false === self::$colorCodeBool) {

            print $message;

            return;

        }

        $colors = iColorCode::PRINTF_ANSI_COLOR;

        if (is_string($color) && !array_key_exists($color, $colors)) {

            $message = "Color provided to color code ($color) is invalid, message caught '$message'";

            $color = iColorCode::RED;

        }

        $message = sprintf($colors[$color], $message);

        if (CarbonPHP::$test) {

            /**
             * The code below doesn't seem to hold. print is needed to pass tests
             * @link https://stackoverflow.com/questions/21784240/is-there-any-way-to-expect-output-to-error-log-in-phpunit-tests
             * @noinspection ForgottenDebugOutputInspection
             * $current = ini_set('error_log', '/dev/stdout'); // use this rather than const as const is not defined in all run time envs
             * error_log($colorCodex);
             * ini_set('error_log', $current);
             */
            print $message . PHP_EOL;

            return;
        }

        /** @noinspection ForgottenDebugOutputInspection */
        error_log($message);    // do not double quote args passed here

        if (null === ErrorCatcher::$defaultLocation || '' === ErrorCatcher::$defaultLocation) {

            return;

        }

        $location = ini_get('error_log');

        if (false === touch(ErrorCatcher::$defaultLocation)) {

            $directory = dirname(ErrorCatcher::$defaultLocation);

            if (true === is_dir($directory)) {

                $message .= "\n\nThe error log file (" . ErrorCatcher::$defaultLocation . ') might not exist on the system. We have failed to manually create this as well. Please create the file required to store logs correctly!' . PHP_EOL;

            } elseif (mkdir($directory, 0744, true) && is_dir($directory)){

                $message .= "\n\nThe folder path ($directory) did not exist. We have created it manually.\n\n";

                /** @noinspection NotOptimalIfConditionsInspection */
                if (false === touch(ErrorCatcher::$defaultLocation)) {

                    $message .= "\n\nCould not create file (" . ErrorCatcher::$defaultLocation . ') as it does not exist on the system. All folders appear correct. Please create the directories required to store logs correctly!' . PHP_EOL;

                }

            } else {

                $message .= "\n\nThe error log folder path (" . ErrorCatcher::$defaultLocation . ') might not exist on the system. We have failed to manually create the folders as well. Please create the directories required to store logs correctly!' . PHP_EOL;

            }

        }

        switch ($location) {
            case '':
{'fraction_non_alphanumeric': 0.11782032400589101, 'fraction_numerical': 0.003681885125184094, 'mean_word_length': 2.2571942446043165, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '4793208', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1459, 'n_words': 409}