Completed
Push — master ( a01cf7...33cfd8 )
by Oscar
01:51
created

Accept::match()   A

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
3
namespace Middleland\Matchers;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
7
class Accept implements MatcherInterface
8
{
9
    private $accept;
10
    private $result = true;
11
12
    /**
13
     * @param string $accept
14
     */
15 View Code Duplication
    public function __construct(string $accept)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
    {
17
        if ($accept[0] === '!') {
18
            $this->result = false;
19
            $accept = substr($accept, 1);
20
        }
21
22
        $this->accept = $accept;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function match(ServerRequestInterface $request): bool
29
    {
30
        return is_int(stripos($request->getHeaderLine('Accept'), $this->accept)) === $this->result;
31
    }
32
}
33