Skip to content

Commit

Permalink
Merge branch 'next' into develop
Browse files Browse the repository at this point in the history
* next:
  update readme
  make logger constructor private
  use ramsey/composer-install
  test against lowest dependencies
  test against php 8.1
  discard (unreachable) type error for now
  specify thrown exception
  use CS 2
  use time-continuum 3
  prepare for next release
  change email address
  CS
  simplify interface
  drop php 7 support
  • Loading branch information
Baptouuuu committed Feb 6, 2022
2 parents 65e3674 + 756ee81 commit c896731
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 90 deletions.
49 changes: 14 additions & 35 deletions .github/workflows/ci.yml
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
File renamed without changes.
18 changes: 6 additions & 12 deletions README.md
Expand Up @@ -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.
Expand All @@ -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 */);
```
10 changes: 5 additions & 5 deletions composer.json
Expand Up @@ -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": {
Expand All @@ -33,6 +33,6 @@
"require-dev": {
"phpunit/phpunit": "~9.0",
"vimeo/psalm": "~4.1",
"innmind/coding-standard": "^1.0"
"innmind/coding-standard": "~2.0"
}
}
7 changes: 2 additions & 5 deletions src/Halt.php
Expand Up @@ -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;
}
16 changes: 9 additions & 7 deletions src/Halt/Logger.php
Expand Up @@ -4,24 +4,21 @@
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
{
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(),
Expand All @@ -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);
}
}
12 changes: 4 additions & 8 deletions src/Halt/Usleep.php
Expand Up @@ -7,10 +7,7 @@
Halt,
PeriodToMilliseconds,
};
use Innmind\TimeContinuum\{
Clock,
Period,
};
use Innmind\TimeContinuum\Period;

final class Usleep implements Halt
{
Expand All @@ -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);
}
}
3 changes: 3 additions & 0 deletions src/PeriodToMilliseconds.php
Expand Up @@ -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) {
Expand Down
14 changes: 5 additions & 9 deletions tests/Halt/LoggerTest.php
Expand Up @@ -7,10 +7,7 @@
Halt\Logger,
Halt,
};
use Innmind\TimeContinuum\{
Clock,
Period,
};
use Innmind\TimeContinuum\Period;
use Psr\Log\LoggerInterface;
use PHPUnit\Framework\TestCase;

Expand All @@ -20,7 +17,7 @@ public function testInterface()
{
$this->assertInstanceOf(
Halt::class,
new Logger(
Logger::psr(
$this->createMock(Halt::class),
$this->createMock(LoggerInterface::class),
),
Expand All @@ -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));
}
}
10 changes: 2 additions & 8 deletions tests/Halt/UsleepTest.php
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PeriodToMillisecondsTest.php
Expand Up @@ -26,7 +26,7 @@ public function testInvokation()
1,
1,
1,
1
1,
));

$this->assertSame(31626061001, $milliseconds);
Expand Down

0 comments on commit c896731

Please sign in to comment.