Skip to content

Commit

Permalink
Merge pull request #16 from Innmind/php84
Browse files Browse the repository at this point in the history
Add PHP 8.4 support
  • Loading branch information
Baptouuuu authored Jan 19, 2025
2 parents 30b5067 + 503d0e5 commit 28182b8
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 179 deletions.
72 changes: 7 additions & 65 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,12 @@ name: CI
on: [push]

jobs:
phpunit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['8.2', '8.3']
dependencies: ['lowest', 'highest']
name: 'BlackBox'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: xdebug
- name: Composer
uses: "ramsey/composer-install@v3"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: BlackBox
run: php blackbox.php
env:
ENABLE_COVERAGE: 'true'
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
coverage:
uses: innmind/github-workflows/.github/workflows/coverage-matrix.yml@main
secrets: inherit
psalm:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.2', '8.3']
dependencies: ['lowest', 'highest']
name: 'Psalm'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Composer
uses: "ramsey/composer-install@v3"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: Psalm
run: vendor/bin/psalm --shepherd
uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main
cs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.2']
name: 'CS'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Composer
uses: "ramsey/composer-install@v3"
- name: CS
run: vendor/bin/php-cs-fixer fix --diff --dry-run
uses: innmind/github-workflows/.github/workflows/cs.yml@main
with:
php-version: '8.2'
23 changes: 3 additions & 20 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
name: Documentation
on:
push:
branches: [master]
branches: [master, main]
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v5
with:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: pip install mkdocs-material
- run: mkdocs gh-deploy --force
uses: innmind/github-workflows/.github/workflows/documentation.yml@main
secrets: inherit
28 changes: 6 additions & 22 deletions .github/workflows/periodic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,9 @@ on:

jobs:
blackbox:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
php-version: ['8.3']
dependency-versions: ['highest']
name: 'BlackBox'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: none
- name: Composer
uses: "ramsey/composer-install@v3"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: BlackBox
run: php blackbox.php ci
uses: innmind/github-workflows/.github/workflows/coverage.yml@main
secrets: inherit
with:
tags: ci
os: ubuntu-latest
php-version: '8.3'
16 changes: 2 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,7 @@ on:
tags:
- '*'

permissions:
contents: write

jobs:
release:
name: Create release
runs-on: ubuntu-22.04
steps:
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
run: |
gh release create "$tag" \
--repo="$GITHUB_REPOSITORY" \
--generate-notes
uses: innmind/github-workflows/.github/workflows/release.yml@main
secrets: inherit
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [Unreleased]

### Fixed

- Support for PHP `8.4`
- An error were `Innmind\TimeContinuum\MoveEndOfMonth` would change the month on leap years

## 4.0.0 - 2024-11-28

## Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}
},
"require-dev": {
"vimeo/psalm": "~5.13",
"vimeo/psalm": "~5.13|dev-master",
"innmind/black-box": "~5.8",
"innmind/coding-standard": "^2.0.1"
},
Expand Down
53 changes: 53 additions & 0 deletions proofs/move/endOfMonth.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Innmind\TimeContinuum\{
Clock,
Move\EndOfMonth,
Format,
};
use Fixtures\Innmind\TimeContinuum\PointInTime;
use Innmind\BlackBox\Set;
Expand Down Expand Up @@ -52,4 +53,56 @@ static function($assert, $point) {
);
},
);

yield test(
'End of month regression',
static function($assert) {
$point = Clock::live()
->at(
'0100-02-27T18:35:40.134853+01:00',
Format::of('Y-m-d\TH:i:s.uP'),
)
->match(
static fn($point) => $point,
static fn() => null,
);

$assert->object($point);

$endOfMonth = (new EndOfMonth)($point);

$assert->same(
$point->year()->toInt(),
$endOfMonth->year()->toInt(),
);
$assert->same(
$point->month()->ofYear(),
$endOfMonth->month()->ofYear(),
);
$assert->same(
$point->month()->numberOfDays(),
$endOfMonth->day()->ofMonth(),
);
$assert->same(
23,
$endOfMonth->hour()->toInt(),
);
$assert->same(
59,
$endOfMonth->minute()->toInt(),
);
$assert->same(
59,
$endOfMonth->second()->toInt(),
);
$assert->same(
999,
$endOfMonth->millisecond()->toInt(),
);
$assert->same(
999,
$endOfMonth->microsecond()->toInt(),
);
},
);
};
16 changes: 3 additions & 13 deletions src/PointInTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,12 @@ public function year(): Year

public function month(): Month
{
return Month::of(
$this->year(),
Calendar\Month::of((int) $this->date->format('n')),
);
return Month::of($this->date);
}

public function day(): Day
{
/** @var int<1, 31> */
$day = (int) $this->date->format('j');

return Day::of(
$this->year(),
$this->month(),
$day,
);
return Day::of($this->date);
}

public function hour(): Hour
Expand Down Expand Up @@ -303,6 +293,6 @@ private static function dateInterval(Period $period): ?\DateInterval
}

/** @psalm-suppress ImpureMethodCall */
return \DateInterval::createFromDateString(\implode(' + ', $parts));
return \DateInterval::createFromDateString(\implode(' + ', $parts)) ?: null;
}
}
21 changes: 8 additions & 13 deletions src/PointInTime/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,24 @@ final class Day
/** @var int<0, 365> */
private int $ofYear;

/**
* @param int<1, 31> $day
*/
private function __construct(Year $year, Month $month, int $day)
private function __construct(\DateTimeImmutable $date)
{
/** @var int<1, 31> */
$day = (int) $date->format('j');

$this->day = $day;
$this->week = Calendar\Day::of((int) \date(
'w',
$time = \mktime(0, 0, 0, $month->ofYear()->toInt(), $day, $year->toInt()),
));
$this->week = Calendar\Day::of((int) $date->format('w'));
/** @var int<0, 365> */
$this->ofYear = (int) \date('z', $time);
$this->ofYear = (int) $date->format('z');
}

/**
* @psalm-pure
* @internal
*
* @param int<1, 31> $day
*/
public static function of(Year $year, Month $month, int $day): self
public static function of(\DateTimeImmutable $date): self
{
return new self($year, $month, $day);
return new self($date);
}

public function ofWeek(): Calendar\Day
Expand Down
13 changes: 5 additions & 8 deletions src/PointInTime/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,20 @@ final class Month
/** @var int<28, 31> */
private int $days;

private function __construct(Year $year, Calendar\Month $month)
private function __construct(\DateTimeImmutable $date)
{
$this->month = $month;
$this->month = Calendar\Month::of((int) $date->format('n'));
/** @var int<28, 31> */
$this->days = (int) \date(
't',
\mktime(0, 0, 0, $month->toInt(), 1, $year->toInt()),
);
$this->days = (int) $date->format('t');
}

/**
* @psalm-pure
* @internal
*/
public static function of(Year $year, Calendar\Month $month): self
public static function of(\DateTimeImmutable $date): self
{
return new self($year, $month);
return new self($date);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PointInTime/Year.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private function __construct(int $year)
{
$this->year = $year;
/** @var 365|366 */
$this->days = (int) \date('z', \mktime(0, 0, 0, 12, 31, $year)) + 1;
$this->days = ((int) (new \DateTimeImmutable("{$year}-12-31T00:00:00"))->format('z')) + 1;
}

/**
Expand Down
10 changes: 8 additions & 2 deletions tests/NowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,14 @@ public function testAheadOf()
\sleep(1);
$point2 = PointInTime::now();

$this->assertTrue($point2->aheadOf($point));
$this->assertFalse($point->aheadOf($point2));
$this->assertTrue(
$point2->aheadOf($point),
$point->format(Format::of('Y-m-d\TH:i:s.uP')).' '.$point2->format(Format::of('Y-m-d\TH:i:s.uP')),
);
$this->assertFalse(
$point->aheadOf($point2),
$point->format(Format::of('Y-m-d\TH:i:s.uP')).' '.$point2->format(Format::of('Y-m-d\TH:i:s.uP')),
);
}

public function testEquals()
Expand Down
Loading

0 comments on commit 28182b8

Please sign in to comment.