ReCaptcha   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 8 3
A getValidationUrl() 0 6 1
1
<?php
2
3
namespace Win\InfraServices;
4
5
use Win\Request\Input;
6
7
/**
8
 * 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 bool
19
	 */
20
	public static function isValid()
21
	{
22
		if (static::$siteKey && static::$secretKey) {
23
			$response = json_decode(file_get_contents(static::getValidationUrl()), true);
24
25
			return (bool) $response['success'];
26
		} else {
27
			return true;
28
		}
29
	}
30
31
	/**
32
	 * Retorna a URL de validação
33
	 * @return string
34
	 */
35
	public static function getValidationUrl()
36
	{
37
		return 'https://www.google.com/recaptcha/api/siteverify'
38
			. '?secret=' . static::$secretKey
39
			. '&response=' . Input::post('g-recaptcha-response')
40
			. '&remoteip=' . Input::server('REMOTE_ADDR');
41
	}
42
}
43