Completed
Push — master ( d41a26...1c5167 )
by Gabriel
04:02
created

MatchingBench   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 38.46 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 20
loc 52
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A benchStaticRoutesSymfony() 0 4 1
A init() 0 18 2
A benchStaticRoutesNip() 0 4 1
A benchDynamicRoutesNip() 0 4 1
A benchDynamicRoutesSymfony() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
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);
0 ignored issues
show
Deprecated Code introduced by
The function Nip\Router\Router::route() has been deprecated: Use matchRequest($request) ( Ignorable by Annotation )

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

25
        /** @scrutinizer ignore-deprecated */ $this->router->route($request);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
26
    }
27
28
    public function benchDynamicRoutesNip()
29
    {
30
        $request = Request::create('/999/posts/create');
31
        $this->router->route($request);
0 ignored issues
show
Deprecated Code introduced by
The function Nip\Router\Router::route() has been deprecated: Use matchRequest($request) ( Ignorable by Annotation )

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

31
        /** @scrutinizer ignore-deprecated */ $this->router->route($request);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
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
    public function init()
47
    {
48
        $this->router = new Router();
49
        $collection = $this->router->getRoutes();
50
51
        for ($i = 0; $i < 1000; ++$i) {
52
            RouteFactory::generateLiteralRoute(
53
                $collection,
54
                "index." . $i,
55
                Route::class,
56
                "",
57
                "/index" . $i);
58
59
            RouteFactory::generateStandardRoute(
60
                $collection,
61
                "index.standard" . $i,
62
                StandardRoute::class,
63
                "/".$i);
64
        }
65
    }
66
}
67