Skip to content

Commit

Permalink
Fix uuid to string methods - #24
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrokeil committed Feb 16, 2021
1 parent 362efa5 commit 253b5c7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"scripts": {
"check": [
"@cs",
"@test"
"@test",
"@static-analysis"
],
"cs": "php-cs-fixer fix -v --diff --dry-run",
"cs-fix": "php-cs-fixer fix -v --diff",
Expand Down
10 changes: 7 additions & 3 deletions src/ValueObject/UuidFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ public function classBuilderFromNative(string $name): ClassBuilder
$this->methodToString($name)->generate(),
$this->methodEquals($name)->generate(),
$this->methodMagicToString($name)->generate(),
)->setTyped($this->typed);
)->setTyped($this->typed)
->addNamespaceImport(
'Ramsey\Uuid\Uuid',
'Ramsey\Uuid\UuidInterface',
);
}

public function methodFromString(string $argumentName): MethodGenerator
Expand Down Expand Up @@ -164,7 +168,7 @@ public function methodToString(string $propertyName): MethodGenerator
'toString',
[],
MethodGenerator::FLAG_PUBLIC,
new BodyGenerator($this->parser, 'return $this->' . $propertyName . ';')
new BodyGenerator($this->parser, 'return $this->' . $propertyName . '->toString();')
);
$method->setTyped($this->typed);
$method->setReturnType('string');
Expand Down Expand Up @@ -207,7 +211,7 @@ public function methodMagicToString(string $propertyName): MethodGenerator
'__toString',
[],
MethodGenerator::FLAG_PUBLIC,
new BodyGenerator($this->parser, 'return $this->' . $propertyName . ';')
new BodyGenerator($this->parser, 'return $this->' . $propertyName . '->toString();')
);
$method->setTyped($this->typed);
$method->setReturnType('string');
Expand Down
4 changes: 2 additions & 2 deletions tests/ValueObject/UuidFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private function __construct(UuidInterface $uuid)
}
public function toString() : string
{
return $this->uuid;
return $this->uuid->toString();
}
public function equals($other) : bool
{
Expand All @@ -112,7 +112,7 @@ public function equals($other) : bool
}
public function __toString() : string
{
return $this->uuid;
return $this->uuid->toString();
}
}
EOF;
Expand Down

0 comments on commit 253b5c7

Please sign in to comment.