Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
✨ Handle bool
Browse files Browse the repository at this point in the history
  • Loading branch information
siguici committed Nov 15, 2023
1 parent e3bbca1 commit 0b412d8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Concerns/AsBool.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,44 @@ public static function from(mixed $value): self
get_debug_type($value),
));
}

public function isTrue(): bool
{
return $this->get();
}

public function isFalse(): bool
{
return ! $this->get();
}

public function toTrue(): self
{
return static::from(true);
}

public function toFalse(): self
{
return static::from(false);
}

public static function isTruthy(bool $value): bool
{
return static::from($value)->isTrue();
}

public static function isFalsy(bool $value): bool
{
return static::from($value)->isFalse();
}

public static function truthify(mixed $value): self
{
return static::from($value)->toTrue();
}

public static function falsify(mixed $value): self
{
return static::from($value)->toFalse();
}
}
16 changes: 16 additions & 0 deletions src/Contracts/BoolType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,20 @@
interface BoolType extends ScalarType
{
public function get(): bool;

public function isTrue(): bool;

public function isFalse(): bool;

public function toTrue(): self;

public function toFalse(): self;

public static function isTruthy(bool $value): bool;

public static function isFalsy(bool $value): bool;

public static function truthify(mixed $value): self;

public static function falsify(mixed $value): self;
}

0 comments on commit 0b412d8

Please sign in to comment.