From 651e98b4dad722e599b734340a5208244a57362a Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 1 Aug 2021 10:52:19 +0200 Subject: [PATCH 01/14] drop php 7 support --- .github/workflows/ci.yml | 6 +++--- composer.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57a3293..709fa91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - php-version: ['7.4', '8.0'] + php-version: ['8.0'] name: 'PHPUnit' steps: - name: Checkout @@ -39,7 +39,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['7.4', '8.0'] + php-version: ['8.0'] name: 'Psalm' steps: - name: Checkout @@ -66,7 +66,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['7.4'] + php-version: ['8.0'] name: 'CS' steps: - name: Checkout diff --git a/composer.json b/composer.json index a8b87c0..0ea73d5 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "issues": "http://github.com/Innmind/TimeWarp/issues" }, "require": { - "php": "~7.4|~8.0", + "php": "~8.0", "innmind/time-continuum": "~2.0", "psr/log": "^1.1" }, From fb957f92bee741dad8921e07fe9209ecfaa39b79 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 1 Aug 2021 10:54:14 +0200 Subject: [PATCH 02/14] simplify interface --- src/Halt.php | 7 ++----- src/Halt/Logger.php | 9 +++------ src/Halt/Usleep.php | 7 ++----- tests/Halt/LoggerTest.php | 10 +++------- tests/Halt/UsleepTest.php | 10 ++-------- 5 files changed, 12 insertions(+), 31 deletions(-) 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..82d0203 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 @@ -21,7 +18,7 @@ public function __construct(Halt $halt, LoggerInterface $logger) $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,6 @@ public function __invoke(Clock $clock, Period $period): void 'seconds' => $period->seconds(), 'milliseconds' => $period->milliseconds(), ]]); - ($this->halt)($clock, $period); + ($this->halt)($period); } } diff --git a/src/Halt/Usleep.php b/src/Halt/Usleep.php index 6e3cfc0..fe4ef8e 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,7 +18,7 @@ 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 diff --git a/tests/Halt/LoggerTest.php b/tests/Halt/LoggerTest.php index 673d3c6..86792f7 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; @@ -29,7 +26,6 @@ public function testInterface() public function testHalt() { - $clock = $this->createMock(Clock::class); $period = $this->createMock(Period::class); $halt = new Logger( $inner = $this->createMock(Halt::class), @@ -38,11 +34,11 @@ public function testHalt() $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 } From e4b586950f2eaa16fa8ec4d8199911fc1672fd26 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 1 Aug 2021 10:55:41 +0200 Subject: [PATCH 03/14] CS --- src/Halt/Usleep.php | 4 +--- tests/PeriodToMillisecondsTest.php | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Halt/Usleep.php b/src/Halt/Usleep.php index fe4ef8e..2bbe4b9 100644 --- a/src/Halt/Usleep.php +++ b/src/Halt/Usleep.php @@ -20,8 +20,6 @@ public function __construct() public function __invoke(Period $period): void { - \usleep( - ($this->periodToMilliseconds)($period) * 1000 - ); + \usleep(($this->periodToMilliseconds)($period) * 1000); } } 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); From 6d4eeb44615547a18c23e863fe2a66ca536744ce Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 1 Aug 2021 10:57:15 +0200 Subject: [PATCH 04/14] change email address --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0ea73d5..f959a88 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "authors": [ { "name": "Baptiste Langlade", - "email": "langlade.baptiste@gmail.com" + "email": "baptiste.langlade@hey.com" } ], "support": { From d261268b59c5b3dc0219bddd7d1d91dc738eda07 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 1 Aug 2021 10:57:24 +0200 Subject: [PATCH 05/14] prepare for next release --- composer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f959a88..0710bc3 100644 --- a/composer.json +++ b/composer.json @@ -16,9 +16,11 @@ }, "require": { "php": "~8.0", - "innmind/time-continuum": "~2.0", + "innmind/time-continuum": "dev-next", "psr/log": "^1.1" }, + "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-4": { "Innmind\\TimeWarp\\": "src/" From f1aa044dc82af7948ee56590eef26bbec38c9bf6 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 6 Feb 2022 10:52:07 +0100 Subject: [PATCH 06/14] use time-continuum 3 --- composer.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 0710bc3..58b505c 100644 --- a/composer.json +++ b/composer.json @@ -16,11 +16,9 @@ }, "require": { "php": "~8.0", - "innmind/time-continuum": "dev-next", - "psr/log": "^1.1" + "innmind/time-continuum": "~3.0", + "psr/log": "~3.0" }, - "minimum-stability": "dev", - "prefer-stable": true, "autoload": { "psr-4": { "Innmind\\TimeWarp\\": "src/" From 895c3d4d5488bc5d6a8b5f55736fb7524017d5f0 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 6 Feb 2022 10:53:09 +0100 Subject: [PATCH 07/14] use CS 2 --- .github/workflows/ci.yml | 2 +- .php_cs.dist => .php-cs-fixer.dist.php | 0 composer.json | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename .php_cs.dist => .php-cs-fixer.dist.php (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 709fa91..6e220cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,4 +88,4 @@ jobs: - name: Install Dependencies run: composer install --no-progress - 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/composer.json b/composer.json index 58b505c..1b09d45 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,6 @@ "require-dev": { "phpunit/phpunit": "~9.0", "vimeo/psalm": "~4.1", - "innmind/coding-standard": "^1.0" + "innmind/coding-standard": "~2.0" } } From 382ccedbc55b0539d968629bec66f2bb38bd9df9 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 6 Feb 2022 11:02:24 +0100 Subject: [PATCH 08/14] specify thrown exception --- src/PeriodToMilliseconds.php | 3 +++ 1 file changed, 3 insertions(+) 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) { From a8152048c6aed4292ca596c57109cd7f9f3ae6ac Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 6 Feb 2022 11:04:22 +0100 Subject: [PATCH 09/14] discard (unreachable) type error for now --- src/Halt/Usleep.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Halt/Usleep.php b/src/Halt/Usleep.php index 2bbe4b9..02796f3 100644 --- a/src/Halt/Usleep.php +++ b/src/Halt/Usleep.php @@ -20,6 +20,7 @@ public function __construct() public function __invoke(Period $period): void { + /** @psalm-suppress ArgumentTypeCoercion todo update types to fix this error */ \usleep(($this->periodToMilliseconds)($period) * 1000); } } From 915e9d3b08af5e709bcab2e8d5caa7f00cf176cd Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 6 Feb 2022 11:05:01 +0100 Subject: [PATCH 10/14] test against php 8.1 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e220cf..b648c63 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - php-version: ['8.0'] + php-version: ['8.0', '8.1'] name: 'PHPUnit' steps: - name: Checkout @@ -39,7 +39,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['8.0'] + php-version: ['8.0', '8.1'] name: 'Psalm' steps: - name: Checkout From 492c7e3e5bfae1ccbc65e5c517d11a8b5c77f8bb Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 6 Feb 2022 11:06:51 +0100 Subject: [PATCH 11/14] test against lowest dependencies --- .github/workflows/ci.yml | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b648c63..120977b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,7 @@ jobs: matrix: os: [ubuntu-latest, macOS-latest] 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 @@ -40,6 +34,7 @@ jobs: strategy: matrix: php-version: ['8.0', '8.1'] + dependencies: ['lowest', 'highest'] name: 'Psalm' steps: - name: Checkout @@ -49,17 +44,10 @@ 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: From 715909efbf08d9341995d37e4497524b25fa247b Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 6 Feb 2022 11:07:13 +0100 Subject: [PATCH 12/14] use ramsey/composer-install --- .github/workflows/ci.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 120977b..5dbe965 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,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 From 9695aa85057c91b0e3194daa7465f16aad96520c Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 6 Feb 2022 11:18:52 +0100 Subject: [PATCH 13/14] make logger constructor private --- src/Halt/Logger.php | 7 ++++++- tests/Halt/LoggerTest.php | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Halt/Logger.php b/src/Halt/Logger.php index 82d0203..9a79145 100644 --- a/src/Halt/Logger.php +++ b/src/Halt/Logger.php @@ -12,7 +12,7 @@ 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; @@ -31,4 +31,9 @@ public function __invoke(Period $period): void ]]); ($this->halt)($period); } + + public static function psr(Halt $halt, LoggerInterface $logger): self + { + return new self($halt, $logger); + } } diff --git a/tests/Halt/LoggerTest.php b/tests/Halt/LoggerTest.php index 86792f7..d25357c 100644 --- a/tests/Halt/LoggerTest.php +++ b/tests/Halt/LoggerTest.php @@ -17,7 +17,7 @@ public function testInterface() { $this->assertInstanceOf( Halt::class, - new Logger( + Logger::psr( $this->createMock(Halt::class), $this->createMock(LoggerInterface::class), ), @@ -27,7 +27,7 @@ public function testInterface() public function testHalt() { $period = $this->createMock(Period::class); - $halt = new Logger( + $halt = Logger::psr( $inner = $this->createMock(Halt::class), $logger = $this->createMock(LoggerInterface::class), ); From 756ee818d8775106d7711d1e5a1bada40e0a2c08 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 6 Feb 2022 11:19:53 +0100 Subject: [PATCH 14/14] update readme --- README.md | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) 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 */); ```