Skip to content

Commit 4c6a988

Browse files
committed
Fix getObjectName()
When there is a getter without a prefix and a setter there is a difference in getObjectName because there are two differents keys. For example: we had "myVar" and "MyVar" for the same property called "myVar".
1 parent d2c7582 commit 4c6a988

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/DtoTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Roave\BetterReflection\Reflection\ReflectionClass;
1818
use Roave\BetterReflection\Reflection\ReflectionMethod;
1919
use RuntimeException;
20+
use function lcfirst;
2021

2122
abstract class DtoTest extends TestCase
2223
{
@@ -146,6 +147,6 @@ private function getObjectName(bool $isGetterWithoutPrefix, string $methodName):
146147
return $methodName;
147148
}
148149

149-
return mb_substr($methodName, mb_substr($methodName, 0, 2) === 'is' ? 2 : 3);
150+
return lcfirst(mb_substr($methodName, mb_substr($methodName, 0, 2) === 'is' ? 2 : 3));
150151
}
151152
}

tests/PHPUnit/Primitive.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class Primitive
4242
/** @var self */
4343
private $primitiveImmutable;
4444

45+
/** @var string */
46+
private $string2;
47+
4548
public function isBool(): bool
4649
{
4750
return $this->bool;
@@ -121,4 +124,14 @@ public function primitiveImmutable(): self
121124
{
122125
return $this->primitiveImmutable;
123126
}
127+
128+
public function string2(): string
129+
{
130+
return $this->string2;
131+
}
132+
133+
public function setString2(string $string): void
134+
{
135+
$this->string2 = $string;
136+
}
124137
}

0 commit comments

Comments
 (0)