OnClientDisconnectedHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 34
loc 34
ccs 5
cts 8
cp 0.625
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A __invoke() 6 6 2

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
 * OnClientDisconnectedHandler.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
8
 * @package        iPublikuj:WebSocketSession!
9
 * @subpackage     Events
10
 * @since          1.0.0
11
 *
12
 * @date           19.02.17
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\WebSocketsSession\Events;
18
19
use Nette;
20
21
use IPub;
22
use IPub\WebSocketsSession\Session;
23
24
use IPub\WebSockets\Entities as WebSocketsEntities;
25
use IPub\WebSockets\Http as WebSocketsHttp;
26
27
/**
28
 * This component will allow access to session data from your Nette Framework website for each user connected
29
 *
30
 * @package        iPublikuj:WebSocketSession!
31
 * @subpackage     Events
32
 *
33
 * @author         Adam Kadlec <[email protected]>
34
 */
35 1 View Code Duplication
final class OnClientDisconnectedHandler
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...
36
{
37
	/**
38
	 * Implement nette smart magic
39
	 */
40 1
	use Nette\SmartObject;
41
42
	/**
43
	 * @var Session\SwitchableSession
44
	 */
45
	private $session;
46
47
	/**
48
	 * @param Session\SwitchableSession $session
49
	 */
50
	public function __construct(
51
		Session\SwitchableSession $session
52
	) {
53 1
		$this->session = $session;
54 1
	}
55
56
	/**
57
	 * @param WebSocketsEntities\Clients\IClient $client
58
	 * @param WebSocketsHttp\IRequest $httpRequest
59
	 *
60
	 * @return void
61
	 */
62
	public function __invoke(WebSocketsEntities\Clients\IClient $client, WebSocketsHttp\IRequest $httpRequest)
63
	{
64
		if ($this->session instanceof Session\SwitchableSession) {
65
			$this->session->detach();
66
		}
67
	}
68
}
69