File tree Expand file tree Collapse file tree 4 files changed +16
-28
lines changed
Expand file tree Collapse file tree 4 files changed +16
-28
lines changed Original file line number Diff line number Diff line change 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" : {
Original file line number Diff line number Diff line change 66
77use Akondas \Exspecto \Exception \TimeoutException ;
88
9- class Await
9+ final class Await
1010{
1111 private int $ waitTime ;
1212 private int $ pollInterval ;
Original file line number Diff line number Diff line change 44
55namespace 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}
Original file line number Diff line number Diff line change 55namespace Akondas \Exspecto \Tests ;
66
77use Akondas \Exspecto \Duration ;
8+ use PHPUnit \Framework \Attributes \DataProvider ;
89use PHPUnit \Framework \TestCase ;
910
1011class 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 }
You can’t perform that action at this time.
0 commit comments