Skip to content

Commit

Permalink
Use prefix "is" for getters on boolean fields (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximePinot authored May 9, 2022
1 parent 8011758 commit e2d6c94
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Util/ClassSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ public function addAccessorMethod(string $propertyName, string $methodName, $ret

public function addGetter(string $propertyName, $returnType, bool $isReturnTypeNullable, array $commentLines = []): void
{
$methodName = 'get'.Str::asCamelCase($propertyName);

$methodName = ('bool' === $returnType ? 'is' : 'get').Str::asCamelCase($propertyName);
$this->addCustomGetter($propertyName, $methodName, $returnType, $isReturnTypeNullable, $commentLines);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Util/ClassSourceManipulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public function getAddGetterTests()
'User_simple.php',
];

yield 'normal_getter_add_bool' => [
'legacy/User_simple.php',
'fooProp',
'bool',
[],
'User_simple_bool.php',
];

yield 'getter_no_props_comments' => [
'User_no_props.php',
'fooProp',
Expand Down
28 changes: 28 additions & 0 deletions tests/Util/fixtures/add_getter/User_simple_bool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity()
*/
class User
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;

public function getId(): ?int
{
return $this->id;
}

public function isFooProp(): ?bool
{
return $this->fooProp;
}
}

0 comments on commit e2d6c94

Please sign in to comment.