Skip to content

Commit 253b5c7

Browse files
committed
Fix uuid to string methods - #24
1 parent 362efa5 commit 253b5c7

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"scripts": {
5555
"check": [
5656
"@cs",
57-
"@test"
57+
"@test",
58+
"@static-analysis"
5859
],
5960
"cs": "php-cs-fixer fix -v --diff --dry-run",
6061
"cs-fix": "php-cs-fixer fix -v --diff",

src/ValueObject/UuidFactory.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ public function classBuilderFromNative(string $name): ClassBuilder
118118
$this->methodToString($name)->generate(),
119119
$this->methodEquals($name)->generate(),
120120
$this->methodMagicToString($name)->generate(),
121-
)->setTyped($this->typed);
121+
)->setTyped($this->typed)
122+
->addNamespaceImport(
123+
'Ramsey\Uuid\Uuid',
124+
'Ramsey\Uuid\UuidInterface',
125+
);
122126
}
123127

124128
public function methodFromString(string $argumentName): MethodGenerator
@@ -164,7 +168,7 @@ public function methodToString(string $propertyName): MethodGenerator
164168
'toString',
165169
[],
166170
MethodGenerator::FLAG_PUBLIC,
167-
new BodyGenerator($this->parser, 'return $this->' . $propertyName . ';')
171+
new BodyGenerator($this->parser, 'return $this->' . $propertyName . '->toString();')
168172
);
169173
$method->setTyped($this->typed);
170174
$method->setReturnType('string');
@@ -207,7 +211,7 @@ public function methodMagicToString(string $propertyName): MethodGenerator
207211
'__toString',
208212
[],
209213
MethodGenerator::FLAG_PUBLIC,
210-
new BodyGenerator($this->parser, 'return $this->' . $propertyName . ';')
214+
new BodyGenerator($this->parser, 'return $this->' . $propertyName . '->toString();')
211215
);
212216
$method->setTyped($this->typed);
213217
$method->setReturnType('string');

tests/ValueObject/UuidFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private function __construct(UuidInterface $uuid)
101101
}
102102
public function toString() : string
103103
{
104-
return $this->uuid;
104+
return $this->uuid->toString();
105105
}
106106
public function equals($other) : bool
107107
{
@@ -112,7 +112,7 @@ public function equals($other) : bool
112112
}
113113
public function __toString() : string
114114
{
115-
return $this->uuid;
115+
return $this->uuid->toString();
116116
}
117117
}
118118
EOF;

0 commit comments

Comments
 (0)