-
-
Notifications
You must be signed in to change notification settings - Fork 420
(Update #589) Replace Generator by EntityClassGenerator in MakerResetPassword #590
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor things - keep going! :)
src/Maker/MakeResetPassword.php
Outdated
); | ||
$this->fileManager->dumpFile($pathRequestRepository, $manipulator->getSourceCode()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think putting all of this new code into a private method in this class might be nice. Or, its own class, which could then be unit tested a bit easier - like UserClassBuilder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a new private method like you said first because i think this stuff is really specific to this command with a good test coverage. See if you like :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting close!
src/Maker/MakeResetPassword.php
Outdated
'@ORM\Id()', | ||
'@ORM\GeneratedValue()', | ||
'@ORM\Column(type="integer")', | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is not needed anymore. And ClassSourceManipulator
is just ignoring it because it's already there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/Doctrine/BaseRelation.php
Outdated
@@ -19,8 +19,11 @@ abstract class BaseRelation | |||
private $propertyName; | |||
private $targetClassName; | |||
private $targetPropertyName; | |||
private $returnType; | |||
private $returnTypeIsNullable = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private $returnTypeIsNullable = true; | |
private $returnTypeIsNullable; |
I just don't want this to have a default value... so let's leave it null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And maybe we should call these properties:overriddenReturnType
and isOverriddenReturnTypeNullable
... because that's what they really are. If they are not set, then it means that the "default" return type of the related class would be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor stuff left!
composer.json
Outdated
"branch-alias": { | ||
"dev-master": "1.0-dev" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be reverted - your editor may have done this automatically
public function isOverriddenReturnTypeNullable(): bool | ||
{ | ||
return $this->overriddenReturnType; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I may have confused you. Here is how I would expect the new parts of this class to look (I'm also changing the name "overridden" to "custom"):
private $customReturnType;
private $isCustomReturnTypeNullable;
public function getCustomReturnType(): ?string
{
return $this->customReturnType;
}
public function isCustomReturnTypeNullable(): bool
{
return $this->isCustomReturnTypeNullable;
}
public function setCustomReturnType(string $customReturnType, bool $isNullable): void
{
$this->customReturnType = $customReturnType;
$this->isCustomReturnTypeNullable = $isNullable;
}
Then, in ClassSourceManipulator
, when we use this, the code would be:
$this->addGetter(
$relation->getPropertyName(),
$typeHint,
$relation->getCustomReturnType() ?: $typeHint,
// getter methods always have nullable return values
// unless this has been customized explicitly
$relation->getCustomReturnType() ? $relation->isCustomReturnTypeNullable() : $typeHint,
$relation->isOverriddenReturnTypeNullable()
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, without modifying other parts of the MakerBundle, i think we should do things like this in BaseRelation
private $customReturnType;
private $isCustomReturnTypeNullable = true;
public function isCustomReturnTypeNullable(): bool
{
return $this->isCustomReturnTypeNullable;
}
public function setCustomReturnType(string $customReturnType, bool $isNullable)
{
$this->customReturnType = $customReturnType;
$this->isCustomReturnTypeNullable = $isNullable;
return $this;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this in ClassSourceManipulator
$this->addGetter(
$relation->getPropertyName(),
$relation->getCustomReturnType() ?: $typeHint,
// getter methods always have nullable return values
// unless this has been customized explicitly
$relation->isCustomReturnTypeNullable()
);
return $this->isNullable; | ||
} | ||
|
||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think (?) this isn't needed. It's true that isNullable
could be null, but the :bool
return type will cast null into a false
boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/Maker/MakeResetPassword.php
Outdated
|
||
$manipulator->addManyToOneRelation((new RelationManyToOne()) | ||
->setPropertyName('user') | ||
->setTargetClassName("App\Entity\User") // customization fail in php 7.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the problem in PHP 7.3? We need to be explicit. And if there IS a problem currently in 7.3, then that's a block for the PR and we should be clear that this is still a "TODO" (like by posting a comment about it in the PR or in the PR description)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not php 7.3, i wrote that because only the test for php 7.3 failed in travis.
$this->assertStringContainsString('@ORM\ManyToOne(targetEntity="App\Entity\UserCustom")', $contentResetPasswordRequest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jrushlow added new code. Our targetClass is generaated as a fetch class UserCustom::class
not in FQCN "App\Entity\UserCustom"
src/Maker/MakeResetPassword.php
Outdated
<?php | ||
parent::__construct($registry, ResetPasswordRequest::class); | ||
CODE | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we talked about, if we want to avoid the comments in the repository class, let's pass an argument to EntityClassGenerator::generateEntityClass()
to make it not generate the comments. That method name is getting a little long, but that's ok - it's an internal class.
src/Util/ClassSourceManipulator.php
Outdated
{ | ||
$this->getClassNode()->stmts = []; | ||
$this->updateSourceCodeFromNewStmts(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully this won't be needed at the end :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VERY close - I'm quite pleased with this PR
Thank you @archeoprog! |
…rushlow) This PR was squashed before being merged into the 1.0-dev branch. Discussion ---------- [Internal] [User] removed unused service from make:user PR #590 added `DoctrineHelper` to `MakeResetPassword` but the service is never used. Commits ------- a49d6f2 [Internal] [User] removed unused service from make:user
UPDATE PULL REQUEST #589
At the request of Ryan Weaver.
I replaced the use of Generator by EntityClassGenerator.
We then needed to use ClassSourceManipulator and i propose to add 3 methods to this class, tests included.
I also propose to add two optional parameters to the $manipulator->addMethodBuilder() method: array $params = [], string $methodBody = null;
Allowing to build methods more directly when needed.