<commit_before><?php

namespace App\Containers\Debugger\Tasks;

use App;
use DB;
use Illuminate\Support\Facades\Config;
use Jenssegers\Agent\Facades\Agent;
use Log;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

/**
 * Class RequestsDebuggerTask
 *
 * @author  <NAME>  <<EMAIL>>
 */
class RequestsDebuggerTask
{

    CONST TESTING_ENV = 'testing';

    protected $responseDataCut;

    protected $tokenDataCut;

    protected $debuggingEnabled;

    protected $environment;

    protected $logger;

    protected $logFile;

    /**
     * RequestsDebuggerTask constructor.
     */
    public function __construct()
    {
        $this->prepareConfigs();
        $this->prepareLogger();
    }

    /**
     * @param $request
     * @param $response
     */
    public function run($request, $response)
    {
        if ($this->environment != self::TESTING_ENV && $this->debuggingEnabled === true) {

            // Prepare some data to be displayed

            // Auth Header
            $authHeader = $request->header("Authorization");

            // User
            $user = $request->user() ? "ID: " . $request->user()->id . " (Name: " . $request->user()->name . ")" : "N/A";

            // Browser
            $browser = Agent::browser();

            // Request Data
            $requestData = $request->all() ? http_build_query($request->all(), "", " + ") : "N/A";

            // Response Data
            $responseContent = ($response && method_exists($response, "content")) ? $response->content() : "N/A";

            // Call the Logger.
            $this->log($request, $user, $browser, $authHeader, $responseContent, $requestData);
        }
    }

    /**
     * Feel free to pass any extra data to be displayed.
     *
     * @param $request
     * @param $user
     * @param $browser
     * @param $authHeader
     * @param $responseContent
     * @param $requestData
     */
    private function log($request, $user, $browser, $authHeader, $responseContent, $requestData)
    {
        $print = "----------------- NEW REQUEST ---------------------------------------------------";
        $print .= "\n \n";

        $print .= "REQUEST: \n";
        $print .= "   Endpoint: " . $request->fullUrl() . "\n";
        $print .= "   Method: " . $request->getMethod() . "\n";
        $print .= "   Version: " . $request->version() . "\n";<commit_msg>solve method not exist `version`<commit_after><?php

namespace App\Containers\Debugger\Tasks;

use App;
use DB;
use Illuminate\Support\Facades\Config;
use Jenssegers\Agent\Facades\Agent;
use Log;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

/**
 * Class RequestsDebuggerTask
 *
 * @author  <NAME>  <<EMAIL>>
 */
class RequestsDebuggerTask
{

    CONST TESTING_ENV = 'testing';

    protected $responseDataCut;

    protected $tokenDataCut;

    protected $debuggingEnabled;

    protected $environment;

    protected $logger;

    protected $logFile;

    /**
     * RequestsDebuggerTask constructor.
     */
    public function __construct()
    {
        $this->prepareConfigs();
        $this->prepareLogger();
    }

    /**
     * @param $request
     * @param $response
     */
    public function run($request, $response)
    {
        if ($this->environment != self::TESTING_ENV && $this->debuggingEnabled === true) {

            // Prepare some data to be displayed

            // Auth Header
            $authHeader = $request->header("Authorization");

            // User
            $user = $request->user() ? "ID: " . $request->user()->id . " (Name: " . $request->user()->name . ")" : "N/A";

            // Browser
            $browser = Agent::browser();

            // Request Data
            $requestData = $request->all() ? http_build_query($request->all(), "", " + ") : "N/A";

            // Response Data
            $responseContent = ($response && method_exists($response, "content")) ? $response->content() : "N/A";

            // Call the Logger.
            $this->log($request, $user, $browser, $authHeader, $responseContent, $requestData);
        }
    }

    /**
     * Feel free to pass any extra data to be displayed.
     *
     * @param $request
     * @param $user
     * @param $browser
     * @param $authHeader
     * @param $responseContent
     * @param $requestData
     */
    private function log($request, $user, $browser, $authHeader, $responseContent, $requestData)
    {
        $print = "----------------- NEW REQUEST ---------------------------------------------------";
        $print .= "\n \n";

        $print .= "REQUEST: \n";
        $print .= "   Endpoint: " . $request->fullUrl() . "\n";
        $print .= "   Method: " . $request->getMethod() . "\n";

        if(method_exists($request, 'version')){
            $print .= "   Version: " . $request->version() . "\n";
        }

{'fraction_non_alphanumeric': 0.18256075148049827, 'fraction_numerical': 0.0, 'mean_word_length': 2.0085995085995085, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 43, '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': '5559163', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1383, 'n_words': 317}