Recaptcha   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isRequestValid() 0 6 1
A validateRequest() 0 4 1
A isValid() 0 6 1
A validate() 0 15 1
1
<?php
2
3
namespace Guiliredu\LaravelSimpleRecaptcha;
4
5
use GuzzleHttp\Client;
6
7
class Recaptcha
8
{
9
    public static function isRequestValid($request)
10
    {
11
        $response = static::validateRequest($request);
12
13
        return (boolean) $response['success'];
14
    }
15
16
    public static function validateRequest($request)
17
    {
18
        return static::validate($request->input('g-recaptcha-response'));
19
    }
20
21
    public static function isValid($input)
22
    {
23
        $response = static::validate($input);
24
25
        return (boolean) $response['success'];
26
    }
27
28
    public static function validate($input)
29
    {
30
        // Guzzle
31
        $http = new Client();
32
33
        $response = $http->request('POST', 'https://www.google.com/recaptcha/api/siteverify', [
34
            'form_params' => [
35
                'secret' => config('recaptcha.secret'),
36
                'response' => $input,
37
                'remoteip' => request()->header('REMOTE_ADDR'),
38
            ]
39
        ]);
40
41
        return json_decode($response->getBody()->getContents(), true);
42
    }
43
}
44