Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow of execution #1

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/Processor/Ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,33 @@ public function getOutputTypes(): array
*/
public function coerce(mixed $value): ?IpAddress
{
// unhappy path: if (something wrong) terminate;
if (!class_exists(IpAddress::class)) {
throw Exceptional::ComponentUnavailable(
'IP validation requires decodelabs-compass package'
'IP validation requires decodelabs/compass package'
);
}

// unhappy path: if (something wrong) terminate;
if ($value === null) {
return null;
}

// unhappy path: if (something wrong) terminate;
if (
is_int($value) ||
$value instanceof BigInteger ||
is_string($value) ||
$value instanceof IpAddress
! is_int($value) &&
! $value instanceof BigInteger &&
! is_string($value) &&
! $value instanceof IpAddress
) {
return IpAddress::parse($value);
throw Exceptional::UnexpectedValue(
'Could not coerce value to Compass IP',
null,
$value
);
}

throw Exceptional::UnexpectedValue(
'Could not coerce value to Compass IP',
null,
$value
);
// the happy path 🍏
return IpAddress::parse($value);
}
}