Passed
Pull Request — master (#60)
by
unknown
10:40
created

HandlerAwareTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A prependHandler() 0 5 1
A handlers() 0 7 2
A handler() 0 5 1
A getHandlers() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Router\Handler;
6
7
use Psr\Http\Server\MiddlewareInterface;
8
9
use function array_unshift;
10
11
trait HandlerAwareTrait
12
{
13
    private array $handlers = [];
14
15
    /**
16
     * Add handler that should be invoked for the route when match happens to the stack.
17
     *
18
     * @param mixed $handler that will be added.
19
     * Handler type and format support depends on the \Yiisoft\Router\Dispatcher\DispatcherInterface implementation.
20
     * @param bool $validate whether to validate handler before execution
21
     *
22
     * @return HandlerAwareInterface
23
     */
24
    public function handler($handler, $validate = false): HandlerAwareInterface
0 ignored issues
show
Unused Code introduced by
The parameter $validate is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
    public function handler($handler, /** @scrutinizer ignore-unused */ $validate = false): HandlerAwareInterface

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        $this->handlers[] = $handler;
27
28
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Yiisoft\Router\Handler\HandlerAwareTrait which is incompatible with the type-hinted return Yiisoft\Router\Handler\HandlerAwareInterface.
Loading history...
29
    }
30
31
    /**
32
     * Add multiple handlers that should be invoked for the route when match happens to the stack.
33
     *
34
     * @param array $handlers that will be added.
35
     * Handler type and format support depends on the \Yiisoft\Router\Dispatcher\DispatcherInterface implementation.
36
     * @param false $validate whether to validate handlers before execution
37
     *
38
     * @return HandlerAwareInterface
39
     */
40
    public function handlers(iterable $handlers, $validate = false): HandlerAwareInterface
41
    {
42
        foreach ($handlers as $handler) {
43
            $this->handler($handler, $validate);
44
        }
45
46
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Yiisoft\Router\Handler\HandlerAwareTrait which is incompatible with the type-hinted return Yiisoft\Router\Handler\HandlerAwareInterface.
Loading history...
47
    }
48
49
    /**
50
     * Prepend handler that should be invoked for the route when match happens to the stack.
51
     *
52
     * @param mixed $handler that will be added.
53
     * Handler type and format support depends on the \Yiisoft\Router\Dispatcher\DispatcherInterface implementation.
54
     * @param bool $validate whether to validate handler before execution
55
     *
56
     * @return HandlerAwareInterface
57
     */
58
    public function prependHandler($handler, $validate = false): HandlerAwareInterface
0 ignored issues
show
Unused Code introduced by
The parameter $validate is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

58
    public function prependHandler($handler, /** @scrutinizer ignore-unused */ $validate = false): HandlerAwareInterface

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
    {
60
        array_unshift($this->handlers, $handler);
61
62
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Yiisoft\Router\Handler\HandlerAwareTrait which is incompatible with the type-hinted return Yiisoft\Router\Handler\HandlerAwareInterface.
Loading history...
63
    }
64
65
    /**
66
     * Get the stack of handlers that should be invoked for the route when match happens.
67
     *
68
     * @return iterable stack of handlers.
69
     */
70
    public function getHandlers(): iterable
71
    {
72
        return $this->handlers;
73
    }
74
}
75