<commit_before><?php

namespace Proengsoft\JsValidation\Remote;

use Illuminate\Http\Exception\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr;
use Illuminate\Validation\Validator as BaseValidator;
use Proengsoft\JsValidation\Support\AccessProtectedTrait;
use Proengsoft\JsValidation\Support\RuleListTrait;

/**
 * Class RemoteValidator.
 */
class Validator
{
    use AccessProtectedTrait, RuleListTrait;

    /**
     * Validator extension name.
     */
    const EXTENSION_NAME = 'jsvalidation';

    /**
     * @var \Illuminate\Validation\Validator
     */
    protected $validator;

    /**
     * @var bool
     */
    protected $validateAll = false;

    /**
     * RemoteValidator constructor.
     *
     * @param \Illuminate\Validation\Validator $validator
     */
    public function __construct(BaseValidator $validator)
    {
        $this->validator = $validator;
    }

    /**
     * Force validate all rules
     *
     * @param $validateAll
     */
    public function setValidateAll($validateAll)
    {
        $this->validateAll = $validateAll;
    }

    /**
     * Validate request
     *
     * @param $attribute
     * @param $value
     * @param $parameters
     */
    public function validate($attribute, $value, $parameters)
    {
        $validationData = $this->parseJsRemoteRequest($attribute, $value, $parameters);
        $validationResult = $this->validateJsRemoteRequest($validationData[1]);
        throw new HttpResponseException(
            new JsonResponse($validationResult, 200));
    }

    /**
     *  Parse Validation input request data.
     *
     * @param $attribute
     * @param $value
     * @param $parameters
     * @return array
     */
    protected function parseJsRemoteRequest($attribute, $value, $parameters)
    {
        parse_str($value, $attrParts);
        $attrParts = is_null($attrParts) ? [] : $attrParts;
        $newAttr = array_keys(Arr::dot($attrParts));

        return [$attribute, array_pop($newAttr), $parameters];
    }

    /**
     * Validate remote Javascript Validations.
     *
     * @param $attribute
     * @return array|bool
     */
    protected function validateJsRemoteRequest($attribute)
    {
        $validator = $this->validator;
        $validator = $this->setRemoteValidation($attribute, $validator);

        if ($validator->passes()) {
            return true;
        }<commit_msg>Avoid using static access to class '\Illuminate\Support\Arr' in method 'parseJsRemoteRequest'.<commit_after><?php

namespace Proengsoft\JsValidation\Remote;

use Illuminate\Http\Exception\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr;
use Illuminate\Validation\Validator as BaseValidator;
use Proengsoft\JsValidation\Support\AccessProtectedTrait;
use Proengsoft\JsValidation\Support\RuleListTrait;

/**
 * Class RemoteValidator.
 */
class Validator
{
    use AccessProtectedTrait, RuleListTrait;

    /**
     * Validator extension name.
     */
    const EXTENSION_NAME = 'jsvalidation';

    /**
     * @var \Illuminate\Validation\Validator
     */
    protected $validator;

    /**
     * @var bool
     */
    protected $validateAll = false;

    /**
     * RemoteValidator constructor.
     *
     * @param \Illuminate\Validation\Validator $validator
     */
    public function __construct(BaseValidator $validator)
    {
        $this->validator = $validator;
    }

    /**
     * Force validate all rules
     *
     * @param $validateAll
     */
    public function setValidateAll($validateAll)
    {
        $this->validateAll = $validateAll;
    }

    /**
     * Validate request
     *
     * @param $attribute
     * @param $value
     * @param $parameters
     */
    public function validate($attribute, $value, $parameters)
    {
        $validationData = $this->parseJsRemoteRequest($attribute, $value, $parameters);
        $validationResult = $this->validateJsRemoteRequest($validationData[1]);
        throw new HttpResponseException(
            new JsonResponse($validationResult, 200));
    }

    /**
     *  Parse Validation input request data.
     *
     * @param $attribute
     * @param $value
     * @param $parameters
     * @return array
     */
    protected function parseJsRemoteRequest($attribute, $value, $parameters)
    {
        parse_str($value, $attrParts);
        $attrParts = is_null($attrParts) ? [] : $attrParts;
        $newAttr = array_keys(array_dot($attrParts));

        return [$attribute, array_pop($newAttr), $parameters];
    }

    /**
     * Validate remote Javascript Validations.
     *
     * @param $attribute
     * @return array|bool
     */
    protected function validateJsRemoteRequest($attribute)
    {
        $validator = $this->validator;
        $validator = $this->setRemoteValidation($attribute, $validator);

        if ($validator->passes()) {
            return true;
        }
{'fraction_non_alphanumeric': 0.1169519152404238, 'fraction_numerical': 0.0016299918500407497, 'mean_word_length': 2.6634328358208954, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '4299406', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1372, 'n_words': 279}