Issues (105)

Traits/CollectionsOperationsTrait.php (4 issues)

1
<?php
2
declare(strict_types=1);
3
4
namespace Nip\Router\RouteCollections\Traits;
5
6
use Nip\Router\Route\Route;
7
8
/**
9
 * Trait CollectionsOperationsTrait
10
 * @package Nip\Router\RouteCollections\Traits
11
 */
12
trait CollectionsOperationsTrait
13
{
14
    /**
15
     * @inheritdoc
16
     * @deprecated Use all()
17
     */
18
    public function getRoutes()
19
    {
20
        return $this->all();
0 ignored issues
show
It seems like all() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

20
        return $this->/** @scrutinizer ignore-call */ all();
Loading history...
21
    }
22
23
    /**
24
     * @param array $routes
25 1
     */
26
    public function setRoutes($routes)
27 1
    {
28 1
        foreach ($routes as $route) {
29
            $this->addRoute($route);
30 1
        }
31
    }
32
33
    /**
34
     * @param Route $route
35 1
     */
36
    public function prependRoute($route)
37 1
    {
38 1
        $routes = $this->all();
39 1
        $this->addRoute($route);
40 1
        $this->setRoutes($routes);
41
    }
42
43
    /**
44
     * @param $route
45
     * @return bool
46
     */
47
    public function has($route)
48
    {
49
        $name = $route instanceof Route ? $route->getName() : $route;
50
51
        return $this->get($name) instanceof Route;
52
    }
53
54
    /**
55
     * @param $route
56
     * @return Route|\Symfony\Component\Routing\Route|null
57 2
     */
58
    public function get($route): ?\Symfony\Component\Routing\Route
59 2
    {
60 2
        $name = $route instanceof Route ? $route->getName() : $route;
61
        return parent::get($name);
62
    }
63
64
65
    /**
66
     * @param Route $route
67
     * @param null $name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $name is correct as it would always require null to be passed?
Loading history...
68
     * @return
69 4
     */
70
    public function addRoute($route, $name = null)
71 4
    {
72
        if ($name) {
0 ignored issues
show
$name is of type null, thus it always evaluated to false.
Loading history...
73
            $route->setName($name);
74 4
        } else {
75
            $name = $route->getName();
76 4
        }
77
        return $this->add($name, $route);
0 ignored issues
show
It seems like add() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

77
        return $this->/** @scrutinizer ignore-call */ add($name, $route);
Loading history...
78
    }
79
}
80