<commit_before><?php

namespace atk4\core;

trait DebugTrait
{
    /**
     * Check this property to see if trait is present in the object.
     *
     * @var bool
     */
    public $_debugTrait = true;

    /** @var bool Is debug enabled? */
    public $debug = null;

    /** @var array Helps debugTraceChange. */
    protected $_prev_bt = [];

    /**
     * Outputs message to STDERR.
     *
     * @codeCoverageIgnore - replaced with "echo" which can be intercepted by test-suite
     *
     * @param string $message
     */
    protected function _echo_stderr($message)
    {
        fwrite(STDERR, $message);
    }

    /**
     * Send some info to debug stream.
     *
     * @param bool|string $message
     * @param array       $context
     *
     * @return $this
     */
    public function debug($message = true, $context = [])
    {
        // using this to switch on/off the debug for this object
        if (is_bool($message)) {
            $this->debug = $message;

            return $this;
        }

        // if debug is enabled, then log it
        if ($this->debug) {
            if (isset($this->app) && isset($this->app->logger) && $this->app->logger instanceof \Psr\Log\LoggerInterface) {
                $this->app->logger->log('debug', $message, $context);
            } else {
                $this->_echo_stderr('['.get_class($this)."]: $message\n");
            }
        }<commit_msg>PHP72 has no longer STDERR (#73)<commit_after><?php

namespace atk4\core;

trait DebugTrait
{
    /**
     * Check this property to see if trait is present in the object.
     *
     * @var bool
     */
    public $_debugTrait = true;

    /** @var bool Is debug enabled? */
    public $debug = null;

    /** @var array Helps debugTraceChange. */
    protected $_prev_bt = [];

    /**
     * Outputs message to STDERR.
     *
     * @codeCoverageIgnore - replaced with "echo" which can be intercepted by test-suite
     *
     * @param string $message
     */
    protected function _echo_stderr($message)
    {
        file_put_contents('php://stderr', $message);
    }

    /**
     * Send some info to debug stream.
     *
     * @param bool|string $message
     * @param array       $context
     *
     * @return $this
     */
    public function debug($message = true, $context = [])
    {
        // using this to switch on/off the debug for this object
        if (is_bool($message)) {
            $this->debug = $message;

            return $this;
        }

        // if debug is enabled, then log it
        if ($this->debug) {
            if (isset($this->app) && isset($this->app->logger) && $this->app->logger instanceof \Psr\Log\LoggerInterface) {
                $this->app->logger->log('debug', $message, $context);
            } else {
                $this->_echo_stderr('['.get_class($this)."]: $message\n");
            }
        }
{'fraction_non_alphanumeric': 0.13778705636743216, 'fraction_numerical': 0.0020876826722338203, 'mean_word_length': 1.8521825396825398, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '4848985', 'n_tokens_mistral': 863, 'n_tokens_neox': 838, 'n_words': 233}