From cb87b1cd9abef7d2e588640bc3edda707077bfa5 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Tue, 12 Dec 2017 21:39:51 -0600 Subject: [PATCH] Use default sizes as default values --- lib/Worker/DefaultPool.php | 13 +++++++------ test/Worker/AbstractPoolTest.php | 3 ++- test/Worker/ProcessPoolTest.php | 3 ++- test/Worker/ThreadPoolTest.php | 3 ++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/Worker/DefaultPool.php b/lib/Worker/DefaultPool.php index 0deda23..ceaf4cb 100644 --- a/lib/Worker/DefaultPool.php +++ b/lib/Worker/DefaultPool.php @@ -43,19 +43,20 @@ class DefaultPool implements Pool { /** * Creates a new worker pool. * - * @param int|null $minSize The minimum number of workers the pool should spawn. + * @param int $minSize The minimum number of workers the pool should spawn. * Defaults to `Pool::DEFAULT_MIN_SIZE`. - * @param int|null $maxSize The maximum number of workers the pool should spawn. + * @param int $maxSize The maximum number of workers the pool should spawn. * Defaults to `Pool::DEFAULT_MAX_SIZE`. * @param \Amp\Parallel\Worker\WorkerFactory|null $factory A worker factory to be used to create * new workers. * * @throws \Error */ - public function __construct(int $minSize = null, int $maxSize = null, WorkerFactory $factory = null) { - $minSize = $minSize ?: self::DEFAULT_MIN_SIZE; - $maxSize = $maxSize ?: self::DEFAULT_MAX_SIZE; - + public function __construct( + int $minSize = self::DEFAULT_MIN_SIZE, + int $maxSize = self::DEFAULT_MAX_SIZE, + WorkerFactory $factory = null + ) { if ($minSize < 0) { throw new \Error('Minimum size must be a non-negative integer.'); } diff --git a/test/Worker/AbstractPoolTest.php b/test/Worker/AbstractPoolTest.php index 3b3c5b8..bb4c638 100644 --- a/test/Worker/AbstractPoolTest.php +++ b/test/Worker/AbstractPoolTest.php @@ -3,6 +3,7 @@ namespace Amp\Parallel\Test\Worker; use Amp\Loop; +use Amp\Parallel\Worker\Pool; use Amp\PHPUnit\TestCase; abstract class AbstractPoolTest extends TestCase { @@ -12,7 +13,7 @@ abstract class AbstractPoolTest extends TestCase { * * @return \Amp\Parallel\Worker\Pool */ - abstract protected function createPool($min = null, $max = null); + abstract protected function createPool($min = null, $max = null): Pool; public function testIsRunning() { Loop::run(function () { diff --git a/test/Worker/ProcessPoolTest.php b/test/Worker/ProcessPoolTest.php index 422b46d..4ed95b2 100644 --- a/test/Worker/ProcessPoolTest.php +++ b/test/Worker/ProcessPoolTest.php @@ -3,6 +3,7 @@ namespace Amp\Parallel\Test\Worker; use Amp\Parallel\Worker\DefaultPool; +use Amp\Parallel\Worker\Pool; use Amp\Parallel\Worker\WorkerFactory; use Amp\Parallel\Worker\WorkerProcess; @@ -10,7 +11,7 @@ use Amp\Parallel\Worker\WorkerProcess; * @group process */ class ProcessPoolTest extends AbstractPoolTest { - protected function createPool($min = null, $max = null) { + protected function createPool($min = Pool::DEFAULT_MIN_SIZE, $max =Pool::DEFAULT_MAX_SIZE): Pool { $factory = $this->createMock(WorkerFactory::class); $factory->method('create')->will($this->returnCallback(function () { return new WorkerProcess; diff --git a/test/Worker/ThreadPoolTest.php b/test/Worker/ThreadPoolTest.php index acbabab..6688e6d 100644 --- a/test/Worker/ThreadPoolTest.php +++ b/test/Worker/ThreadPoolTest.php @@ -3,6 +3,7 @@ namespace Amp\Parallel\Test\Worker; use Amp\Parallel\Worker\DefaultPool; +use Amp\Parallel\Worker\Pool; use Amp\Parallel\Worker\WorkerFactory; use Amp\Parallel\Worker\WorkerThread; @@ -11,7 +12,7 @@ use Amp\Parallel\Worker\WorkerThread; * @requires extension pthreads */ class ThreadPoolTest extends AbstractPoolTest { - protected function createPool($min = null, $max = null) { + protected function createPool($min = Pool::DEFAULT_MIN_SIZE, $max = Pool::DEFAULT_MAX_SIZE): Pool { $factory = $this->createMock(WorkerFactory::class); $factory->method('create')->will($this->returnCallback(function () { return new WorkerThread;