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

Do not add use if has same namespace than current namespace #96

Closed
wants to merge 1 commit into from

Conversation

maximecaze
Copy link

  • bug fix
  • BC break? no
  • doc PR: -

Do not print uses for namespace uses issued from the same namespace

@dg
Copy link
Member

dg commented Nov 12, 2021

Can you add a test to see what it does?

@maximecaze
Copy link
Author

After consideration, I am not sure this change is legitimate, but I am curious of this change 0e283d9#diff-d20ef32e1a8b64805a08e16ce09ecafc0eb6487be1c47b8bd0766857b596244b. Before that, when we add uses of the same namespace than the generated class, the use does not appear, because there is no need.

Ex with a generated class FooBar:

$extends = Foo\Bar::class;
$file = new \Nette\PhpGenerator\PhpFile();
$namespace = $file->addNamespace('Foo')->addUse($extends);
$class = $namespace->addClass('FooBar');
$class->setExtends($extends);
...
<?php 

namespace Foo;

use Foo/Bar; // no need of that because of Bar class has same namespace than FooBar class

class FooBar extends Bar {}

What do you think ?
I am sorry, I am not confortable with these tests yet, I did not succeed to write the correct test...

@dg
Copy link
Member

dg commented Nov 16, 2021

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants