Skip to content

Commit a1887e7

Browse files
committed
Support thecodingmachine/safe 3
1 parent 080b5a2 commit a1887e7

File tree

7 files changed

+15
-32
lines changed

7 files changed

+15
-32
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## Unreleased
1111

12+
## v6.4.0
13+
14+
### Added
15+
16+
- Support `thecodingmachine/safe` 3
1217
## v6.3.0
1318

1419
### Added

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"ext-json": "*",
1919
"egulias/email-validator": "^2.1.17 || ^3 || ^4",
2020
"spatie/regex": "^1.4 || ^2 || ^3",
21-
"thecodingmachine/safe": "^1.3 || ^2",
21+
"thecodingmachine/safe": "^1.3 || ^2 || ^3",
2222
"webonyx/graphql-php": "^15"
2323
},
2424
"require-dev": {

src/DateScalar.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ public function parseValue($value): \DateTimeInterface
2929
public function parseLiteral($valueNode, ?array $variables = null): \DateTimeInterface
3030
{
3131
if (! $valueNode instanceof StringValueNode) {
32-
throw new Error(
33-
"Query error: Can only parse strings, got {$valueNode->kind}",
34-
$valueNode
35-
);
32+
throw new Error("Query error: Can only parse strings, got {$valueNode->kind}", $valueNode);
3633
}
3734

3835
return $this->tryParsingDate($valueNode->value, Error::class);

src/JSON.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ protected function decodeJSON(mixed $value): mixed
4747
// @phpstan-ignore-next-line we attempt unsafe values and let it throw
4848
$decoded = \Safe\json_decode($value);
4949
} catch (JsonException $jsonException) {
50-
throw new Error(
51-
$jsonException->getMessage()
52-
);
50+
throw new Error($jsonException->getMessage());
5351
}
5452

5553
return $decoded;

src/Regex.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ public function serialize($value): string
4848
$stringValue = Utils::coerceToString($value, InvariantViolation::class);
4949

5050
if (! static::matchesRegex($stringValue)) {
51-
throw new InvariantViolation(
52-
static::unmatchedRegexMessage($stringValue)
53-
);
51+
throw new InvariantViolation(static::unmatchedRegexMessage($stringValue));
5452
}
5553

5654
return $stringValue;
@@ -68,9 +66,7 @@ public function parseValue($value): string
6866
$stringValue = Utils::coerceToString($value, Error::class);
6967

7068
if (! static::matchesRegex($stringValue)) {
71-
throw new Error(
72-
static::unmatchedRegexMessage($stringValue)
73-
);
69+
throw new Error(static::unmatchedRegexMessage($stringValue));
7470
}
7571

7672
return $stringValue;
@@ -81,10 +77,7 @@ public function parseLiteral($valueNode, ?array $variables = null): string
8177
$value = Utils::extractStringFromLiteral($valueNode);
8278

8379
if (! static::matchesRegex($value)) {
84-
throw new Error(
85-
static::unmatchedRegexMessage($value),
86-
$valueNode
87-
);
80+
throw new Error(static::unmatchedRegexMessage($value), $valueNode);
8881
}
8982

9083
return $value;

src/StringScalar.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ public function serialize($value): string
4343
$stringValue = Utils::coerceToString($value, InvariantViolation::class);
4444

4545
if (! $this->isValid($stringValue)) {
46-
throw new InvariantViolation(
47-
$this->invalidStringMessage($stringValue)
48-
);
46+
throw new InvariantViolation($this->invalidStringMessage($stringValue));
4947
}
5048

5149
return $stringValue;
@@ -64,9 +62,7 @@ public function parseValue($value): string
6462
$stringValue = Utils::coerceToString($value, Error::class);
6563

6664
if (! $this->isValid($stringValue)) {
67-
throw new Error(
68-
$this->invalidStringMessage($stringValue)
69-
);
65+
throw new Error($this->invalidStringMessage($stringValue));
7066
}
7167

7268
return $stringValue;
@@ -77,10 +73,7 @@ public function parseLiteral($valueNode, ?array $variables = null): string
7773
$stringValue = Utils::extractStringFromLiteral($valueNode);
7874

7975
if (! $this->isValid($stringValue)) {
80-
throw new Error(
81-
$this->invalidStringMessage($stringValue),
82-
$valueNode
83-
);
76+
throw new Error($this->invalidStringMessage($stringValue), $valueNode);
8477
}
8578

8679
return $stringValue;

src/Utils.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ public static function canBeString(mixed $value): bool
2828
public static function extractStringFromLiteral(Node $valueNode): string
2929
{
3030
if (! $valueNode instanceof StringValueNode) {
31-
throw new Error(
32-
"Query error: Can only parse strings got: {$valueNode->kind}",
33-
$valueNode
34-
);
31+
throw new Error("Query error: Can only parse strings got: {$valueNode->kind}", $valueNode);
3532
}
3633

3734
return $valueNode->value;

0 commit comments

Comments
 (0)