MaybeHandlesCsrfTrait::renderTokenField()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Leonidas\Library\Admin\Abstracts;
4
5
use Leonidas\Contracts\Auth\CsrfManagerInterface;
6
7
trait MaybeHandlesCsrfTrait
8
{
9
    /**
10
     * @var ?CsrfManagerInterface
11
     */
12
    protected $csrfManager = null;
13
14
    /**
15
     * Get the value of csrfToken
16
     *
17
     * @return CsrfManagerInterface
18
     */
19
    public function getTokenManager(): CsrfManagerInterface
20
    {
21
        return $this->csrfManager;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->csrfManager could return the type null which is incompatible with the type-hinted return Leonidas\Contracts\Auth\CsrfManagerInterface. Consider adding an additional type-check to rule them out.
Loading history...
22
    }
23
24
    /**
25
     * Set the value of csrfToken
26
     *
27
     * @param CsrfManagerInterface $csrfTokenManager
28
     *
29
     * @return $this
30
     */
31
    public function setTokenManager(CsrfManagerInterface $csrfTokenManager)
32
    {
33
        $this->csrfManager = $csrfTokenManager;
34
35
        return $this;
36
    }
37
38
    protected function renderTokenField(): string
39
    {
40
        return $this->csrfManager->renderField() . "\n";
0 ignored issues
show
Bug introduced by
The method renderField() does not exist on null. ( Ignorable by Annotation )

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

40
        return $this->csrfManager->/** @scrutinizer ignore-call */ renderField() . "\n";

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
    }
42
43
    protected function maybeRenderTokenField(): string
44
    {
45
        return isset($this->csrfManager) ? $this->renderTokenField() : '';
46
    }
47
}
48