RequestAttributeExtractor   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 22
ccs 5
cts 5
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extractHandler() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * Copyright (c) Florian Krämer (https://florian-kraemer.net)
5
 * Licensed under The MIT License
6
 * For full copyright and license information, please see the LICENSE.txt
7
 * Redistributions of files must retain the above copyright notice.
8
 *
9
 * @copyright Copyright (c) Florian Krämer (https://florian-kraemer.net)
10
 * @author    Florian Krämer
11
 * @link      https://github.com/Phauthentic
12
 * @license   https://opensource.org/licenses/MIT MIT License
13
 */
14
15
declare(strict_types=1);
16
17
namespace Phauthentic\Infrastructure\Http\Dispatcher;
18
19
use Psr\Http\Message\ServerRequestInterface;
20
21
/**
22
 * Simple Request Attribute Extractor
23
 */
24
class RequestAttributeExtractor implements HandlerExtractorInterface
25
{
26
    /**
27
     * @var string
28
     */
29
    protected $attributeName;
30
31
    /**
32
     * @param string $attributeName Attribute name to check for the handler
33
     */
34 2
    public function __construct(string $attributeName = 'handler')
35
    {
36 2
        $this->attributeName = $attributeName;
37 2
    }
38
39
    /**
40
     * @param \Psr\Http\Message\ServerRequestInterface $request Server Request
41
     * @return mixed
42
     */
43 2
    public function extractHandler(ServerRequestInterface $request)
44
    {
45 2
        return $request->getAttribute($this->attributeName, null);
46
    }
47
}
48