Guarded::getGuardian()   A
last analyzed

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
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Jasny\Controller\Traits;
4
5
use Jasny\Controller\Guardian;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
9
trait Guarded
10
{
11
    protected Guardian $guardian;
12
13
    abstract protected function getRequest(): ServerRequestInterface;
14
    abstract protected function getResponse(): ResponseInterface;
15
16
    private function getGuardian(): Guardian
17
    {
18
        $this->guardian ??= new Guardian();
19
        return $this->guardian;
20
    }
21
22
    protected function guard(\ReflectionObject|\ReflectionMethod $subject): ?ResponseInterface
23
    {
24
        return $this->getGuardian()->guard($subject, $this->getRequest(), $this->getResponse());
25
    }
26
}
27