Skip to content

Commit 1d89d56

Browse files
authored
Update CI (#27)
1 parent 24a4797 commit 1d89d56

13 files changed

+135
-164
lines changed

.github/workflows/autoformat.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
with:
1717
coverage: none
1818
extensions: mbstring
19-
php-version: 8.0
19+
php-version: 8.1
2020

2121
- run: composer install --no-interaction --no-progress --no-suggest
2222

@@ -33,7 +33,7 @@ jobs:
3333
with:
3434
ref: ${{ github.head_ref }}
3535

36-
- uses: creyD/prettier_action@v2.2
36+
- uses: creyD/prettier_action@v4.3
3737
with:
3838
prettier_options: --write --tab-width=2 *.md **/*.md
3939
branch: ${{ github.head_ref }}
@@ -52,7 +52,7 @@ jobs:
5252
with:
5353
coverage: none
5454
extensions: mbstring
55-
php-version: 8.0
55+
php-version: 8.1
5656

5757
- run: composer install --no-interaction --no-progress --no-suggest
5858

.github/workflows/continuous-integration.yml renamed to .github/workflows/validate.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
branches:
77
- master
88

9-
name: "Continuous Integration"
9+
name: "Validate"
1010

1111
jobs:
1212
composer-validate:
@@ -23,7 +23,7 @@ jobs:
2323
with:
2424
coverage: none
2525
extensions: mbstring
26-
php-version: 8.0
26+
php-version: 8.1
2727

2828
- name: "Validate composer.json and composer.lock"
2929
run: composer validate --strict
@@ -59,7 +59,7 @@ jobs:
5959
php-version:
6060
- "8.0"
6161
- "8.1"
62-
62+
- "8.2"
6363
dependencies:
6464
- "prefer-lowest"
6565
- "prefer-stable"
@@ -93,7 +93,7 @@ jobs:
9393
uses: shivammathur/setup-php@v2
9494
with:
9595
coverage: pcov
96-
php-version: 8.0
96+
php-version: 8.1
9797

9898
- name: "Install dependencies with composer"
9999
run: composer install --no-interaction --no-progress

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
},
2424
"require-dev": {
2525
"ergebnis/composer-normalize": "^2.16",
26-
"friendsofphp/php-cs-fixer": "3.4.*",
27-
"mll-lab/php-cs-fixer-config": "^4.3",
26+
"mll-lab/php-cs-fixer-config": "^5",
2827
"phpstan/extension-installer": "^1",
2928
"phpstan/phpstan": "^1",
3029
"phpstan/phpstan-deprecation-rules": "^1",
3130
"phpstan/phpstan-phpunit": "^1",
3231
"phpstan/phpstan-strict-rules": "^1",
33-
"phpunit/phpunit": "^9",
32+
"phpunit/phpunit": "^9 || ^10",
3433
"symfony/var-dumper": "^5.4 || ^6",
3534
"thecodingmachine/phpstan-safe-rule": "^1.1"
3635
},

src/DateScalar.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,31 @@
22

33
namespace MLL\GraphQLScalars;
44

5-
use DateTimeImmutable;
6-
use DateTimeInterface;
7-
use Exception;
85
use GraphQL\Error\Error;
96
use GraphQL\Error\InvariantViolation;
107
use GraphQL\Language\AST\StringValueNode;
118
use GraphQL\Type\Definition\ScalarType;
129
use GraphQL\Utils\Utils;
13-
use function is_string;
10+
1411
use function Safe\preg_match;
1512

1613
abstract class DateScalar extends ScalarType
1714
{
1815
public function serialize($value): string
1916
{
20-
if (! $value instanceof DateTimeInterface) {
17+
if (! $value instanceof \DateTimeInterface) {
2118
$value = $this->tryParsingDate($value, InvariantViolation::class);
2219
}
2320

2421
return $value->format(static::outputFormat());
2522
}
2623

27-
public function parseValue($value): DateTimeInterface
24+
public function parseValue($value): \DateTimeInterface
2825
{
2926
return $this->tryParsingDate($value, Error::class);
3027
}
3128

32-
public function parseLiteral($valueNode, ?array $variables = null): DateTimeInterface
29+
public function parseLiteral($valueNode, ?array $variables = null): \DateTimeInterface
3330
{
3431
if (! $valueNode instanceof StringValueNode) {
3532
throw new Error(
@@ -44,14 +41,13 @@ public function parseLiteral($valueNode, ?array $variables = null): DateTimeInte
4441
/**
4542
* @template T of Error|InvariantViolation
4643
*
47-
* @param mixed $value Any value that might be a Date
4844
* @param class-string<T> $exceptionClass
4945
*
5046
* @throws T
5147
*/
52-
protected function tryParsingDate($value, string $exceptionClass): DateTimeInterface
48+
protected function tryParsingDate(mixed $value, string $exceptionClass): \DateTimeInterface
5349
{
54-
if (is_string($value)) {
50+
if (\is_string($value)) {
5551
if (1 !== preg_match(static::regex(), $value, $matches)) {
5652
$regex = static::regex();
5753
throw new $exceptionClass("Value \"{$value}\" does not match \"{$regex}\". Make sure it's ISO 8601 compliant ");
@@ -63,8 +59,8 @@ protected function tryParsingDate($value, string $exceptionClass): DateTimeInter
6359
}
6460

6561
try {
66-
return new DateTimeImmutable($value);
67-
} catch (Exception $e) {
62+
return new \DateTimeImmutable($value);
63+
} catch (\Exception $e) {
6864
throw new $exceptionClass($e->getMessage());
6965
}
7066
}

src/JSON.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function parseLiteral($valueNode, ?array $variables = null)
4141
*
4242
* @return mixed The decoded value
4343
*/
44-
protected function decodeJSON($value)
44+
protected function decodeJSON(mixed $value): mixed
4545
{
4646
try {
4747
// @phpstan-ignore-next-line we attempt unsafe values and let it throw

src/Utils.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ final class Utils
1212
{
1313
/**
1414
* Check if a value can be serialized to a string.
15-
*
16-
* @param mixed $value Any value
1715
*/
18-
public static function canBeString($value): bool
16+
public static function canBeString(mixed $value): bool
1917
{
2018
return null === $value
2119
|| is_scalar($value)
@@ -46,12 +44,11 @@ public static function extractStringFromLiteral(Node $valueNode): string
4644
*
4745
* @template T of \Throwable
4846
*
49-
* @param mixed $value Any value
5047
* @param class-string<T> $exceptionClass
5148
*
5249
* @throws T
5350
*/
54-
public static function coerceToString($value, string $exceptionClass): string
51+
public static function coerceToString(mixed $value, string $exceptionClass): string
5552
{
5653
if (! self::canBeString($value)) {
5754
$safeValue = GraphQLUtils::printSafeJson($value);

tests/DateScalarTest.php renamed to tests/DateScalarTestBase.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@
22

33
namespace MLL\GraphQLScalars\Tests;
44

5-
use DateTimeImmutable;
65
use GraphQL\Error\Error;
76
use GraphQL\Error\InvariantViolation;
87
use GraphQL\Language\AST\IntValueNode;
98
use GraphQL\Language\AST\StringValueNode;
109
use MLL\GraphQLScalars\DateScalar;
1110
use PHPUnit\Framework\TestCase;
1211

13-
abstract class DateScalarTest extends TestCase
12+
abstract class DateScalarTestBase extends TestCase
1413
{
1514
/**
1615
* @dataProvider invalidDateValues
17-
*
18-
* @param mixed $value An invalid value for a date
1916
*/
20-
public function testThrowsIfSerializingInvalidDates($value): void
17+
public function testThrowsIfSerializingInvalidDates(mixed $value): void
2118
{
2219
$dateScalar = $this->scalarInstance();
2320

@@ -27,10 +24,8 @@ public function testThrowsIfSerializingInvalidDates($value): void
2724

2825
/**
2926
* @dataProvider invalidDateValues
30-
*
31-
* @param mixed $value An invalid value for a date
3227
*/
33-
public function testThrowsIfParseValueInvalidDate($value): void
28+
public function testThrowsIfParseValueInvalidDate(mixed $value): void
3429
{
3530
$dateScalar = $this->scalarInstance();
3631

@@ -43,7 +38,7 @@ public function testThrowsIfParseValueInvalidDate($value): void
4338
*
4439
* @return iterable<array-key, array{mixed}>
4540
*/
46-
public function invalidDateValues(): iterable
41+
public static function invalidDateValues(): iterable
4742
{
4843
yield [1];
4944
yield ['rolf'];
@@ -85,7 +80,7 @@ public function testThrowsIfParseLiteralNonString(): void
8580

8681
public function testSerializesDateTimeInterfaceInstance(): void
8782
{
88-
$now = new DateTimeImmutable();
83+
$now = new \DateTimeImmutable();
8984
$result = $this->scalarInstance()->serialize($now);
9085

9186
self::assertNotEmpty($result);
@@ -101,5 +96,5 @@ abstract protected function scalarInstance(): DateScalar;
10196
*
10297
* @return iterable<array{string, string}>
10398
*/
104-
abstract public function validDates(): iterable;
99+
abstract public static function validDates(): iterable;
105100
}

tests/DateTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use MLL\GraphQLScalars\Date;
66
use MLL\GraphQLScalars\DateScalar;
77

8-
final class DateTest extends DateScalarTest
8+
final class DateTest extends DateScalarTestBase
99
{
10-
public function invalidDateValues(): iterable
10+
public static function invalidDateValues(): iterable
1111
{
1212
yield from parent::invalidDateValues();
1313

@@ -23,7 +23,7 @@ protected function scalarInstance(): DateScalar
2323
return new Date();
2424
}
2525

26-
public function validDates(): iterable
26+
public static function validDates(): iterable
2727
{
2828
yield ['2020-04-20', '2020-04-20T00:00:00.000000+00:00'];
2929
}

tests/DateTimeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use MLL\GraphQLScalars\DateScalar;
66
use MLL\GraphQLScalars\DateTime;
77

8-
final class DateTimeTest extends DateScalarTest
8+
final class DateTimeTest extends DateScalarTestBase
99
{
10-
public function invalidDateValues(): iterable
10+
public static function invalidDateValues(): iterable
1111
{
1212
yield from parent::invalidDateValues();
1313

@@ -21,7 +21,7 @@ protected function scalarInstance(): DateScalar
2121
return new DateTime();
2222
}
2323

24-
public function validDates(): iterable
24+
public static function validDates(): iterable
2525
{
2626
yield ['2020-04-20 23:51:15', '2020-04-20T23:51:15.000000+00:00'];
2727
}

tests/DateTimeTzTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use MLL\GraphQLScalars\DateScalar;
66
use MLL\GraphQLScalars\DateTimeTz;
77

8-
final class DateTimeTzTest extends DateScalarTest
8+
final class DateTimeTzTest extends DateScalarTestBase
99
{
10-
public function invalidDateValues(): iterable
10+
public static function invalidDateValues(): iterable
1111
{
1212
yield from parent::invalidDateValues();
1313

@@ -22,7 +22,7 @@ protected function scalarInstance(): DateScalar
2222
return new DateTimeTz();
2323
}
2424

25-
public function validDates(): iterable
25+
public static function validDates(): iterable
2626
{
2727
yield ['2020-04-20T16:20:04+04:00', '2020-04-20T16:20:04.000000+04:00'];
2828
yield ['2020-04-20T16:20:04Z', '2020-04-20T16:20:04.000000+00:00'];

0 commit comments

Comments
 (0)