Completed
Push — master ( ba7c5d...c3b626 )
by Julián
02:08
created

Header   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isExcluded() 0 7 3
1
<?php
2
/**
3
 * Effortless maintenance management (http://juliangut.com/janitor)
4
 *
5
 * @link https://github.com/juliangut/janitor for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/janitor/blob/master/LICENSE
8
 */
9
10
namespace Janitor\Excluder;
11
12
use Janitor\Excluder as ExcluderInterface;
13
use Psr\Http\Message\ServerRequestInterface;
14
15
/**
16
 * Maintenance excluder by request header value
17
 */
18
class Header implements ExcluderInterface
19
{
20
    /**
21
     * Request header.
22
     *
23
     * @var string
24
     */
25
    protected $header;
26
27
    /**
28
     * Request header value.
29
     *
30
     * @var string
31
     */
32
    protected $value;
33
34
    /**
35
     * @param string      $header
36
     * @param string|null $value
37
     */
38
    public function __construct($header, $value = null)
39
    {
40
        $this->header = $header;
41
        $this->value = $value;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function isExcluded(ServerRequestInterface $request)
48
    {
49
        return $this->value === null
50
            ? $request->hasHeader($this->header)
51
            : $this->value === $request->getHeaderLine($this->header)
52
                || @preg_match($this->value, $request->getHeaderLine($this->header)) === 1;
53
    }
54
}
55