Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Issue #4669 - Class generator should return uses from file generator #5152

Closed
wants to merge 2 commits into from

Conversation

robertmarsal
Copy link
Contributor

Propagate file generator uses to class generator. Fixes issue #4669.

@Maks3w
Copy link
Member

Maks3w commented Oct 3, 2013

Seems correct but I've a question. You are adding all uses to all classes but exists the possibility that not all uses are used by all classes.

Could you add only the necessary uses for each class extracted?

@robertmarsal
Copy link
Contributor Author

I thought of that but I don't see how to separate the uses by class as I can not see where the instances are created. But from what I understand if someoane defines two classes in the same file and sets up a uses definition is because both classes require it, if not better use two different files right?

It's tricky, but if you have any suggestion I am open to ideas, thanks!

foreach ($fileReflection->getClasses() as $class) {
$phpClass = ClassGenerator::fromReflection($class);
$phpClass->setContainingFileGenerator($file);

if ($uses) {
Copy link
Member

Choose a reason for hiding this comment

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

Due getUses definition and implementation $uses will be always an array so there is no need of this if

@Maks3w
Copy link
Member

Maks3w commented Oct 20, 2013

@robertboloc The same algos used for detect unused use statements by CS fixers can be used here.

https://github.com/fabpot/PHP-CS-Fixer/blob/master/Symfony/CS/Fixer/UnusedUseStatementsFixer.php

@weierophinney
Copy link
Member

@Maks3w that algorithm will not work here, as it's operating on the entire file, and not the individual classes in the file.

Considering the most common use case is one class per file, I think the solution as proposed here is fine.

weierophinney added a commit that referenced this pull request Oct 23, 2013
Issue #4669 - Class generator should return uses from file generator
weierophinney added a commit that referenced this pull request Oct 23, 2013
@ghost ghost assigned weierophinney Oct 23, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants