Test Failed
Pull Request — master (#32)
by Anatoly
02:09
created

RouteCollectionGroupAction::addSuffix()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
namespace Sunrise\Http\Router;
13
14
/**
15
 * Import classes
16
 */
17
use Psr\Http\Server\MiddlewareInterface;
18
19
/**
20
 * Import functions
21
 */
22
use function array_merge;
23
24
/**
25
 * RouteCollectionGroupAction
26
 */
27
class RouteCollectionGroupAction implements RouteCollectionGroupActionInterface
28
{
29
30
    /**
31
     * Route collection for group activities
32
     *
33
     * @var RouteCollectionInterface
34
     */
35
    private $collection;
36
37
    /**
38
     * Constructor of the class
39
     *
40
     * @param RouteCollectionInterface $collection
41
     */
42
    public function __construct(RouteCollectionInterface $collection)
43
    {
44
        $this->collection = $collection;
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50
    public function addPrefix(string $prefix) : RouteCollectionGroupActionInterface
51
    {
52
        foreach ($this->collection as $route) {
53
            $route->addPrefix($prefix);
54
        }
55
56
        return $this;
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    public function addSuffix(string $suffix) : RouteCollectionGroupActionInterface
63
    {
64
        foreach ($this->collection as $route) {
65
            $route->addSuffix($suffix);
66
        }
67
68
        return $this;
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     */
74
    public function addMethod(string ...$methods) : RouteCollectionGroupActionInterface
75
    {
76
        foreach ($this->collection as $route) {
77
            $route->addMethod(...$methods);
78
        }
79
80
        return $this;
81
    }
82
83
    /**
84
     * {@inheritDoc}
85
     */
86
    public function addMiddleware(MiddlewareInterface ...$middlewares) : RouteCollectionGroupActionInterface
87
    {
88
        foreach ($this->collection as $route) {
89
            $route->addMiddleware(...$middlewares);
90
        }
91
92
        return $this;
93
    }
94
95
    /**
96
     * {@inheritDoc}
97
     */
98
    public function unshiftMiddleware(MiddlewareInterface ...$middlewares) : RouteCollectionGroupActionInterface
99
    {
100
        foreach ($this->collection as $route) {
101
            $route->setMiddlewares(...array_merge(
102
                $middlewares,
103
                $route->getMiddlewares()
104
            ));
105
        }
106
107
        return $this;
108
    }
109
}
110