Passed
Branch scrutinizer (e74cca)
by Wanderson
01:51
created

ReCaptcha::isValid()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\Html\Form;
4
5
use Win\Request\Input;
6
7
/**
8
 * Utiliza o ReCaptcha do Google
9
 * Validando se o usuário não é um robô
10
 */
11
class ReCaptcha {
12
13
	public static $siteKey = '';
14
	public static $secretKey = '';
15
16
	/**
17
	 * Retorna TRUE se usuário marcou "Não sou um robô"
18
	 * @return boolean
19
	 */
20
	public static function isValid() {
21
		if (static::$siteKey && static::$secretKey) {
22
			$captcha = Input::post('g-recaptcha-response');
23
			$response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . static::$secretKey . "&response=" . $captcha . "&remoteip=" . Input::server('REMOTE_ADDR')), true);
24
			return (boolean) $response['success'];
25
		} else {
26
			return true;
27
		}
28
	}
29
30
}
31