Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use prefix "is" for getters on boolean fields #456

Merged
merged 6 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}