diff --git a/Dockerfile b/Dockerfile index c024c6c..20c865d 100755 --- a/Dockerfile +++ b/Dockerfile @@ -8,11 +8,11 @@ COPY composer.json /usr/local/src/ RUN composer install --ignore-platform-reqs --optimize-autoloader \ --no-plugins --no-scripts --prefer-dist -FROM php:8.3-cli-alpine AS compile +FROM php:8.4-cli-alpine AS compile ENV PHP_REDIS_VERSION=6.1.0 \ - PHP_SWOOLE_VERSION=v5.1.3 \ - PHP_MONGO_VERSION=1.20.0 + PHP_SWOOLE_VERSION=v6.0.2 \ + PHP_MONGO_VERSION=2.1.1 RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone @@ -67,9 +67,9 @@ RUN echo "opcache.enable_cli=1" >> $PHP_INI_DIR/php.ini RUN echo "memory_limit=1024M" >> $PHP_INI_DIR/php.ini COPY --from=composer /usr/local/src/vendor /usr/src/code/vendor -COPY --from=swoole /usr/local/lib/php/extensions/no-debug-non-zts-20230831/swoole.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/ -COPY --from=redis /usr/local/lib/php/extensions/no-debug-non-zts-20230831/redis.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/ -COPY --from=mongodb /usr/local/lib/php/extensions/no-debug-non-zts-20230831/mongodb.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/ +COPY --from=swoole /usr/local/lib/php/extensions/no-debug-non-zts-20240924/swoole.so /usr/local/lib/php/extensions/no-debug-non-zts-20240924/ +COPY --from=redis /usr/local/lib/php/extensions/no-debug-non-zts-20240924/redis.so /usr/local/lib/php/extensions/no-debug-non-zts-20240924/ +COPY --from=mongodb /usr/local/lib/php/extensions/no-debug-non-zts-20240924/mongodb.so /usr/local/lib/php/extensions/no-debug-non-zts-20240924/ # Add Source Code COPY . /usr/src/code diff --git a/composer.json b/composer.json index 7d24f07..75ec221 100755 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "test": "./vendor/bin/phpunit --configuration phpunit.xml --debug" }, "require": { - "php": ">=8.3", + "php": ">=8.4", "utopia-php/telemetry": "0.1.*" }, "require-dev": { @@ -39,7 +39,7 @@ }, "config": { "platform": { - "php": "8.3" + "php": "8.4" }, "allow-plugins": { "php-http/discovery": false, diff --git a/src/Pools/Pool.php b/src/Pools/Pool.php index e374d38..65d6937 100644 --- a/src/Pools/Pool.php +++ b/src/Pools/Pool.php @@ -13,16 +13,6 @@ */ class Pool { - /** - * @var string - */ - protected string $name; - - /** - * @var int - */ - protected int $size = 0; - /** * @var callable */ @@ -72,12 +62,10 @@ class Pool * @param int $size * @param callable(): TResource $init */ - public function __construct(string $name, int $size, callable $init) + public function __construct(protected string $name, protected int $size, callable $init) { - $this->name = $name; - $this->size = $size; $this->init = $init; - $this->pool = array_fill(0, $size, true); + $this->pool = array_fill(0, $this->size, true); $this->setTelemetry(new NoTelemetry()); } @@ -313,7 +301,7 @@ public function count(): int * @param Connection|null $connection * @return $this */ - public function reclaim(Connection $connection = null): static + public function reclaim(?Connection $connection = null): static { if ($connection !== null) { $this->push($connection); @@ -331,7 +319,7 @@ public function reclaim(Connection $connection = null): static * @param Connection|null $connection * @return $this */ - public function destroy(Connection $connection = null): static + public function destroy(?Connection $connection = null): static { try { if ($connection !== null) { diff --git a/tests/Pools/ConnectionTest.php b/tests/Pools/ConnectionTest.php index 93bf1a0..1a8a126 100644 --- a/tests/Pools/ConnectionTest.php +++ b/tests/Pools/ConnectionTest.php @@ -14,6 +14,7 @@ class ConnectionTest extends TestCase */ protected Connection $object; + #[\Override] public function setUp(): void { $this->object = new Connection('x'); @@ -53,9 +54,7 @@ public function testSetResource(): void public function testSetPool(): void { - $pool = new Pool('test', 1, function () { - return 'x'; - }); + $pool = new Pool('test', 1, fn () => 'x'); $this->assertNull($this->object->getPool()); $this->assertInstanceOf(Connection::class, $this->object->setPool($pool)); @@ -63,9 +62,7 @@ public function testSetPool(): void public function testGetPool(): void { - $pool = new Pool('test', 1, function () { - return 'x'; - }); + $pool = new Pool('test', 1, fn () => 'x'); $this->assertNull($this->object->getPool()); $this->assertInstanceOf(Connection::class, $this->object->setPool($pool)); @@ -82,9 +79,7 @@ public function testGetPool(): void public function testReclaim(): void { - $pool = new Pool('test', 2, function () { - return 'x'; - }); + $pool = new Pool('test', 2, fn () => 'x'); $this->assertEquals(2, $pool->count()); diff --git a/tests/Pools/GroupTest.php b/tests/Pools/GroupTest.php index d8bc8b9..de1c7ec 100644 --- a/tests/Pools/GroupTest.php +++ b/tests/Pools/GroupTest.php @@ -11,6 +11,7 @@ class GroupTest extends TestCase { protected Group $object; + #[\Override] public function setUp(): void { $this->object = new Group(); @@ -18,18 +19,14 @@ public function setUp(): void public function testAdd(): void { - $this->object->add(new Pool('test', 1, function () { - return 'x'; - })); + $this->object->add(new Pool('test', 1, fn () => 'x')); $this->assertInstanceOf(Pool::class, $this->object->get('test')); } public function testGet(): void { - $this->object->add(new Pool('test', 1, function () { - return 'x'; - })); + $this->object->add(new Pool('test', 1, fn () => 'x')); $this->assertInstanceOf(Pool::class, $this->object->get('test')); @@ -40,9 +37,7 @@ public function testGet(): void public function testRemove(): void { - $this->object->add(new Pool('test', 1, function () { - return 'x'; - })); + $this->object->add(new Pool('test', 1, fn () => 'x')); $this->assertInstanceOf(Pool::class, $this->object->get('test')); @@ -55,9 +50,7 @@ public function testRemove(): void public function testReset(): void { - $this->object->add(new Pool('test', 5, function () { - return 'x'; - })); + $this->object->add(new Pool('test', 5, fn () => 'x')); $this->assertEquals(5, $this->object->get('test')->count()); @@ -74,9 +67,7 @@ public function testReset(): void public function testReconnectAttempts(): void { - $this->object->add(new Pool('test', 5, function () { - return 'x'; - })); + $this->object->add(new Pool('test', 5, fn () => 'x')); $this->assertEquals(3, $this->object->get('test')->getReconnectAttempts()); @@ -87,9 +78,7 @@ public function testReconnectAttempts(): void public function testReconnectSleep(): void { - $this->object->add(new Pool('test', 5, function () { - return 'x'; - })); + $this->object->add(new Pool('test', 5, fn () => 'x')); $this->assertEquals(1, $this->object->get('test')->getReconnectSleep()); @@ -113,7 +102,7 @@ public function testUse(): void $this->assertEquals(1, $pool3->count()); // @phpstan-ignore argument.type - $this->object->use(['pool1', 'pool3'], function ($one, $three) use ($pool1, $pool2, $pool3) { + $this->object->use(['pool1', 'pool3'], function ($one, $three) use ($pool1, $pool2, $pool3): void { $this->assertEquals('1', $one); $this->assertEquals('3', $three); diff --git a/tests/Pools/PoolTest.php b/tests/Pools/PoolTest.php index 33e5f0f..f0e4a8b 100644 --- a/tests/Pools/PoolTest.php +++ b/tests/Pools/PoolTest.php @@ -15,11 +15,10 @@ class PoolTest extends TestCase */ protected Pool $object; + #[\Override] public function setUp(): void { - $this->object = new Pool('test', 5, function () { - return 'x'; - }); + $this->object = new Pool('test', 5, fn () => 'x'); } public function testGetName(): void @@ -112,7 +111,7 @@ public function testPop(): void public function testUse(): void { $this->assertEquals(5, $this->object->count()); - $this->object->use(function ($resource) { + $this->object->use(function ($resource): void { $this->assertEquals(4, $this->object->count()); $this->assertEquals('x', $resource); }); @@ -267,7 +266,7 @@ public function testTelemetry(): void $telemetry = new TestTelemetry(); $this->object->setTelemetry($telemetry); - $allocate = function (int $amount, callable $assertion) { + $allocate = function (int $amount, callable $assertion): void { $connections = []; for ($i = 0; $i < $amount; $i++) { $connections[] = $this->object->pop(); @@ -282,7 +281,7 @@ public function testTelemetry(): void $this->assertEquals(5, $this->object->count()); - $allocate(3, function () use ($telemetry) { + $allocate(3, function () use ($telemetry): void { $this->assertEquals([1, 2, 3], $telemetry->gauges['pool.connection.open.count']->values); $this->assertEquals([1, 2, 3], $telemetry->gauges['pool.connection.active.count']->values); $this->assertEquals([0, 0, 0], $telemetry->gauges['pool.connection.idle.count']->values); @@ -290,7 +289,7 @@ public function testTelemetry(): void $this->assertEquals(5, $this->object->count()); - $allocate(1, function () use ($telemetry) { + $allocate(1, function () use ($telemetry): void { $this->assertEquals([1, 2, 3, 3, 3, 3, 3], $telemetry->gauges['pool.connection.open.count']->values); $this->assertEquals([1, 2, 3, 2, 1, 0, 1], $telemetry->gauges['pool.connection.active.count']->values); $this->assertEquals([0, 0, 0, 1, 2, 3, 2], $telemetry->gauges['pool.connection.idle.count']->values);