Skip to content

Commit

Permalink
Added methods toString() and __toString() for traits `FloatValueT…
Browse files Browse the repository at this point in the history
…rait`, `IntegerValueTrait` and `StringValueTrait`
  • Loading branch information
tg666 committed Apr 19, 2024
1 parent 484f2f1 commit f811790
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SixtyEightPublishers\ArchitectureBundle\Domain\Exception\InvalidNativeValueTypeException;
use SixtyEightPublishers\ArchitectureBundle\Domain\Exception\Typehint;
use function array_key_exists;
use function array_map;
use function count;
use function implode;

Expand Down Expand Up @@ -155,7 +156,13 @@ public function getValues(): array

public function toString(): string
{
return implode('/', $this->values);
return implode(
separator: '/',
array: array_map(
callback: \strval(...),
array: $this->values,
),
);
}

public function __toString(): string
Expand Down
10 changes: 10 additions & 0 deletions src/ArchitectureBundle/Domain/ValueObject/FloatValueTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public function equals(ValueObjectInterface $object): bool
return $object instanceof static && $object->toNative() === $this->toNative();
}

public function toString(): string
{
return (string) $this->toNative();
}

public function __toString(): string
{
return $this->toString();
}

protected function validate(): void
{
}
Expand Down
10 changes: 10 additions & 0 deletions src/ArchitectureBundle/Domain/ValueObject/IntegerValueTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public function equals(ValueObjectInterface $object): bool
return $object instanceof static && $object->toNative() === $this->toNative();
}

public function toString(): string
{
return (string) $this->toNative();
}

public function __toString(): string
{
return $this->toString();
}

protected function validate(): void
{
}
Expand Down
10 changes: 10 additions & 0 deletions src/ArchitectureBundle/Domain/ValueObject/StringValueTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public function equals(ValueObjectInterface $object): bool
return $object instanceof static && $object->toNative() === $this->toNative();
}

public function toString(): string
{
return $this->toNative();
}

public function __toString(): string
{
return $this->toString();
}

protected function validate(): void
{
}
Expand Down

0 comments on commit f811790

Please sign in to comment.