Issues (21)

src/Manager/Traits/HasClientTrait.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace ByTIC\GoogleRecaptcha\Manager\Traits;
4
5
use ReCaptcha\ReCaptcha;
6
7
/**
8
 * Trait HasClientTrait
9
 * @package ByTIC\GoogleRecaptcha\Manager\Traits
10
 */
11
trait HasClientTrait
12
{
13
    /**
14
     * @var null|ReCaptcha
15
     */
16
    protected $client = null;
17
18
    /**
19
     * @return ReCaptcha|null
20
     */
21
    public function getClient(): ReCaptcha
22
    {
23
        if ($this->client === null) {
24
            $this->initClient();
25
        }
26
        return $this->client;
27
    }
28
29
    /**
30
     * @param ReCaptcha|null $client
31
     */
32
    public function setClient(?ReCaptcha $client): void
33
    {
34
        $this->client = $client;
35
    }
36
37
    protected function initClient()
38
    {
39
        $client = new \ReCaptcha\ReCaptcha($this->getSecretKey());
0 ignored issues
show
It seems like getSecretKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        $client = new \ReCaptcha\ReCaptcha($this->/** @scrutinizer ignore-call */ getSecretKey());
Loading history...
40
        $this->setClient($client);
41
    }
42
}