Skip to content

Commit

Permalink
Merge pull request #1 from szepeviktor/patch-1
Browse files Browse the repository at this point in the history
Flow of execution
  • Loading branch information
betterthanclay authored Oct 26, 2023
2 parents 281025f + 3451b83 commit 24cf44b
Showing 1 changed file with 15 additions and 11 deletions.
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);
}
}

0 comments on commit 24cf44b

Please sign in to comment.