Passed
Push — master ( 035a69...ef3bdc )
by Kirill
03:22
created

VerbsTrait::getVerbs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Router\Traits;
13
14
use Spiral\Router\Exception\RouteException;
15
use Spiral\Router\RouteInterface;
16
17
trait VerbsTrait
18
{
19
    /** @var array */
20
    protected $verbs = RouteInterface::VERBS;
21
22
    /**
23
     * Attach specific list of HTTP verbs to the route.
24
     *
25
     * @param string ...$verbs
26
     *
27
     * @return RouteInterface|$this
28
     *
29
     * @throws RouteException
30
     */
31
    public function withVerbs(string ...$verbs): RouteInterface
32
    {
33
        foreach ($verbs as &$verb) {
34
            $verb = strtoupper($verb);
35
            if (!in_array($verb, RouteInterface::VERBS, true)) {
36
                throw new RouteException("Invalid HTTP verb `{$verb}`");
37
            }
38
39
            unset($verb);
40
        }
41
        unset($verb);
42
43
        $route = clone $this;
44
        $route->verbs = $verbs;
45
46
        return $route;
47
    }
48
49
    /**
50
     * Return list of HTTP verbs route must handle.
51
     *
52
     * @return array
53
     */
54
    public function getVerbs(): array
55
    {
56
        return $this->verbs;
57
    }
58
}
59