RescueEvent   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 6
c 6
b 0
f 0
lcom 1
cbo 1
dl 84
loc 84
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A get_exception() 4 4 1
A set_exception() 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\Route;
13
14
use ICanBoogie\Event;
15
use ICanBoogie\HTTP\Request;
16
use ICanBoogie\HTTP\Response;
17
use ICanBoogie\Routing\Route;
18
19
/**
20
 * Event class for the `ICanBoogie\Routing\RouteDispatcher::rescue` event.
21
 *
22
 * Event hooks may use this event to _rescue_ a route by providing a suitable response, or
23
 * replace the exception to throw if the rescue fails.
24
 *
25
 * @property \Exception $exception
26
 * @property-read Request $request
27
 * @property Response|null $response
28
 */
29 View Code Duplication
class RescueEvent 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 = 'rescue';
32
33
	/**
34
	 * Reference to the exception to throw if the rescue fails.
35
	 *
36
	 * @var \Exception
37
	 */
38
	private $exception;
39
40
	/**
41
	 * @return \Exception
42
	 */
43
	protected function get_exception()
44
	{
45
		return $this->exception;
46
	}
47
48
	/**
49
	 * @param \Exception $exception
50
	 *
51
	 * @return \Exception
52
	 */
53
	protected function set_exception(\Exception $exception)
54
	{
55
		return $this->exception = $exception;
56
	}
57
58
	/**
59
	 * The request.
60
	 *
61
	 * @var Request
62
	 */
63
	private $request;
64
65
	/**
66
	 * @return Request
67
	 */
68
	protected function get_request()
69
	{
70
		return $this->request;
71
	}
72
73
	/**
74
	 * Reference to the response that rescue the route.
75
	 *
76
	 * @var Response
77
	 */
78
	private $response;
79
80
	/**
81
	 * @return Response|null
82
	 */
83
	protected function get_response()
84
	{
85
		return $this->response;
86
	}
87
88
	/**
89
	 * @param Response|null $response
90
	 */
91
	protected function set_response(Response $response = null)
92
	{
93
		$this->response = $response;
94
	}
95
96
	/**
97
	 * The event is constructed with the type {@link self::TYPE}.
98
	 *
99
	 * @param Route $target
100
	 * @param \Exception $exception Reference to the exception thrown while dispatching the route.
101
	 * @param Request $request
102
	 * @param Response|null $response
103
	 */
104
	public function __construct(Route $target, \Exception &$exception, Request $request, Response &$response = null)
105
	{
106
		$this->exception = &$exception;
107
		$this->request = $request;
108
		$this->response = &$response;
109
110
		parent::__construct($target, self::TYPE);
111
	}
112
}
113