Guarded   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 5
c 1
b 0
f 0
dl 0
loc 16
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getGuardian() 0 4 1
A guard() 0 3 1
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