Skip to content

Commit

Permalink
Simplify SwooleTable class structure and remove version checks (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records authored Feb 18, 2025
1 parent 515ef6a commit 6da1f2f
Showing 1 changed file with 25 additions and 68 deletions.
93 changes: 25 additions & 68 deletions src/Tables/SwooleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,35 @@

use Swoole\Table;

if (SWOOLE_VERSION_ID === 40804 || SWOOLE_VERSION_ID >= 50000) {
class SwooleTable extends Table
class SwooleTable extends Table
{
use Concerns\EnsuresColumnSizes;

/**
* The table columns.
*
* @var array
*/
protected $columns;

/**
* Set the data type and size of the columns.
*/
public function column(string $name, int $type, int $size = 0): bool
{
use Concerns\EnsuresColumnSizes;
$this->columns[$name] = [$type, $size];

/**
* The table columns.
*
* @var array
*/
protected $columns;

/**
* Set the data type and size of the columns.
*/
public function column(string $name, int $type, int $size = 0): bool
{
$this->columns[$name] = [$type, $size];

return parent::column($name, $type, $size);
}

/**
* Update a row of the table.
*/
public function set(string $key, array $values): bool
{
collect($values)
->each($this->ensureColumnsSize());

return parent::set($key, $values);
}
return parent::column($name, $type, $size);
}
} else {
class SwooleTable extends Table
{
use Concerns\EnsuresColumnSizes;

/**
* The table columns.
*
* @var array
*/
protected $columns;

/**
* Set the data type and size of the columns.
*
* @param string $name
* @param int $type
* @param int $size
* @return void
*/
public function column($name, $type, $size = 0)
{
$this->columns[$name] = [$type, $size];

parent::column($name, $type, $size);
}

/**
* Update a row of the table.
*
* @param string $key
* @return void
*/
public function set($key, array $values)
{
collect($values)
->each($this->ensureColumnsSize());
/**
* Update a row of the table.
*/
public function set(string $key, array $values): bool
{
collect($values)
->each($this->ensureColumnsSize());

parent::set($key, $values);
}
return parent::set($key, $values);
}
}

0 comments on commit 6da1f2f

Please sign in to comment.