HasClientTrait::setClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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
Bug introduced by
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
}