diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57a3293..5dbe965 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,8 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - php-version: ['7.4', '8.0'] + php-version: ['8.0', '8.1'] + dependencies: ['lowest', 'highest'] name: 'PHPUnit' steps: - name: Checkout @@ -19,17 +20,10 @@ jobs: php-version: ${{ matrix.php-version }} extensions: mbstring, intl coverage: xdebug - - name: Get Composer Cache Directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache dependencies - uses: actions/cache@v2 + - name: Composer + uses: "ramsey/composer-install@v2" with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - name: Install Dependencies - run: composer install + dependency-versions: ${{ matrix.dependencies }} - name: PHPUnit run: vendor/bin/phpunit --coverage-clover=coverage.clover - uses: codecov/codecov-action@v1 @@ -39,7 +33,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['7.4', '8.0'] + php-version: ['8.0', '8.1'] + dependencies: ['lowest', 'highest'] name: 'Psalm' steps: - name: Checkout @@ -49,24 +44,17 @@ jobs: with: php-version: ${{ matrix.php-version }} extensions: mbstring, intl - - name: Get Composer Cache Directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache dependencies - uses: actions/cache@v2 + - name: Composer + uses: "ramsey/composer-install@v2" with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - name: Install Dependencies - run: composer install + dependency-versions: ${{ matrix.dependencies }} - name: Psalm run: vendor/bin/psalm --shepherd cs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['7.4'] + php-version: ['8.0'] name: 'CS' steps: - name: Checkout @@ -76,16 +64,7 @@ jobs: with: php-version: ${{ matrix.php-version }} extensions: mbstring, intl - - name: Get Composer Cache Directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-${{ matrix.php-version }}-composer- - - name: Install Dependencies - run: composer install --no-progress + - name: Composer + uses: "ramsey/composer-install@v2" - name: CS - run: vendor/bin/php-cs-fixer fix --diff --dry-run --diff-format udiff + run: vendor/bin/php-cs-fixer fix --diff --dry-run diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 100% rename from .php_cs.dist rename to .php-cs-fixer.dist.php diff --git a/README.md b/README.md index 7d6608c..626e2c4 100644 --- a/README.md +++ b/README.md @@ -21,22 +21,16 @@ use Innmind\TimeWarp\{ Halt\Usleep, Halt, }; -use Innmind\TimeContinuum\{ - Clock, - Earth, - Earth\Period\Minute, -}; +use Innmind\TimeContinuum\Earth\Period\Minute; -function yourApp( - Clock $clock, - Halt $halt -): void { +function yourApp(Halt $halt): void +{ // do something - $halt($clock, new Minute(42)); + $halt(new Minute(42)); // do some more } -yourApp(new Earth\Clock, new Usleep); +yourApp(new Usleep); ``` This example will halt your program for 42 minutes. @@ -47,5 +41,5 @@ This example will halt your program for 42 minutes. use Innmind\TimeWarp\Halt\Logger; use Psr\Log\LoggerInterface; -$halt = new Logger($halt, /** an instance of LoggerInterface */); +$halt = Logger::psr($halt, /** an instance of LoggerInterface */); ``` diff --git a/composer.json b/composer.json index a8b87c0..1b09d45 100644 --- a/composer.json +++ b/composer.json @@ -8,16 +8,16 @@ "authors": [ { "name": "Baptiste Langlade", - "email": "langlade.baptiste@gmail.com" + "email": "baptiste.langlade@hey.com" } ], "support": { "issues": "http://github.com/Innmind/TimeWarp/issues" }, "require": { - "php": "~7.4|~8.0", - "innmind/time-continuum": "~2.0", - "psr/log": "^1.1" + "php": "~8.0", + "innmind/time-continuum": "~3.0", + "psr/log": "~3.0" }, "autoload": { "psr-4": { @@ -33,6 +33,6 @@ "require-dev": { "phpunit/phpunit": "~9.0", "vimeo/psalm": "~4.1", - "innmind/coding-standard": "^1.0" + "innmind/coding-standard": "~2.0" } } diff --git a/src/Halt.php b/src/Halt.php index 92cd014..152928a 100644 --- a/src/Halt.php +++ b/src/Halt.php @@ -3,15 +3,12 @@ namespace Innmind\TimeWarp; -use Innmind\TimeContinuum\{ - Clock, - Period, -}; +use Innmind\TimeContinuum\Period; interface Halt { /** * Halt the program for the given period */ - public function __invoke(Clock $clock, Period $period): void; + public function __invoke(Period $period): void; } diff --git a/src/Halt/Logger.php b/src/Halt/Logger.php index 4fddb02..9a79145 100644 --- a/src/Halt/Logger.php +++ b/src/Halt/Logger.php @@ -4,10 +4,7 @@ namespace Innmind\TimeWarp\Halt; use Innmind\TimeWarp\Halt; -use Innmind\TimeContinuum\{ - Clock, - Period, -}; +use Innmind\TimeContinuum\Period; use Psr\Log\LoggerInterface; final class Logger implements Halt @@ -15,13 +12,13 @@ final class Logger implements Halt private Halt $halt; private LoggerInterface $logger; - public function __construct(Halt $halt, LoggerInterface $logger) + private function __construct(Halt $halt, LoggerInterface $logger) { $this->halt = $halt; $this->logger = $logger; } - public function __invoke(Clock $clock, Period $period): void + public function __invoke(Period $period): void { $this->logger->debug('Halting current process...', ['period' => [ 'years' => $period->years(), @@ -32,6 +29,11 @@ public function __invoke(Clock $clock, Period $period): void 'seconds' => $period->seconds(), 'milliseconds' => $period->milliseconds(), ]]); - ($this->halt)($clock, $period); + ($this->halt)($period); + } + + public static function psr(Halt $halt, LoggerInterface $logger): self + { + return new self($halt, $logger); } } diff --git a/src/Halt/Usleep.php b/src/Halt/Usleep.php index 6e3cfc0..02796f3 100644 --- a/src/Halt/Usleep.php +++ b/src/Halt/Usleep.php @@ -7,10 +7,7 @@ Halt, PeriodToMilliseconds, }; -use Innmind\TimeContinuum\{ - Clock, - Period, -}; +use Innmind\TimeContinuum\Period; final class Usleep implements Halt { @@ -21,10 +18,9 @@ public function __construct() $this->periodToMilliseconds = new PeriodToMilliseconds; } - public function __invoke(Clock $clock, Period $period): void + public function __invoke(Period $period): void { - \usleep( - ($this->periodToMilliseconds)($period) * 1000 - ); + /** @psalm-suppress ArgumentTypeCoercion todo update types to fix this error */ + \usleep(($this->periodToMilliseconds)($period) * 1000); } } diff --git a/src/PeriodToMilliseconds.php b/src/PeriodToMilliseconds.php index 93eac5c..b7e3cce 100644 --- a/src/PeriodToMilliseconds.php +++ b/src/PeriodToMilliseconds.php @@ -8,6 +8,9 @@ final class PeriodToMilliseconds { + /** + * @throws LogicException If any number of months is specified + */ public function __invoke(Period $period): int { if ($period->months() !== 0) { diff --git a/tests/Halt/LoggerTest.php b/tests/Halt/LoggerTest.php index 673d3c6..d25357c 100644 --- a/tests/Halt/LoggerTest.php +++ b/tests/Halt/LoggerTest.php @@ -7,10 +7,7 @@ Halt\Logger, Halt, }; -use Innmind\TimeContinuum\{ - Clock, - Period, -}; +use Innmind\TimeContinuum\Period; use Psr\Log\LoggerInterface; use PHPUnit\Framework\TestCase; @@ -20,7 +17,7 @@ public function testInterface() { $this->assertInstanceOf( Halt::class, - new Logger( + Logger::psr( $this->createMock(Halt::class), $this->createMock(LoggerInterface::class), ), @@ -29,20 +26,19 @@ public function testInterface() public function testHalt() { - $clock = $this->createMock(Clock::class); $period = $this->createMock(Period::class); - $halt = new Logger( + $halt = Logger::psr( $inner = $this->createMock(Halt::class), $logger = $this->createMock(LoggerInterface::class), ); $inner ->expects($this->once()) ->method('__invoke') - ->with($clock, $period); + ->with($period); $logger ->expects($this->once()) ->method('debug'); - $this->assertNull($halt($clock, $period)); + $this->assertNull($halt($period)); } } diff --git a/tests/Halt/UsleepTest.php b/tests/Halt/UsleepTest.php index d83ec3c..ff12294 100644 --- a/tests/Halt/UsleepTest.php +++ b/tests/Halt/UsleepTest.php @@ -7,10 +7,7 @@ Halt\Usleep, Halt, }; -use Innmind\TimeContinuum\{ - Clock, - Earth\Period\Millisecond, -}; +use Innmind\TimeContinuum\Earth\Period\Millisecond; use PHPUnit\Framework\TestCase; class UsleepTest extends TestCase @@ -25,10 +22,7 @@ public function testHalt() $sleep = new Usleep; $start = \microtime(true); - $this->assertNull($sleep( - $this->createMock(Clock::class), - new Millisecond(500) - )); + $this->assertNull($sleep(new Millisecond(500))); $end = \microtime(true); $this->assertEqualsWithDelta(0.5, $end - $start, 0.09); // 90 milliseconds delta allowed } diff --git a/tests/PeriodToMillisecondsTest.php b/tests/PeriodToMillisecondsTest.php index 2ea81b5..d48c49e 100644 --- a/tests/PeriodToMillisecondsTest.php +++ b/tests/PeriodToMillisecondsTest.php @@ -26,7 +26,7 @@ public function testInvokation() 1, 1, 1, - 1 + 1, )); $this->assertSame(31626061001, $milliseconds);