Skip to content

Commit 345748b

Browse files
authored
modernzie code and bump all dev dependencies (#8)
1 parent b712787 commit 345748b

File tree

4 files changed

+16
-28
lines changed

4 files changed

+16
-28
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
"php": ">=8.2"
2121
},
2222
"require-dev": {
23-
"php-cs-fixer/shim": "^3.48",
24-
"phpstan/phpstan": "^1.10",
25-
"phpunit/phpunit": "^10.5"
23+
"php-cs-fixer/shim": "^3.64",
24+
"phpstan/phpstan": "^2.0",
25+
"phpunit/phpunit": "^11.4"
2626
},
2727
"autoload": {
2828
"psr-4": {

src/Await.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Akondas\Exspecto\Exception\TimeoutException;
88

9-
class Await
9+
final class Await
1010
{
1111
private int $waitTime;
1212
private int $pollInterval;

src/Duration.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,27 @@
44

55
namespace Akondas\Exspecto;
66

7-
class Duration
7+
final class Duration
88
{
99
public const SECONDS = 'seconds';
1010
public const MILLISECONDS = 'milliseconds';
1111

12-
/**
13-
* @param int|float $seconds
14-
*/
15-
public static function seconds($seconds): int
12+
public static function seconds(int|float $seconds): int
1613
{
1714
return (int) ($seconds * 1_000_000);
1815
}
1916

20-
/**
21-
* @param int|float $milliseconds
22-
*/
23-
public static function milliseconds($milliseconds): int
17+
public static function milliseconds(int|float $milliseconds): int
2418
{
2519
return (int) ($milliseconds * 1_000);
2620
}
2721

28-
/**
29-
* @param int|float $duration
30-
*/
31-
public static function fromUnit($duration, string $unit): int
22+
public static function fromUnit(int|float $duration, string $unit): int
3223
{
33-
if (!method_exists(self::class, $unit)) {
34-
throw new \InvalidArgumentException('Unknown unit');
35-
}
36-
37-
return self::{$unit}($duration);
24+
return match ($unit) {
25+
'seconds' => self::seconds($duration),
26+
'milliseconds' => self::milliseconds($duration),
27+
default => throw new \InvalidArgumentException('Unknown unit'),
28+
};
3829
}
3930
}

tests/DurationTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
namespace Akondas\Exspecto\Tests;
66

77
use Akondas\Exspecto\Duration;
8+
use PHPUnit\Framework\Attributes\DataProvider;
89
use PHPUnit\Framework\TestCase;
910

1011
class DurationTest extends TestCase
1112
{
12-
/**
13-
* @param int|float $duration
14-
*
15-
* @dataProvider durationsProvider
16-
*/
17-
public function testFromUnit($duration, string $unit, int $expected): void
13+
#[DataProvider('durationsProvider')]
14+
public function testFromUnit(int|float $duration, string $unit, int $expected): void
1815
{
1916
self::assertEquals($expected, Duration::fromUnit($duration, $unit));
2017
}

0 commit comments

Comments
 (0)