Passed
Push — master ( 71b494...4cbbee )
by Anatoly
01:42
created

ZendBench::benchZendMatch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 41
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 23
nc 2
nop 0
dl 0
loc 41
rs 9.552
c 0
b 0
f 0
1
<?php
2
3
namespace Sunrise\Http\Router\Benchs;
4
5
use Sunrise\Http\ServerRequest\ServerRequestFactory;
6
use Zend\Psr7Bridge\Psr7ServerRequest;
0 ignored issues
show
Bug introduced by
The type Zend\Psr7Bridge\Psr7ServerRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Zend\Router\Http\TreeRouteStack;
0 ignored issues
show
Bug introduced by
The type Zend\Router\Http\TreeRouteStack was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
/**
10
 * @BeforeMethods({"init"})
11
 */
12
class ZendBench
13
{
14
	protected $maxRoutes = 1000;
15
	protected $request;
16
17
	public function init()
18
	{
19
		$uri = \sprintf('/route/%d', $this->maxRoutes);
20
21
		$this->request = (new ServerRequestFactory)
22
		->createServerRequest('GET', $uri);
23
	}
24
25
	/**
26
	 * @Warmup(1)
27
	 * @Revs(10)
28
	 * @Iterations(100)
29
	 */
30
	public function benchZendMatch()
31
	{
32
		$router = new TreeRouteStack();
33
34
		for ($i = 1; $i <= $this->maxRoutes; $i++)
35
		{
36
			$id = \sprintf('route:%d', $i);
37
			$path = \sprintf('/route/%d', $i);
38
39
			/**
40
			 * @link https://github.com/zendframework/zend-expressive-zendrouter/blob/master/src/ZendRouter.php
41
			 */
42
			$router->addRoute($id, [
43
				'type' => 'segment',
44
				'options' => [
45
					'route' => $path,
46
				],
47
				'may_terminate' => false,
48
				'child_routes' => [
49
					'GET' => [
50
						'type' => 'method',
51
						'options' => [
52
							'verb' => 'GET',
53
						],
54
					],
55
					'method_not_allowed'=> [
56
						'type' => 'regex',
57
						'priority' => -1,
58
						'options' => [
59
							'regex' => '',
60
							'defaults' => [
61
								'method_not_allowed' => $path,
62
							],
63
							'spec' => '',
64
						],
65
					],
66
				],
67
			]);
68
		}
69
70
		$router->match(Psr7ServerRequest::toZend($this->request, true));
71
	}
72
}
73