Skip to content

Commit

Permalink
Merge branch 'release/v0.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Oct 25, 2023
2 parents 8aa1e1d + f96fdaa commit ca5defe
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.4.1 (2023-10-25)
* Coerce null scalar values if type required

## v0.4.0 (2023-10-18)
* Refactored main interface methods
* Refactored package file structure
Expand Down
2 changes: 1 addition & 1 deletion src/Processor/BoolNative.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getOutputTypes(): array
public function coerce(mixed $value): ?bool
{
if ($value === null) {
return null;
return $this->isRequired() ? false : null;
}

if (is_bool($value)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Processor/FloatNative.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getOutputTypes(): array
public function coerce(mixed $value): ?float
{
if ($value === null) {
return null;
return $this->isRequired() ? 0 : null;
}

return Coercion::toFloat($value);
Expand Down
2 changes: 1 addition & 1 deletion src/Processor/IntNative.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getOutputTypes(): array
public function coerce(mixed $value): ?int
{
if ($value === null) {
return null;
return $this->isRequired() ? 0 : null;
}

return Coercion::toInt($value);
Expand Down
10 changes: 10 additions & 0 deletions src/ProcessorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ protected function checkConstraintTypes(
}


protected function isRequired(): bool
{
if (!isset($this->constraints['required'])) {
return false;
}

return (bool)$this->constraints['required']->getParameter();
}


public function getDefaultConstraints(): array
{
return [];
Expand Down

0 comments on commit ca5defe

Please sign in to comment.