Skip to content

Commit 6da1f2f

Browse files
authored
Simplify SwooleTable class structure and remove version checks (#1000)
1 parent 515ef6a commit 6da1f2f

File tree

1 file changed

+25
-68
lines changed

1 file changed

+25
-68
lines changed

src/Tables/SwooleTable.php

Lines changed: 25 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,78 +4,35 @@
44

55
use Swoole\Table;
66

7-
if (SWOOLE_VERSION_ID === 40804 || SWOOLE_VERSION_ID >= 50000) {
8-
class SwooleTable extends Table
7+
class SwooleTable extends Table
8+
{
9+
use Concerns\EnsuresColumnSizes;
10+
11+
/**
12+
* The table columns.
13+
*
14+
* @var array
15+
*/
16+
protected $columns;
17+
18+
/**
19+
* Set the data type and size of the columns.
20+
*/
21+
public function column(string $name, int $type, int $size = 0): bool
922
{
10-
use Concerns\EnsuresColumnSizes;
23+
$this->columns[$name] = [$type, $size];
1124

12-
/**
13-
* The table columns.
14-
*
15-
* @var array
16-
*/
17-
protected $columns;
18-
19-
/**
20-
* Set the data type and size of the columns.
21-
*/
22-
public function column(string $name, int $type, int $size = 0): bool
23-
{
24-
$this->columns[$name] = [$type, $size];
25-
26-
return parent::column($name, $type, $size);
27-
}
28-
29-
/**
30-
* Update a row of the table.
31-
*/
32-
public function set(string $key, array $values): bool
33-
{
34-
collect($values)
35-
->each($this->ensureColumnsSize());
36-
37-
return parent::set($key, $values);
38-
}
25+
return parent::column($name, $type, $size);
3926
}
40-
} else {
41-
class SwooleTable extends Table
42-
{
43-
use Concerns\EnsuresColumnSizes;
4427

45-
/**
46-
* The table columns.
47-
*
48-
* @var array
49-
*/
50-
protected $columns;
51-
52-
/**
53-
* Set the data type and size of the columns.
54-
*
55-
* @param string $name
56-
* @param int $type
57-
* @param int $size
58-
* @return void
59-
*/
60-
public function column($name, $type, $size = 0)
61-
{
62-
$this->columns[$name] = [$type, $size];
63-
64-
parent::column($name, $type, $size);
65-
}
66-
67-
/**
68-
* Update a row of the table.
69-
*
70-
* @param string $key
71-
* @return void
72-
*/
73-
public function set($key, array $values)
74-
{
75-
collect($values)
76-
->each($this->ensureColumnsSize());
28+
/**
29+
* Update a row of the table.
30+
*/
31+
public function set(string $key, array $values): bool
32+
{
33+
collect($values)
34+
->each($this->ensureColumnsSize());
7735

78-
parent::set($key, $values);
79-
}
36+
return parent::set($key, $values);
8037
}
8138
}

0 commit comments

Comments
 (0)