Completed
Push — master ( 177022...fa1d20 )
by Joao
11:37
created

CaptchaTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A captchaCheck() 0 14 2
1
<?php namespace jlourenco\support\Traits;
2
3
use Input;
4
use ReCaptcha\ReCaptcha;
5
6
trait CaptchaTrait
7
{
8
9
    public function captchaCheck()
0 ignored issues
show
Coding Style introduced by
captchaCheck uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
10
    {
11
        $response = Input::get('g-recaptcha-response');
12
        $remoteip = $_SERVER['REMOTE_ADDR'];
13
        $secret   = env('RE_CAP_SECRET');
14
15
        $recaptcha = new ReCaptcha($secret);
16
        $resp = $recaptcha->verify($response, $remoteip);
17
18
        if ($resp->isSuccess())
19
            return true;
20
        else
21
            return false;
22
    }
23
24
}