Skip to content

Commit be1f426

Browse files
committed
* Implemented method getKeywordLocation() to StaticKeywordAnalysisException
* Empty enum arrays are now allowed (according to specification)
1 parent 8d2b794 commit be1f426

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/Keyword/Exception/StaticKeywordAnalysisException.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@
99

1010
class StaticKeywordAnalysisException extends JsonSchemaEvaluatorException
1111
{
12+
private readonly string $keywordLocation;
13+
1214
public function __construct(
1315
string $message,
1416
private readonly StaticKeywordInterface $keyword,
1517
private readonly StaticEvaluationContext $context
1618
) {
17-
parent::__construct(
18-
sprintf($message, $this->keyword->getName())
19-
. ' at location '
20-
. $context->getCurrentSchemaKeywordLocation()
21-
);
19+
parent::__construct(sprintf($message, $this->keyword->getName()));
20+
$this->keywordLocation = $context->getCurrentSchemaKeywordLocation();
21+
}
22+
23+
public function getKeywordLocation(): string
24+
{
25+
return $this->keywordLocation;
2226
}
2327

2428
public function getContext(): StaticEvaluationContext

src/Keyword/Validation/EnumKeyword.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public function getName(): string
2525
*/
2626
public function evaluateStatic(mixed &$keywordValue, StaticEvaluationContext $context): void
2727
{
28-
if (!is_array($keywordValue) || !$keywordValue) {
28+
if (!is_array($keywordValue)) {
2929
throw new InvalidKeywordValueException(
30-
'The value of \'%s\' must be a non-empty array.',
30+
'The value of \'%s\' must be an array.',
3131
$this,
3232
$context
3333
);

tests/Unit/Keyword/Exception/StaticKeywordAnalysisExceptionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ public function test(): void
2222
$this->assertEquals('test123', $exception->getMessage());
2323
$this->assertEquals($keyword, $exception->getKeyword());
2424
$this->assertEquals($staticContext, $exception->getContext());
25+
$this->assertEquals('', $exception->getKeywordLocation());
2526
}
2627
}

0 commit comments

Comments
 (0)