<commit_before><?php
namespace App\Shared\Helpers;

use GuzzleHttp\Client;
use Illuminate\Http\Request;
use Illuminate\Contracts\Validation\Validator;


class Recaptcha {
    
    /**
     * The POST field name of reCAPTCHA
     *
     * @var string
     */
    public $field = 'g-recaptcha-response';

    public $errorMessage = 'reCAPTCHA verification failed';

    /**
     * @var Client
     */
    private $client;

    public function __construct(Client $client) {
        $this->client = $client;
    }

    /**
     * Returns this site's public reCAPTCHA key
     *
     * @return void
     */
    public static function getSiteKey() {
        $key = env('RECAPTCHA_SITE_KEY');
        if($key === null) {
            throw new \Exception('reCAPTCHA site key not set');
        }
        return $key;
    }

    /**
     * Determines whether the given request
     * passed the reCAPTCHA test
     *
     * @param Request $request
     * @return Bool
     */
    public function fails(Request $request) : Bool {
        if(env('RECAPTCHA_ENABLED', false) === false) {
            return false;
        }

        $response = $client->post('https://www.google.com/recaptcha/api/siteverify', [
            'form_params' => [
                'secret'    => env('RECAPTCHA_SECRET_KEY'),
                'response'  => $request->get($this->getFieldName()),
                'remoteip'  => $request->ip(),
            ],
        ]);
        $result = json_decode($response->getBody(), true);

        $success = $result['success'];
        if($success === null || $success === false) {
            return true;
        }

        return false;
    }

    /**
     * Adds an error message to the given validator
     * if the request failed the reCAPTCHA test
     *
     * @param Request $request
     * @param Validator $validator
     * @return void
     */
    public function validate(Request $request, Validator $validator) {
        if($this->fails($request)) {
            $validator->errors()->add($this->field, 'reCAPTCHA failed. Are you a bot?');
        }
    }

}<commit_msg>Fix missing php dependency<commit_after><?php
namespace App\Shared\Helpers;

use GuzzleHttp\Client;
use Illuminate\Http\Request;
use Illuminate\Contracts\Validation\Validator;


class Recaptcha {
    
    /**
     * The POST field name of reCAPTCHA
     *
     * @var string
     */
    public $field = 'g-recaptcha-response';

    public $errorMessage = 'reCAPTCHA verification failed';

    /**
     * @var Client
     */
    private $client;

    public function __construct(Client $client) {
        $this->client = $client;
    }

    /**
     * Returns this site's public reCAPTCHA key
     *
     * @return void
     */
    public static function getSiteKey() {
        $key = env('RECAPTCHA_SITE_KEY');
        if($key === null) {
            throw new \Exception('reCAPTCHA site key not set');
        }
        return $key;
    }

    /**
     * Determines whether the given request
     * passed the reCAPTCHA test
     *
     * @param Request $request
     * @return Bool
     */
    public function fails(Request $request) : Bool {
        if(env('RECAPTCHA_ENABLED', false) === false) {
            return false;
        }

        $response = $this->client->post('https://www.google.com/recaptcha/api/siteverify', [
            'form_params' => [
                'secret'    => env('RECAPTCHA_SECRET_KEY'),
                'response'  => $request->get($this->getFieldName()),
                'remoteip'  => $request->ip(),
            ],
        ]);
        $result = json_decode($response->getBody(), true);

        $success = $result['success'];
        if($success === null || $success === false) {
            return true;
        }

        return false;
    }

    /**
     * Adds an error message to the given validator
     * if the request failed the reCAPTCHA test
     *
     * @param Request $request
     * @param Validator $validator
     * @return void
     */
    public function validate(Request $request, Validator $validator) {
        if($this->fails($request)) {
            $validator->errors()->add($this->field, 'reCAPTCHA failed. Are you a bot?');
        }
    }

}
{'fraction_non_alphanumeric': 0.13253873659117998, 'fraction_numerical': 0.0, 'mean_word_length': 1.9864768683274021, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '7470052', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1230, 'n_words': 293}