GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch master (5e9c27)
by Dmitry
121:16 queued 119:02
created

Handlersocketi   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 156
Duplicated Lines 34.62 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 22
c 3
b 2
f 0
lcom 1
cbo 1
dl 54
loc 156
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getReadSocket() 0 11 2
A getWriteSocket() 0 11 2
A fetchArray() 0 17 4
B fetchAll() 11 24 5
A delete() 14 14 2
A insert() 0 12 1
A update() 0 16 2
A increment() 14 14 2
A decrement() 15 15 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
// Copyright (c) Dmitry Kosenkov,  All rights reserved.
4
5
namespace HSAL\Driver;
6
7
use \HSAL\HSAL;
8
use \HSAL\Driver;
9
use \HSAL\DriverInterface;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, HSAL\Driver\DriverInterface.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
11
class Handlersocketi extends Driver implements DriverInterface
12
{
13
	private $hsr;	
14
	private $hsr_connected = FALSE;
15
16
	private $hsw;
17
	private $hsw_connected = FALSE;
18
19
	const PORT_READ = 9998;
20
	const PORT_WRITE = 9999;
21
22
	protected function getReadSocket()
23
	{
24
		if (!$this->hsr_connected)
25
		{
26
			$this->hsr = new \HandlerSocketi($this->host, self::PORT_READ);
27
28
			$this->hsr_connected = TRUE;
29
		}
30
31
		return $this->hsr;
32
	}
33
34
	protected function getWriteSocket()
35
	{
36
		if (!$this->hsw_connected)
37
		{
38
			$this->hsw = new \HandlerSocketi($this->host, self::PORT_WRITE);
39
40
			$this->hsw_connected = TRUE;
41
		}
42
43
		return $this->hsw;
44
	}
45
46
47
	public function fetchArray($table, Array $fields, $index, Array $condition, $operator)
48
	{
49
		$hs = $this->getReadSocket();
50
51
		list($database, $table) = $this->getTableDatabase($table);
52
53
		if ($index == HSAL::INDEX_PRIMARY) $index = 'PRIMARY';
54
55
		$index = $hs->openIndex($database, $table, $fields, ['index' => $index]);
56
57
		$result = $index->find([$operator => $condition]);
58
59
		if (!empty($result) && is_array($result))
60
			return $result[0];
61
		else
62
			return FALSE;
63
	}
64
65
	public function fetchAll($table, Array $fields, $index, Array $condition, $operator, $limit, $offset)
66
	{
67
		$hs = $this->getReadSocket();
68
69
		list($database, $table) = $this->getTableDatabase($table);
70
71
		if ($index == HSAL::INDEX_PRIMARY) $index = 'PRIMARY';
72
73
		$index = $hs->openIndex($database, $table, $fields, ['index' => $index]);
74
75
		$result = $index->find([$operator => $condition], ['limit' => $limit, 'offset' => $offset]);
76
77 View Code Duplication
		if (!empty($result) && is_array($result))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
78
		{
79
			foreach ($result as $key => $arr) 
80
			{
81
				$result[$key] = array_combine($fields, $arr);
82
			}
83
84
			return $result;
85
		}
86
		else
87
			return FALSE;
88
	}
89
90 View Code Duplication
	public function delete($table, $index, Array $condition, $operator)
0 ignored issues
show
Duplication introduced by
This method 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...
91
	{
92
		$hs = $this->getWriteSocket();
93
94
		list($database, $table) = $this->getTableDatabase($table);
95
96
		if ($index == HSAL::INDEX_PRIMARY) $index = 'PRIMARY';
97
98
		$index = $hs->openIndex($database, $table, [], ['index' => $index]);
99
100
		$result = $index->remove([$operator => $condition]);
101
102
		return (bool)$result;
103
	}
104
105
	public function insert($table, Array $values)
106
	{
107
		$hs = $this->getWriteSocket();
108
109
		list($database, $table) = $this->getTableDatabase($table);
110
111
		$index = $hs->openIndex($database, $table, array_keys($values));
112
113
		$result = $index->insert(array_values($values));
114
115
		return (bool)$result;
116
	}
117
118
	public function update($table, Array $values, $index, Array $condition, $operator)
119
	{
120
		$hs = $this->getWriteSocket();
121
122
		list($database, $table) = $this->getTableDatabase($table);
123
124
		if ($index == HSAL::INDEX_PRIMARY) $index = 'PRIMARY';
0 ignored issues
show
Unused Code introduced by
$index is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
125
126
		$fields = array_keys($values);
0 ignored issues
show
Unused Code introduced by
$fields is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
127
128
		$index = $hs->openIndex($database, $table, array_keys($values));
129
130
		$result = $index->update([$operator => $condition], array_values($values));
131
132
		return (bool)$result;
133
	}
134
135 View Code Duplication
	public function increment($table, $field, $index, Array $condition, $operator, $increment)
0 ignored issues
show
Duplication introduced by
This method 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...
136
	{
137
		$hs = $this->getWriteSocket();
138
139
		list($database, $table) = $this->getTableDatabase($table);
140
141
		if ($index == HSAL::INDEX_PRIMARY) $index = 'PRIMARY';
0 ignored issues
show
Unused Code introduced by
$index is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
142
143
		$index = $hs->openIndex($database, $table, [$field]);
144
145
		$result = $index->update([$operator => $condition], ['+' => $increment]);
146
147
		return (bool)$result;
148
	}
149
150 View Code Duplication
	public function decrement($table, $field, $index, Array $condition, $operator, $decrement)
0 ignored issues
show
Duplication introduced by
This method 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...
151
	{
152
153
		$hs = $this->getWriteSocket();
154
155
		list($database, $table) = $this->getTableDatabase($table);
156
157
		if ($index == HSAL::INDEX_PRIMARY) $index = 'PRIMARY';
0 ignored issues
show
Unused Code introduced by
$index is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
158
159
		$index = $hs->openIndex($database, $table, [$field]);
160
161
		$result = $index->update([$operator => $condition], ['-' => $decrement]);
162
163
		return (bool)$result;
164
	}
165
166
}