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

Commit

Permalink
🎨 Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
siguici committed Sep 27, 2024
1 parent 4bd8ad4 commit cc4dca0
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 154 deletions.
65 changes: 8 additions & 57 deletions src/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@

namespace Sikessem\Values;

use Sikessem\Values\Types\BoolType;
use Sikessem\Values\Types\FloatType;
use Sikessem\Values\Types\IntType;
use Sikessem\Values\Types\MixedType;
use Sikessem\Values\Types\NumberType;
use Sikessem\Values\Types\NumericType;
use Sikessem\Values\Types\ScalarType;
use Sikessem\Values\Types\StringType;

class Cast
{
public function __construct(protected mixed $value) {}
Expand All @@ -22,83 +13,43 @@ public static function from(mixed $value): self
return new self($value);
}

public function intoBool(): BoolType
public function intoBool(): BoolValue
{
return BoolValue::of($this->value);
}

public function intoInt(): IntType
public function intoInt(): IntValue
{
return IntValue::of($this->value);
}

public function intoFloat(): FloatType
public function intoFloat(): FloatValue
{
return FloatValue::of($this->value);
}

public function intoString(): StringType
public function intoString(): StringValue
{
return StringValue::of($this->value);
}

public function intoNumber(): NumberType
public function intoNumber(): NumberValue
{
return NumberValue::of($this->value);
}

public function intoNumeric(): NumericType
public function intoNumeric(): NumericValue
{
return NumericValue::of($this->value);
}

public function intoScalar(): ScalarType
public function intoScalar(): ScalarValue
{
return ScalarValue::of($this->value);
}

public function intoMixed(): MixedType
public function intoMixed(): MixedValue
{
return MixedValue::of($this->value);
}

public static function toBool(mixed $value): BoolType
{
return self::from($value)->intoBool();
}

public static function toInt(mixed $value): IntType
{
return self::from($value)->intoInt();
}

public static function toFloat(mixed $value): FloatType
{
return self::from($value)->intoFloat();
}

public static function toString(mixed $value): StringType
{
return self::from($value)->intoString();
}

public static function toNumber(mixed $value): NumberType
{
return self::from($value)->intoNumber();
}

public static function toNumeric(mixed $value): NumericType
{
return self::from($value)->intoNumeric();
}

public static function toScalar(mixed $value): ScalarType
{
return self::from($value)->intoScalar();
}

public static function toMixed(mixed $value): MixedType
{
return self::from($value)->intoMixed();
}
}
18 changes: 9 additions & 9 deletions src/Concerns/AsBool.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ trait AsBool
{
use AsScalar;

public function __invoke(mixed $value = null): bool
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}

abstract public function get(): bool;

/**
Expand All @@ -35,15 +44,6 @@ public static function of(mixed $value): self
));
}

public function __invoke(mixed $value = null): bool
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}

public function isTrue(): bool
{
return $this->get();
Expand Down
18 changes: 9 additions & 9 deletions src/Concerns/AsFloat.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ trait AsFloat
{
use AsNumber;

public function __invoke(mixed $value = null): float
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}

abstract public function get(): float;

/**
Expand All @@ -34,13 +43,4 @@ public static function of(mixed $value): self
get_debug_type($value),
));
}

public function __invoke(mixed $value = null): float
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}
}
18 changes: 9 additions & 9 deletions src/Concerns/AsInt.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ trait AsInt
{
use AsNumber;

public function __invoke(mixed $value = null): int
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}

abstract public function get(): int;

/**
Expand All @@ -34,13 +43,4 @@ public static function of(mixed $value): self
get_debug_type($value),
));
}

public function __invoke(mixed $value = null): int
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}
}
18 changes: 9 additions & 9 deletions src/Concerns/AsMixed.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@

trait AsMixed
{
public function __invoke(mixed $value = null): mixed
{
if ($value !== null) {
static::of($value)->get();
}

return $this->get();
}

abstract public function get(): mixed;

public static function of(mixed $value): self
Expand All @@ -31,13 +40,4 @@ public function to(string $type): MixedType
{
return $type::of($this->get());
}

public function __invoke(mixed $value = null): mixed
{
if ($value !== null) {
static::of($value)->get();
}

return $this->get();
}
}
18 changes: 9 additions & 9 deletions src/Concerns/AsNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ trait AsNumber
{
use AsNumeric;

public function __invoke(mixed $value = null): int|float
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}

abstract public function get(): int|float;

/**
Expand All @@ -34,13 +43,4 @@ public static function of(mixed $value): self
get_debug_type($value),
));
}

public function __invoke(mixed $value = null): int|float
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}
}
18 changes: 9 additions & 9 deletions src/Concerns/AsNumeric.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ trait AsNumeric
{
use AsScalar;

public function __invoke(mixed $value = null): int|float|string
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}

abstract public function get(): int|float|string;

/**
Expand All @@ -34,13 +43,4 @@ public static function of(mixed $value): self
get_debug_type($value),
));
}

public function __invoke(mixed $value = null): int|float|string
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}
}
20 changes: 10 additions & 10 deletions src/Concerns/AsScalar.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ trait AsScalar
public function __toString(): string
{
/** @psalm-suppress RedundantCast */
return (string) $this->get();
return $this->get();
}

public function __invoke(mixed $value = null): bool|int|float|string
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}

abstract public function get(): bool|int|float|string;
Expand Down Expand Up @@ -41,13 +50,4 @@ public static function of(mixed $value): self
get_debug_type($value),
));
}

public function __invoke(mixed $value = null): bool|int|float|string
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}
}
18 changes: 9 additions & 9 deletions src/Concerns/AsString.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ trait AsString
{
use AsScalar;

public function __invoke(mixed $value = null): string
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}

/**
* @throws \InvalidArgumentException If the value is not a string.
*/
Expand All @@ -32,13 +41,4 @@ public static function of(mixed $value): self
get_debug_type($value),
));
}

public function __invoke(mixed $value = null): string
{
if ($value !== null) {
return static::of($value)->get();
}

return $this->get();
}
}
12 changes: 2 additions & 10 deletions src/Types/BoolType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

interface BoolType extends ScalarType
{
public function __invoke(mixed $value = null): bool;

public function get(): bool;

public function isTrue(): bool;
Expand All @@ -15,14 +17,4 @@ 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;

public function __invoke(mixed $value = null): bool;
}
4 changes: 2 additions & 2 deletions src/Types/FloatType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

interface FloatType extends NumberType
{
public function get(): float;

public function __invoke(mixed $value = null): float;

public function get(): float;
}
4 changes: 2 additions & 2 deletions src/Types/IntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

interface IntType extends NumberType
{
public function get(): int;

public function __invoke(mixed $value = null): int;

public function get(): int;
}
Loading

0 comments on commit cc4dca0

Please sign in to comment.