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

improve PHP 8 support w/ rector, removes legacy code, deprecates unused methods #1128

Merged
merged 1 commit into from
May 31, 2022

Conversation

jrushlow
Copy link
Collaborator

@jrushlow jrushlow commented May 24, 2022

  • removes Argon2 support with make:user
  • deprecates unused methods that are not final or internal
  • removes PHP 7.x version checks
  • uses rector (not included) to bring src up to PHP 8 standards

@jrushlow jrushlow changed the title WIP improve PHP 8 support w/ rector, removes legacy code, deprecates unused methods May 24, 2022
@jrushlow jrushlow added the Feature New Feature label May 24, 2022
@jrushlow jrushlow marked this pull request as ready for review May 24, 2022 21:02
} catch (MappingException|LegacyCommonMappingException|PersistenceMappingException $mappingException) {
} catch (MappingException|LegacyCommonMappingException|PersistenceMappingException) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doctrine\Common namespaced imports e.g. LegacyCommonMappingException will be removed in a separate PR as there are a lot of changes related to outdated legacy classes that need to be made based on a git grep

Comment on lines -146 to +151
// @legacy @todo - refactor for better naming conventions BEFORE next release.
$useAttributesForDoctrineMapping = $userClassConfiguration->isEntity() && ($this->doctrineHelper->isDoctrineSupportingAttributes()) && $this->doctrineHelper->doesClassUsesAttributes($userClassNameDetails->getFullName());
$entityUsesAttributes = ($isEntity = $userClassConfiguration->isEntity()) && $this->doctrineHelper->doesClassUsesAttributes($userClassNameDetails->getFullName());

if ($isEntity && !$entityUsesAttributes) {
throw new \RuntimeException('MakeUser only supports attribute mapping with doctrine entities.');
}

// B) Implement UserInterface
$manipulator = new ClassSourceManipulator(
sourceCode: $this->fileManager->getFileContents($classPath),
overwrite: true,
useAttributesForDoctrineMapping: $useAttributesForDoctrineMapping
useAttributesForDoctrineMapping: $entityUsesAttributes
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For make user we can gen a user that is not an entity - in which case we don't add any attributes to the generated class.. But if the user is an entity, we only generate it using attributes, otherwise we complain. Is my thinking correct on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is correct :)

@jrushlow jrushlow added the Status: Needs Review Needs to be reviewed label May 31, 2022
Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor stuff!

src/Generator.php Outdated Show resolved Hide resolved
Comment on lines -146 to +151
// @legacy @todo - refactor for better naming conventions BEFORE next release.
$useAttributesForDoctrineMapping = $userClassConfiguration->isEntity() && ($this->doctrineHelper->isDoctrineSupportingAttributes()) && $this->doctrineHelper->doesClassUsesAttributes($userClassNameDetails->getFullName());
$entityUsesAttributes = ($isEntity = $userClassConfiguration->isEntity()) && $this->doctrineHelper->doesClassUsesAttributes($userClassNameDetails->getFullName());

if ($isEntity && !$entityUsesAttributes) {
throw new \RuntimeException('MakeUser only supports attribute mapping with doctrine entities.');
}

// B) Implement UserInterface
$manipulator = new ClassSourceManipulator(
sourceCode: $this->fileManager->getFileContents($classPath),
overwrite: true,
useAttributesForDoctrineMapping: $useAttributesForDoctrineMapping
useAttributesForDoctrineMapping: $entityUsesAttributes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is correct :)

@@ -16,7 +16,7 @@
/**
* @internal
*/
final class ClassNameValue
final class ClassNameValue implements \Stringable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to implement this explicitly? I thought that any classes with __toString() automatically get the Stringable interface. I only see implements \Stringable 3 times in symfony/symfony, which leads me to believe that we generally don't add this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was one of the rector "auto fix it up" jobber dooers. Looking at the PHP Docs:

Unlike most interfaces, Stringable is implicitly present on any class that has the magic __toString() method defined, although it can and should be declared explicitly.

It's not really necessary per the docs other than they we it should be declared explicitly. Should we remove this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although it can and should be declared explicitly

Ok, fair enough - we can keep it :)

@weaverryan
Copy link
Member

Thanks Jesse - huge cleanup!

@weaverryan weaverryan merged commit 48c1634 into symfony:main May 31, 2022
@jrushlow jrushlow deleted the legacy/8 branch May 31, 2022 13:22
@jrushlow jrushlow mentioned this pull request Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants