Skip to content

Commit e2d6c94

Browse files
authored
Use prefix "is" for getters on boolean fields (#456)
1 parent 8011758 commit e2d6c94

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/Util/ClassSourceManipulator.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ public function addAccessorMethod(string $propertyName, string $methodName, $ret
253253

254254
public function addGetter(string $propertyName, $returnType, bool $isReturnTypeNullable, array $commentLines = []): void
255255
{
256-
$methodName = 'get'.Str::asCamelCase($propertyName);
257-
256+
$methodName = ('bool' === $returnType ? 'is' : 'get').Str::asCamelCase($propertyName);
258257
$this->addCustomGetter($propertyName, $methodName, $returnType, $isReturnTypeNullable, $commentLines);
259258
}
260259

tests/Util/ClassSourceManipulatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ public function getAddGetterTests()
100100
'User_simple.php',
101101
];
102102

103+
yield 'normal_getter_add_bool' => [
104+
'legacy/User_simple.php',
105+
'fooProp',
106+
'bool',
107+
[],
108+
'User_simple_bool.php',
109+
];
110+
103111
yield 'getter_no_props_comments' => [
104112
'User_no_props.php',
105113
'fooProp',
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Entity;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
/**
8+
* @ORM\Entity()
9+
*/
10+
class User
11+
{
12+
/**
13+
* @ORM\Id
14+
* @ORM\GeneratedValue
15+
* @ORM\Column(type="integer")
16+
*/
17+
private $id;
18+
19+
public function getId(): ?int
20+
{
21+
return $this->id;
22+
}
23+
24+
public function isFooProp(): ?bool
25+
{
26+
return $this->fooProp;
27+
}
28+
}

0 commit comments

Comments
 (0)