BeforeDispatchEvent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 0
cbo 1
dl 74
loc 74
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get_route() 4 4 1
A get_request() 4 4 1
A get_response() 4 4 1
A set_response() 4 4 1
A __construct() 8 8 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
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ICanBoogie\Routing\RouteDispatcher;
13
14
use ICanBoogie\Event;
15
use ICanBoogie\HTTP\Request;
16
use ICanBoogie\HTTP\Response;
17
use ICanBoogie\Routing\RouteDispatcher;
18
use ICanBoogie\Routing\Route;
19
20
/**
21
 * Event class for the `ICanBoogie\Routing\RouteDispatcher::dispatch:before` event.
22
 *
23
 * Third parties may use this event to provide a response to the request before the route is
24
 * mapped. The event is usually used by third parties to redirect requests or provide cached
25
 * responses.
26
 *
27
 * @property-read Route $route
28
 * @property-read Request $request
29
 * @property Response $response
30
 */
31 View Code Duplication
class BeforeDispatchEvent extends Event
0 ignored issues
show
Duplication introduced by
This class 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...
32
{
33
	const TYPE = 'dispatch:before';
34
35
	/**
36
	 * The route.
37
	 *
38
	 * @var Route
39
	 */
40
	private $route;
41
42
	/**
43
	 * @return Route
44
	 */
45
	protected function get_route()
46
	{
47
		return $this->route;
48
	}
49
50
	/**
51
	 * The HTTP request.
52
	 *
53
	 * @var Request
54
	 */
55
	private $request;
56
57
	/**
58
	 * @return Request
59
	 */
60
	protected function get_request()
61
	{
62
		return $this->request;
63
	}
64
65
	/**
66
	 * Reference to the HTTP response.
67
	 *
68
	 * @var Response|null
69
	 */
70
	private $response;
71
72
	/**
73
	 * @return Response|null
74
	 */
75
	protected function get_response()
76
	{
77
		return $this->response;
78
	}
79
80
	/**
81
	 * @param Response|null $response
82
	 */
83
	protected function set_response(Response &$response = null)
84
	{
85
		$this->response = $response;
86
	}
87
88
	/**
89
	 * The event is constructed with the type {@link self::TYPE}.
90
	 *
91
	 * @param RouteDispatcher $target
92
	 * @param Route $route
93
	 * @param Request $request
94
	 * @param Response|null $response
95
	 */
96
	public function __construct(RouteDispatcher $target, Route $route, Request $request, Response &$response = null)
97
	{
98
		$this->route = $route;
99
		$this->request = $request;
100
		$this->response = &$response;
101
102
		parent::__construct($target, self::TYPE);
103
	}
104
}
105