Completed
Push — develop ( da7aa8...3d4c5c )
by greg
09:02
created

Recaptcha::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace PlaygroundCore\Service;
3
4
use Zend\ServiceManager\ServiceManager;
5
use ZfcBase\EventManager\EventProvider;
6
use Zend\ServiceManager\ServiceLocatorInterface;
7
8
/**
9
 * main class
10
 */
11
class Recaptcha extends EventProvider
12
{
13
    /**
14
     * @var ModuleOptions
15
     */
16
    protected $options;
17
18
    /**
19
     *
20
     * @var ServiceManager
21
     */
22
    protected $serviceLocator;
23
24
    public function __construct(ServiceLocatorInterface $locator)
25
    {
26
        $this->serviceLocator = $locator;
0 ignored issues
show
Documentation Bug introduced by
$locator is of type object<Zend\ServiceManag...erviceLocatorInterface>, but the property $serviceLocator was declared to be of type object<Zend\ServiceManager\ServiceManager>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
27
    }
28
29
    /**
30
     * This method calls Google ReCaptcha.
31
     * @param  unknown_type $url
0 ignored issues
show
Bug introduced by
There is no parameter named $url. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
32
     * @return unknown
33
     */
34
    public function recaptcha($response, $ipClient = null)
35
    {
36
        if ($this->getOptions()->getGRecaptchaKey()) {
37
            $client = new \Zend\Http\Client($this->getOptions()->getGRecaptchaUrl());
38
            $client->setParameterPost(array(
39
                'secret'  => $this->getOptions()->getGRecaptchaKey(),
40
                'response' => $response,
41
                'remoteip'   => $ipClient,
42
            ));
43
            $client->setMethod(\Zend\Http\Request::METHOD_POST);
44
    
45
            $result = $client->send();
46
            if ($result) {
47
                $jsonResult = \Zend\Json\Json::decode($result->getBody());
48
                if ($jsonResult->success) {
49
                    return true;
50
                }
51
            }
52
        }
53
54
        return false;
55
    }
56
57
    public function setOptions($options)
58
    {
59
        $this->options = $options;
60
61
        return $this;
62
    }
63
64
    public function getOptions()
65
    {
66
        if (!$this->options) {
67
            $this->setOptions($this->serviceLocator->get('playgroundcore_module_options'));
68
        }
69
70
        return $this->options;
71
    }
72
}
73