IsBypassedCheck::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TheCodingMachine\Middlewares\SafeRequests;
5
6
use Psr\Http\Message\ServerRequestInterface;
7
8
/**
9
 * Checks for the presence of a 'TheCodingMachine\BypassCsrf' attribute in the request.
10
 */
11
final class IsBypassedCheck implements IsSafeHttpRequestInterface
12
{
13
14
    /**
15
     * @var string
16
     */
17
    private $attributeName;
18
19
    public function __construct(string $attributeName)
20
    {
21
        $this->attributeName = $attributeName;
22
    }
23
24
    public static function fromDefault() : self
25
    {
26
        return new self('TheCodingMachine\\BypassCsrf');
27
    }
28
29
    public function __invoke(ServerRequestInterface $request) : bool
30
    {
31
        return (bool) $request->getAttribute($this->attributeName);
32
    }
33
}
34