Skip to content

Commit ccba5af

Browse files
aymanrbclaude
andcommitted
Add getOrFail() shorthand to ParseResult for explicit strict key access
get(\$key, true) works but requires reading the boolean argument at every call site to understand its intent. getOrFail() expresses the strict contract directly in its name and returns a non-nullable string, giving callers a cleaner type signature without requiring an assertion or null-coalesce at the call site. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 46bb70c commit ccba5af

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/ParseResult.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ public function get(string $resultDataKey, bool $failOnUndefinedKey = false): ?s
6666
return $this->parsedRawData[$resultDataKey];
6767
}
6868

69+
public function getOrFail(string $resultDataKey): string
70+
{
71+
if (!$this->keyExists($resultDataKey)) {
72+
throw new InvalidParsedDataKeyException('Undefined results key: ' . $resultDataKey);
73+
}
74+
75+
return $this->parsedRawData[$resultDataKey];
76+
}
77+
6978
private function cleanData(): void
7079
{
7180
$this->parsedRawData = array_map($this->cleanElement(...), $this->parsedRawData);

0 commit comments

Comments
 (0)