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

[make:entity] addGetter on boolean field that starts with "is" #1492

Closed
ClemRiviere opened this issue Mar 26, 2024 · 1 comment
Closed

[make:entity] addGetter on boolean field that starts with "is" #1492

ClemRiviere opened this issue Mar 26, 2024 · 1 comment
Labels
Feature New Feature

Comments

@ClemRiviere
Copy link
Contributor

Hi devs,

Context

Here is an exemple of an Entity created with a "isFooProp" boolean field :

> symfony console make:entity Test
 created: src/Entity/Test.php
 created: src/Repository/TestRepository.php
 
 Entity generated! Now let's add some fields!
 You can always add more fields later manually or by re-running this command.

 New property name (press <return> to stop adding fields):
 > isFooProp

 Field type (enter ? to see all types) [boolean]:
 > 

 Can this field be null in the database (nullable) (yes/no) [no]:
 > 

 updated: src/Entity/Test.php

Current behavior

This is the resulting entity :

#[ORM\Entity(repositoryClass: TestRepository::class)]
class Test
{
   ...
    #[ORM\Column]
    private ?bool $isFooProp = null;
    ...

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

    public function setIsFooProp(bool $isFooProp): static
    ...
}

Proposed behavior

#[ORM\Entity(repositoryClass: TestRepository::class)]
class Test
{
   ...
    #[ORM\Column]
    private ?bool $isFooProp = null;
    ...

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

    public function setIsFooProp(bool $isFooProp): static
    ...
}

I already worked on this modification and should be able to propose a PR, I just wanted to have your feedback on this topic before. All comments are welcome :)

@jrushlow jrushlow added the Feature New Feature label Mar 26, 2024
@jrushlow
Copy link
Collaborator

jrushlow commented Mar 26, 2024

Howdy @ClemRiviere - I'm not opposed to the idea. I've actually run into the same issue in the past - though in practice I tend to lean towards "non-verb" naming conventions for class properties. Looking forward to reviewing your PR.

Suggest - is & has prefixes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature
Projects
None yet
Development

No branches or pull requests

2 participants