<commit_before><?php namespace Nord\Lumen\Core\App;

use Closure;
use Illuminate\Contracts\Validation\Factory;
use Illuminate\Contracts\Validation\Validator;

trait ValidatesData
{

    /**
     * @param mixed $data
     * @param array $rules
     * @param array $messages
     * @param array $customAttributes
     *
     * @return Validator
     */
    private function createValidator($data, array $rules, array $messages = [], array $customAttributes = [])
    {
        return $this->getValidatorFactory()->make($data, $rules, $messages, $customAttributes);
    }


    /**
     * @param mixed $data
     * @param array $rules
     * @param array $messages
     * @param array $customAttributes
     *
     * @return array
     */
    private function validateData($data, array $rules, array $messages = [], array $customAttributes = [])
    {
        return $this->createValidator($data, $rules, $messages, $customAttributes)->failed();
    }


    /**
     * @param mixed   $data
     * @param array   $rules
     * @param Closure $validationFailed
     * @param array   $messages
     * @param array   $customAttributes
     *
     * @return array
     */
    private function tryValidateData(
        $data,
        array $rules,
        Closure $validationFailed,
        array $messages = [],
        array $customAttributes = []
    ) {
        if (($errors = $this->validateData($data, $rules, $messages, $customAttributes))) {
            call_user_func($validationFailed, $errors);
        }

        return $errors;
    }


    /**
     * @return Factory
     */<commit_msg>Fix bug that caused ValidatesData trait to always pass validation (oops)<commit_after><?php namespace Nord\Lumen\Core\App;

use Closure;
use Illuminate\Contracts\Validation\Factory;
use Illuminate\Validation\Validator;

trait ValidatesData
{

    /**
     * @param mixed $data
     * @param array $rules
     * @param array $messages
     * @param array $customAttributes
     *
     * @return Validator
     */
    private function createValidator($data, array $rules, array $messages = [], array $customAttributes = [])
    {
        return $this->getValidatorFactory()->make($data, $rules, $messages, $customAttributes);
    }


    /**
     * @param mixed   $data
     * @param array   $rules
     * @param Closure $validationFailed
     * @param array   $messages
     * @param array   $customAttributes
     *
     * @return array
     */
    private function tryValidateData(
        $data,
        array $rules,
        Closure $validationFailed,
        array $messages = [],
        array $customAttributes = []
    ) {
        $validator = $this->createValidator($data, $rules, $messages, $customAttributes);

        if ($validator->fails()) {
            call_user_func($validationFailed, $validator->errors()->getMessages());
        }
    }


    /**
     * @return Factory
     */
{'fraction_non_alphanumeric': 0.12647262647262647, 'fraction_numerical': 0.0, 'mean_word_length': 2.482509047044632, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '7428946', 'n_tokens_mistral': 803, 'n_tokens_neox': 798, 'n_words': 197}