Skip to content

Commit e47bc9c

Browse files
authored
Fix type declaration error of Swoole table (#452)
1 parent dc757dc commit e47bc9c

File tree

2 files changed

+82
-34
lines changed

2 files changed

+82
-34
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ jobs:
3131
tools: composer:v2
3232
coverage: none
3333

34+
- name: Show extension info
35+
run: |
36+
php --ri ${{ matrix.driver }}
37+
3438
- name: Install dependencies
3539
run: |
3640
composer require laravel/framework:"^8.35" --no-update

src/Tables/SwooleTable.php

Lines changed: 78 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,88 @@
44

55
use Swoole\Table;
66

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-
* @param string $name
22-
* @param int $type
23-
* @param int $size
24-
* @return void
25-
*/
26-
public function column($name, $type, $size = 0)
7+
if (SWOOLE_VERSION_ID === 40804 || SWOOLE_VERSION_ID >= 50000) {
8+
class SwooleTable extends Table
279
{
28-
$this->columns[$name] = [$type, $size];
10+
use Concerns\EnsuresColumnSizes;
2911

30-
parent::column($name, $type, $size);
31-
}
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+
* @param string $name
23+
* @param int $type
24+
* @param int $size
25+
* @return bool
26+
*/
27+
public function column(string $name, int $type, int $size = 0): bool
28+
{
29+
$this->columns[$name] = [$type, $size];
30+
31+
return parent::column($name, $type, $size);
32+
}
3233

33-
/**
34-
* Update a row of the table.
35-
*
36-
* @param string $key
37-
* @param array $values
38-
* @return void
39-
*/
40-
public function set($key, array $values)
34+
/**
35+
* Update a row of the table.
36+
*
37+
* @param string $key
38+
* @param array $values
39+
* @return bool
40+
*/
41+
public function set(string $key, array $values): bool
42+
{
43+
collect($values)
44+
->each($this->ensureColumnsSize());
45+
46+
return parent::set($key, $values);
47+
}
48+
}
49+
} else {
50+
class SwooleTable extends Table
4151
{
42-
collect($values)
43-
->each($this->ensureColumnsSize());
52+
use Concerns\EnsuresColumnSizes;
53+
54+
/**
55+
* The table columns.
56+
*
57+
* @var array
58+
*/
59+
protected $columns;
60+
61+
/**
62+
* Set the data type and size of the columns.
63+
*
64+
* @param string $name
65+
* @param int $type
66+
* @param int $size
67+
* @return void
68+
*/
69+
public function column($name, $type, $size = 0)
70+
{
71+
$this->columns[$name] = [$type, $size];
72+
73+
parent::column($name, $type, $size);
74+
}
75+
76+
/**
77+
* Update a row of the table.
78+
*
79+
* @param string $key
80+
* @param array $values
81+
* @return void
82+
*/
83+
public function set($key, array $values)
84+
{
85+
collect($values)
86+
->each($this->ensureColumnsSize());
4487

45-
parent::set($key, $values);
88+
parent::set($key, $values);
89+
}
4690
}
4791
}

0 commit comments

Comments
 (0)