Skip to content

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

Merged
weaverryan merged 1 commit into
symfony:mainfrom
jrushlow:legacy/8
May 31, 2022
Merged

improve PHP 8 support w/ rector, removes legacy code, deprecates unused methods#1128
weaverryan merged 1 commit into
symfony:mainfrom
jrushlow:legacy/8

Conversation

@jrushlow

@jrushlow jrushlow commented May 24, 2022

Copy link
Copy Markdown
Collaborator
  • 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
try {
$metadata = $this->doctrineHelper->getMetadata($classOrNamespace);
} catch (MappingException|LegacyCommonMappingException|PersistenceMappingException $mappingException) {
} catch (MappingException|LegacyCommonMappingException|PersistenceMappingException) {

Copy link
Copy Markdown
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 thread src/Maker/MakeUser.php
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
Copy Markdown
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
Copy Markdown
Contributor

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

@weaverryan weaverryan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just minor stuff!

Comment thread src/Generator.php Outdated
Comment thread src/Maker/MakeUser.php
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes. This is correct :)

* @internal
*/
final class ClassNameValue
final class ClassNameValue implements \Stringable

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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