Skip to content

Commit

Permalink
modernzie code and bump all dev dependencies (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas authored Nov 24, 2024
1 parent b712787 commit 345748b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/Await.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Akondas\Exspecto\Exception\TimeoutException;

class Await
final class Await
{
private int $waitTime;
private int $pollInterval;
Expand Down
27 changes: 9 additions & 18 deletions src/Duration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
};
}
}
9 changes: 3 additions & 6 deletions tests/DurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit 345748b

Please sign in to comment.