PriorityDelegate::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Caridea
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
 * use this file except in compliance with the License. You may obtain a copy of
8
 * the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 * License for the specific language governing permissions and limitations under
16
 * the License.
17
 *
18
 * @copyright 2017-2018 LibreWorks contributors
19
 * @license   Apache-2.0
20
 */
21
namespace Caridea\Dispatch\Middleware;
22
23
use Psr\Http\Message\ResponseInterface;
24
use Psr\Http\Message\ServerRequestInterface;
25
use Psr\Http\Server\MiddlewareInterface;
26
use Psr\Http\Server\RequestHandlerInterface;
27
28
/**
29
 * A middleware that specifies a priority number.
30
 *
31
 * Allows you to specify priority for an existing middleware implementation
32
 * at runtime without having to extend the class.
33
 *
34
 * @copyright 2017-2018 LibreWorks contributors
35
 * @license   Apache-2.0
36
 */
37
class PriorityDelegate implements Prioritized
38
{
39
    /**
40
     * @var \Psr\Http\Server\MiddlewareInterface
41
     */
42
    private $delegate;
43
    /**
44
     * @var int
45
     */
46
    private $priority;
47
48
    /**
49
     * Creates a new `PriorityDelegate`.
50
     *
51
     * @param \Psr\Http\Server\MiddlewareInterface $delegate  The middleware to delegate
52
     * @param int $priority  The priority
53
     */
54 1
    public function __construct(MiddlewareInterface $delegate, int $priority)
55
    {
56 1
        $this->delegate = $delegate;
57 1
        $this->priority = $priority;
58 1
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63 1
    public function getPriority(): int
64
    {
65 1
        return $this->priority;
66
    }
67
68
    /**
69
     * {@inheritDoc}
70
     */
71 1
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
72
    {
73 1
        return $this->delegate->process($request, $handler);
74
    }
75
}
76