Test Setup Failed
Push — master ( fc6567...89d4a6 )
by Gabriel
07:58
created

MatchingBench::benchDynamicRoutesNip()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Nip\Request;
4
use Nip\Router\Route\Route;
5
use Nip\Router\RouteFactory;
6
use Nip\Router\Router;
7
use Nip\Router\Tests\Fixtures\Application\Library\Router\Route\StandardRoute;
8
9
/**
10
 * Class MatchingBench
11
 * @Iterations(5)
12
 * @Revs(100)
13
 * @BeforeMethods({"init"})
14
 */
15
class MatchingBench
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
16
{
17
    /**
18
     * @var Router
19
     */
20
    protected $router;
21
22
    public function benchStaticRoutesNip()
23
    {
24
        $request = Request::create('/index999');
25
        $this->router->route($request);
26
    }
27
28
    public function benchDynamicRoutesNip()
29
    {
30
        $request = Request::create('/999/posts/create');
31
        $this->router->route($request);
32
    }
33
34
    public function benchStaticRoutesSymfony()
35
    {
36
        $request = Request::create('/index999');
37
        $this->router->matchRequest($request);
38
    }
39
40
    public function benchDynamicRoutesSymfony()
41
    {
42
        $request = Request::create('/999/posts/create');
43
        $this->router->matchRequest($request);
44
    }
45
46 View Code Duplication
    public function init()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        $this->router = new Router();
49
        $collection = $this->router->getRoutes();
50
51
        for ($i = 0; $i < 1000; ++$i) {
52
            RouteFactory::generateLiteralRoute(
53
                $collection,
0 ignored issues
show
Bug introduced by
It seems like $collection defined by $this->router->getRoutes() on line 49 can also be of type array<integer,object<Nip\Router\Route\Route>>; however, Nip\Router\RouteFactory::generateLiteralRoute() does only seem to accept object<Nip\Router\RouteCollection>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
54
                "index." . $i,
55
                Route::class,
56
                "",
57
                "/index" . $i);
58
59
            RouteFactory::generateStandardRoute(
60
                $collection,
0 ignored issues
show
Bug introduced by
It seems like $collection defined by $this->router->getRoutes() on line 49 can also be of type array<integer,object<Nip\Router\Route\Route>>; however, Nip\Router\RouteFactory::generateStandardRoute() does only seem to accept object<Nip\Router\RouteCollection>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
61
                "index.standard" . $i,
62
                StandardRoute::class,
63
                "/".$i);
64
        }
65
    }
66
}