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

Header::isExcluded()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 3
eloc 5
nc 4
nop 1
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