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.

HSPHP   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 159
Duplicated Lines 44.65 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 1
dl 71
loc 159
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getReadSocket() 0 13 2
A getWriteSocket() 0 13 2
A fetchArray() 15 15 2
A fetchAll() 11 23 3
A delete() 15 15 2
A insert() 0 15 2
A update() 0 18 2
A increment() 15 15 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;
10
11
12
class HSPHP extends Driver implements DriverInterface
13
{
14
	private $hsr;	
15
	private $hsr_connected = FALSE;
16
17
	private $hsw;
18
	private $hsw_connected = FALSE;
19
20
	protected function getReadSocket()
21
	{
22
		if (!$this->hsr_connected)
23
		{
24
			$this->hsr = new \HSPHP\ReadSocket();
25
26
			$this->hsr->connect($this->host, $this->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 \HSPHP\WriteSocket();
39
40
			$this->hsw->connect($this->host, $this->port_write);
41
42
			$this->hsw_connected = TRUE;
43
		}
44
45
		return $this->hsw;
46
	}
47
48 View Code Duplication
	public function fetchArray($table, Array $fields, $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...
49
	{
50
		$hs = $this->getReadSocket();
51
52
		list($database, $table) = $this->getTableDatabase($table);
53
54
		$idx = $hs->getIndexId($database, $table, $index, implode(',',$fields));
55
		$hs->select($idx, $operator, $condition);
56
		$result = $hs->readResponse();
57
58
		if (!empty($result))
59
			return $result[0];
60
		else
61
			return FALSE;
62
	}
63
64
	public function fetchAll($table, Array $fields, $index, Array $condition, $operator, $limit, $offset)
65
	{
66
		$hs = $this->getReadSocket();
67
68
		list($database, $table) = $this->getTableDatabase($table);
69
70
		$idx = $hs->getIndexId($database, $table, $index, implode(',', $fields));
71
		$hs->select($idx, $operator, $condition, $limit, $offset);
72
73
		$result = $hs->readResponse();
74
75 View Code Duplication
		if (!empty($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...
76
		{
77
			foreach ($result as $key => $arr) 
78
			{
79
				$result[$key] = array_combine($fields, $arr);
80
			}
81
82
			return $result;
83
		}
84
		else
85
			return FALSE;
86
	}
87
88 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...
89
	{
90
		$hs = $this->getWriteSocket();
91
92
		list($database, $table) = $this->getTableDatabase($table);
93
94
		$idx = $hs->getIndexId($database, $table, $index, '');
95
		$hs->delete($idx, $operator, $condition);
96
		$result = $hs->readResponse();
97
98
		if (!empty($result))
99
			return (bool)$result[0][0];
100
		else
101
			return FALSE;
102
	}
103
104
	public function insert($table, Array $values)
105
	{
106
		$hs = $this->getWriteSocket();
107
108
		list($database, $table) = $this->getTableDatabase($table);
109
110
		$fields = array_keys($values);
111
112
		$idx = $hs->getIndexId($database, $table, '', implode(',',$fields));
113
		$hs->insert($idx, array_values($values));
114
115
		$result = $hs->readResponse();
116
117
		return is_array($result) ? TRUE : FALSE;
118
	}
119
120
	public function update($table, Array $values, $index, Array $condition, $operator)
121
	{
122
		$hs = $this->getWriteSocket();
123
124
		list($database, $table) = $this->getTableDatabase($table);
125
126
		$fields = array_keys($values);
127
128
		$idx = $hs->getIndexId($database, $table, $index, implode(',', $fields));
129
		$hs->update($idx, $operator, $condition, array_values($values));
130
131
		$result = $hs->readResponse();
132
133
		if (!empty($result))
134
			return (bool)$result[0][0];
135
		else
136
			return FALSE;
137
	}
138
139 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...
140
	{
141
		$hs = $this->getWriteSocket();
142
143
		list($database, $table) = $this->getTableDatabase($table);
144
145
		$idx = $hs->getIndexId($database, $table, $index, [$field]);
146
		$hs->increment($idx, $operator, $condition, [$increment]);
147
		$result = $hs->readResponse();
148
149
		if (!empty($result))
150
			return (bool)$result[0][0];
151
		else
152
			return FALSE;
153
	}
154
155 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...
156
	{
157
		$hs = $this->getWriteSocket();
158
159
		list($database, $table) = $this->getTableDatabase($table);
160
161
		$idx = $hs->getIndexId($database, $table, $index, [$field]);
162
		$hs->decrement($idx, $operator, $condition, [$decrement]);
163
		$result = $hs->readResponse();
164
165
		if (!empty($result))
166
			return (bool)$result[0][0];
167
		else
168
			return FALSE;
169
	}
170
}