Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernize code and bump all dev dependencies #8

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading