Completed
Pull Request — master (#1)
by David
05:31
created

IsBypassedCheck   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 23
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromDefault() 0 4 1
A __invoke() 0 4 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