diff --git a/composer.json b/composer.json index eb6ec95..66c87aa 100644 --- a/composer.json +++ b/composer.json @@ -20,9 +20,9 @@ "php": ">=8.2" }, "require-dev": { - "php-cs-fixer/shim": "^3.48", - "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^10.5" + "php-cs-fixer/shim": "^3.64", + "phpstan/phpstan": "^2.0", + "phpunit/phpunit": "^11.4" }, "autoload": { "psr-4": { diff --git a/src/Await.php b/src/Await.php index 8abac46..6efded1 100644 --- a/src/Await.php +++ b/src/Await.php @@ -6,7 +6,7 @@ use Akondas\Exspecto\Exception\TimeoutException; -class Await +final class Await { private int $waitTime; private int $pollInterval; diff --git a/src/Duration.php b/src/Duration.php index 6752201..d18d614 100644 --- a/src/Duration.php +++ b/src/Duration.php @@ -4,36 +4,27 @@ namespace Akondas\Exspecto; -class Duration +final class Duration { public const SECONDS = 'seconds'; public const MILLISECONDS = 'milliseconds'; - /** - * @param int|float $seconds - */ - public static function seconds($seconds): int + public static function seconds(int|float $seconds): int { return (int) ($seconds * 1_000_000); } - /** - * @param int|float $milliseconds - */ - public static function milliseconds($milliseconds): int + public static function milliseconds(int|float $milliseconds): int { return (int) ($milliseconds * 1_000); } - /** - * @param int|float $duration - */ - public static function fromUnit($duration, string $unit): int + public static function fromUnit(int|float $duration, string $unit): int { - if (!method_exists(self::class, $unit)) { - throw new \InvalidArgumentException('Unknown unit'); - } - - return self::{$unit}($duration); + return match ($unit) { + 'seconds' => self::seconds($duration), + 'milliseconds' => self::milliseconds($duration), + default => throw new \InvalidArgumentException('Unknown unit'), + }; } } diff --git a/tests/DurationTest.php b/tests/DurationTest.php index d041bb7..154f55b 100644 --- a/tests/DurationTest.php +++ b/tests/DurationTest.php @@ -5,16 +5,13 @@ namespace Akondas\Exspecto\Tests; use Akondas\Exspecto\Duration; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class DurationTest extends TestCase { - /** - * @param int|float $duration - * - * @dataProvider durationsProvider - */ - public function testFromUnit($duration, string $unit, int $expected): void + #[DataProvider('durationsProvider')] + public function testFromUnit(int|float $duration, string $unit, int $expected): void { self::assertEquals($expected, Duration::fromUnit($duration, $unit)); }