Skip to content

Commit d2b260c

Browse files
committedDec 10, 2024··
bug #1621 [make-entity]Keep the 'is' prefixes for booleans properties setters (octoseth)
This PR was merged into the 1.x-dev branch. Discussion ---------- [make-entity]Keep the 'is' prefixes for booleans properties setters When generating a new entity, if we name a boolean property with the prefix "is", this prefix is removed to construct the setter. example: ``` bool $isInternational; public function isInternational(): ?bool { return $this->isInternational; } public function setInternational(bool $isInternational): static { $this->isInternational = $isInternational; return $this; } ``` This is breaking when we want to access the property via a form : > [NoSuchPropertyException] > HTTP 500 Internal Server Error > The method "isInternational" in class "App\Entity\Conference" requires 0 arguments, but should accept only 1.. Make the property public, add a setter, or set the "mapped" field option in the form type to be false. This PR revert this change introduce in [PR 1493](#1493) to keep the 'is' prefix on the setter. example : ``` public function setIsInternational(bool $isInternational): static { $this->isInternational = $isInternational; return $this; } ``` Commits ------- 9fa9221 Keep the 'is' prefix on a boolean property when making the setter
2 parents 348e80a + 9fa9221 commit d2b260c

File tree

3 files changed

+2
-6
lines changed

3 files changed

+2
-6
lines changed
 

‎src/Util/ClassSourceManipulator.php

-4
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,6 @@ private function createSetterNodeBuilder(string $propertyName, $type, bool $isNu
485485

486486
private function getSetterName(string $propertyName, $type): string
487487
{
488-
if ('bool' === $type && 0 === strncasecmp($propertyName, 'is', 2)) {
489-
return 'set'.Str::asCamelCase(substr($propertyName, 2));
490-
}
491-
492488
return 'set'.Str::asCamelCase($propertyName);
493489
}
494490

‎templates/verifyEmail/EmailVerifier.tpl.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function handleEmailConfirmation(Request $request, <?= $user_class_name ?
4343
{
4444
$this->verifyEmailHelper->validateEmailConfirmationFromRequest($request, (string) $user-><?= $id_getter ?>(), (string) $user-><?= $email_getter?>());
4545

46-
$user->setVerified(true);
46+
$user->setIsVerified(true);
4747

4848
$this->entityManager->persist($user);
4949
$this->entityManager->flush();

‎tests/Util/fixtures/add_setter/User_bool_begins_with_is.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function getId(): ?int
1717
return $this->id;
1818
}
1919

20-
public function setFooProp(bool $isFooProp): static
20+
public function setIsFooProp(bool $isFooProp): static
2121
{
2222
$this->isFooProp = $isFooProp;
2323

0 commit comments

Comments
 (0)
Please sign in to comment.