DispatchEvent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
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 62
loc 62
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` event.
22
 *
23
 * Third parties may use this event to alter the response before it is returned by the dispatcher.
24
 *
25
 * @property-read Route $route
26
 * @property-read Request $request
27
 * @property Response $response
28
 */
29 View Code Duplication
class DispatchEvent 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...
30
{
31
	const TYPE = 'dispatch';
32
33
	/**
34
	 * The route.
35
	 *
36
	 * @var Route
37
	 */
38
	private $route;
39
40
	protected function get_route()
41
	{
42
		return $this->route;
43
	}
44
45
	/**
46
	 * The HTTP request.
47
	 *
48
	 * @var Request
49
	 */
50
	private $request;
51
52
	protected function get_request()
53
	{
54
		return $this->request;
55
	}
56
57
	/**
58
	 * Reference to the HTTP response.
59
	 *
60
	 * @var Response
61
	 */
62
	private $response;
63
64
	protected function get_response()
65
	{
66
		return $this->response;
67
	}
68
69
	protected function set_response(Response $response = null)
70
	{
71
		$this->response = $response;
72
	}
73
74
	/**
75
	 * The event is constructed with the type `dispatch`.
76
	 *
77
	 * @param RouteDispatcher $target
78
	 * @param Route $route
79
	 * @param Request $request
80
	 * @param Response|null $response
81
	 */
82
	public function __construct(RouteDispatcher $target, Route $route, Request $request, Response &$response = null)
83
	{
84
		$this->route = $route;
85
		$this->request = $request;
86
		$this->response = &$response;
87
88
		parent::__construct($target, self::TYPE);
89
	}
90
}
91