<commit_before><?php

namespace G4\Runner;

use G4\CleanCore\Request\Request;
use G4\Constants\Parameters;

class Application extends \G4\CleanCore\Application
{
    public function __construct(\G4\Runner\RunnerInterface $appRunner = null)
    {
        if(null !== $appRunner && $appRunner instanceof \G4\Runner\RunnerInterface) {
            $request = new Request();
            $request
                ->setModule($appRunner->getApplicationModule())
                ->setMethod($appRunner->getApplicationMethod())
                ->setResourceName($appRunner->getApplicationService())
                ->setParams($appRunner->getApplicationParams())
                ->setAjaxCall($appRunner->getHttpRequest()->isAjax());

            // set anonymization rules for sensitive parameters
            foreach ($this->getRequestAnonymizationRules() as $param => $rule) {
                $request->setAnonymizationRules($param, $rule);
            }

            $this
                ->setRequest($request)
                ->setAppNamespace($appRunner->getApplicationModule());
        }
    }

    private function getRequestAnonymizationRules()
    {
        return [
            Parameters::X_ND_AUTH => function($value) {
                return substr_replace($value, str_repeat('*', 20), 0, -12);
            },
            Parameters::X_ND_APP_KEY => function($value) {
                return substr_replace($value, str_repeat('*', 20), 0, -12);
            },
            Parameters::CC_NUMBER => function($value) {
                return substr_replace($value, str_repeat('*', 12), 0, -4);
            },
            Parameters::CC_CVV2 => '***',<commit_msg>Application __construct() method will set rawInput and serverVariables properties of request<commit_after><?php

namespace G4\Runner;

use G4\CleanCore\Request\Request;
use G4\Constants\Parameters;

class Application extends \G4\CleanCore\Application
{
    public function __construct(\G4\Runner\RunnerInterface $appRunner = null)
    {
        if(null !== $appRunner && $appRunner instanceof \G4\Runner\RunnerInterface) {
            $request = new Request();
            $request
                ->setModule($appRunner->getApplicationModule())
                ->setMethod($appRunner->getApplicationMethod())
                ->setResourceName($appRunner->getApplicationService())
                ->setParams($appRunner->getApplicationParams())
                ->setAjaxCall($appRunner->getHttpRequest()->isAjax())
                ->setRawInput(file_get_contents("php://input"))
                ->setServerVariables($_SERVER);

            // set anonymization rules for sensitive parameters
            foreach ($this->getRequestAnonymizationRules() as $param => $rule) {
                $request->setAnonymizationRules($param, $rule);
            }

            $this
                ->setRequest($request)
                ->setAppNamespace($appRunner->getApplicationModule());
        }
    }

    private function getRequestAnonymizationRules()
    {
        return [
            Parameters::X_ND_AUTH => function($value) {
                return substr_replace($value, str_repeat('*', 20), 0, -12);
            },
            Parameters::X_ND_APP_KEY => function($value) {
                return substr_replace($value, str_repeat('*', 20), 0, -12);
            },
            Parameters::CC_NUMBER => function($value) {
                return substr_replace($value, str_repeat('*', 12), 0, -4);
            },
            Parameters::CC_CVV2 => '***',
{'fraction_non_alphanumeric': 0.13174332765474162, 'fraction_numerical': 0.01192504258943782, 'mean_word_length': 2.247004608294931, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '5749766', 'n_tokens_mistral': 931, 'n_tokens_neox': 878, 'n_words': 162}