Skip to content

Commit 6442638

Browse files
authored
Feature/PHP 8.1 Upgrade (#8)
1 parent 9d5399d commit 6442638

34 files changed

+717
-142
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/.gitattributes export-ignore
33
/phpunit.xml export-ignore
44
/tests export-ignore
5+
/wiki export-ignore
56
/README.md

.github/workflows/documentation.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
name: Documentation
22

33
on:
4-
pull_request:
5-
types: [ closed ]
4+
push:
5+
branches: [ 'main' ]
66

77
jobs:
88
publish:
9-
if: github.event.pull_request.merged == true
109
runs-on: ubuntu-latest
1110

1211
strategy:
1312
matrix:
14-
php-version:
15-
- "7.4"
13+
php-version: [ '8.1' ]
1614

1715
steps:
1816
- name: Checkout source code
@@ -39,7 +37,7 @@ jobs:
3937
- name: Install Dependencies
4038
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
4139

42-
- name: Pusblish documentation to Wiki
40+
- name: Publish documentation to Wiki
4341
uses: SwiftDocOrg/github-wiki-publish-action@v1
4442
with:
4543
path: "wiki/"

.github/workflows/test.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@ name: Test
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [ 'main' ]
76
pull_request:
8-
types: [ opened, synchronize, reopened ]
7+
types: [ 'opened', 'synchronize', 'reopened' ]
98

109
jobs:
1110
test:
1211
runs-on: ubuntu-latest
1312

1413
strategy:
1514
matrix:
16-
php-version: [ "8.0", "8.1" ]
15+
php-version: [ '8.1' ]
1716

1817
steps:
1918
- name: Checkout source code
2019
uses: actions/checkout@v2
20+
with:
21+
fetch-depth: 0
2122

2223
- name: Set up PHP ${{ matrix.php-version }}
2324
uses: shivammathur/setup-php@v2
@@ -36,8 +37,9 @@ jobs:
3637
- name: Validate composer.json and composer.lock
3738
run: composer validate
3839

39-
- name: Install Dependencies
40-
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
40+
- name: Install dependencies
41+
if: steps.composer-cache.outputs.cache-hit != 'true'
42+
run: composer install --prefer-dist --no-progress --no-suggest
4143

4244
- name: Execute Static Code analysis
4345
run: composer analyse

composer.json

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"minimum-stability": "stable",
1313
"require": {
14-
"php": "^8.0",
14+
"php": "^8.1.0",
1515
"ext-json": "*",
1616
"ramsey/uuid": "^4.1",
1717
"nesbot/carbon": "^2.40",
@@ -21,20 +21,29 @@
2121
"complex-heart/contracts": "^1.0.0"
2222
},
2323
"require-dev": {
24-
"mockery/mockery": "^1.4",
25-
"phpunit/phpunit": "^9.3",
26-
"fakerphp/faker": "^1.9.1",
27-
"phpstan/phpstan": "^1.6.8",
28-
"pestphp/pest": "^1.4"
24+
"pestphp/pest": "^1.22.3",
25+
"pestphp/pest-plugin-mock": "^1.0.0",
26+
"pestphp/pest-plugin-faker": "^1.0.0",
27+
"phpstan/phpstan": "^1.9.0"
2928
},
3029
"autoload": {
3130
"psr-4": {
3231
"ComplexHeart\\Domain\\Model\\": "src/"
3332
}
3433
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"ComplexHeart\\Domain\\Model\\Test\\": "tests/"
37+
}
38+
},
3539
"scripts": {
3640
"test": "vendor/bin/pest --configuration=phpunit.xml --coverage-clover=coverage.xml --log-junit=test.xml",
37-
"analyse": "vendor/bin/phpstan analyse src --no-progress --level=5"
41+
"test-cov": "vendor/bin/pest --configuration=phpunit.xml --coverage-html=coverage",
42+
"analyse": "vendor/bin/phpstan analyse src --no-progress --level=5",
43+
"check": [
44+
"@analyse",
45+
"@test"
46+
]
3847
},
3948
"config": {
4049
"allow-plugins": {

src/Exceptions/ImmutableException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
class ImmutableException extends RuntimeException
1616
{
1717

18-
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ComplexHeart\Domain\Model\Exceptions;
6+
7+
use RuntimeException;
8+
9+
/**
10+
* Class InstantiationException
11+
*
12+
* @author Unay Santisteban <usantisteban@othercode.es>
13+
* @package ComplexHeart\Domain\Model\Exceptions
14+
*/
15+
class InstantiationException extends RuntimeException
16+
{
17+
18+
}

src/Traits/HasAttributes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final public static function attributes(): array
2424
{
2525
return array_filter(
2626
array_keys(get_class_vars(static::class)),
27-
fn(string $item): bool => strpos($item, '_') !== 0
27+
fn(string $item): bool => !str_starts_with($item, '_')
2828
);
2929
}
3030

@@ -63,7 +63,7 @@ final protected function hydrate(iterable $source): void
6363
*
6464
* @return mixed|null
6565
*/
66-
final protected function get(string $attribute)
66+
final protected function get(string $attribute): mixed
6767
{
6868
if (in_array($attribute, static::attributes())) {
6969
$method = $this->getStringKey($attribute, 'get', 'Value');
@@ -82,7 +82,7 @@ final protected function get(string $attribute)
8282
* @param string $attribute
8383
* @param mixed $value
8484
*/
85-
final protected function set(string $attribute, $value): void
85+
final protected function set(string $attribute, mixed $value): void
8686
{
8787
if (in_array($attribute, $this->attributes())) {
8888
$method = $this->getStringKey($attribute, 'set', 'Value');

src/Traits/HasEquality.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ protected function hash(): string
4646
*
4747
* @return string
4848
*/
49-
abstract function __toString();
49+
abstract function __toString(): string;
5050
}

src/Traits/HasInvariants.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final public static function invariants(): array
2424
{
2525
$invariants = [];
2626
foreach (get_class_methods(static::class) as $invariant) {
27-
if (strpos($invariant, 'invariant') === 0 && $invariant !== 'invariants') {
27+
if (str_starts_with($invariant, 'invariant') && $invariant !== 'invariants') {
2828
$invariants[$invariant] = str_replace(
2929
'invariant ',
3030
'',
@@ -52,7 +52,7 @@ final public static function invariants(): array
5252
*
5353
* If exception is thrown the error message will be the exception message.
5454
*
55-
* $onFail function must have following signature:
55+
* $onFail function must have the following signature:
5656
* fn(array<string, string>) => void
5757
*
5858
* @param callable|null $onFail
@@ -74,7 +74,7 @@ private function check(callable $onFail = null): void
7474
}
7575
}
7676

77-
if (count($violations) > 0) {
77+
if (!empty($violations)) {
7878
if (is_null($onFail)) {
7979
$customizedHandler = function (array $violations) use ($handler): void {
8080
call_user_func_array([$this, $handler], [$violations]);

src/Traits/HasTypeCheck.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait HasTypeCheck
2020
*
2121
* @return bool
2222
*/
23-
protected function isValueTypeValid($value, string $validType): bool
23+
protected function isValueTypeValid(mixed $value, string $validType): bool
2424
{
2525
if ($validType === 'mixed') {
2626
return true;
@@ -42,8 +42,8 @@ protected function isValueTypeValid($value, string $validType): bool
4242
*
4343
* @return bool
4444
*/
45-
protected function isValueTypeNotValid($value, string $validType): bool
45+
protected function isValueTypeNotValid(mixed $value, string $validType): bool
4646
{
4747
return !$this->isValueTypeValid($value, $validType);
4848
}
49-
}
49+
}

0 commit comments

Comments
 (0)