Skip to content

Leading slash in alias use at class line #137

@ghost

Description

Version: 4.1.0 RC

Bug Description

The generator stores a regular 'as'-alias, but outputs it with a leading slash.

Steps To Reproduce

$ns = new PhpNamespace('Me\My\Action');
$target = new ClassType('MyAction');
$target->setFinal()->setExtends('ParentClass')->addComment('{@inheritDoc}');
$ns->add($target);
$ns->addUse('Their\Package\ParentClass', 'ParentClass');
echo var_dump($ns, (string) $ns);

Dump:

object(Nette\PhpGenerator\PhpNamespace)#4 (5) {
  ["name":"Nette\PhpGenerator\PhpNamespace":private]=>string(12) "Me\My\Action"
  ["bracketedSyntax":"Nette\PhpGenerator\PhpNamespace":private]=> bool(false)
  ["aliases":"Nette\PhpGenerator\PhpNamespace":private]=> array(3) {
    ["n"]=> array(1) {
      ["ParentClass"]=> string(25) "Their\Package\ParentClass"
    }
    ["f"]=> array(0) {}
    ["c"]=> array(0) {}
  }
  ["classes":"Nette\PhpGenerator\PhpNamespace":private]=> array(1) {
    ["myclass"]=> object(Nette\PhpGenerator\ClassType)#2 (14) {
      ["namespace":"Nette\PhpGenerator\ClassLike":private]=> NULL
      ["name":"Nette\PhpGenerator\ClassLike":private]=> string(7) "MyClass"
      ["comment":"Nette\PhpGenerator\ClassLike":private]=> string(13) "{@inheritDoc}"
      ["attributes":"Nette\PhpGenerator\ClassLike":private]=> array(0) {}
      ["type":"Nette\PhpGenerator\ClassType":private]=> string(5) "class"
      ["final":"Nette\PhpGenerator\ClassType":private]=> bool(true)
      ["abstract":"Nette\PhpGenerator\ClassType":private]=> bool(false)
      ["extends":"Nette\PhpGenerator\ClassType":private]=> string(11) "ParentClass"
      ["readOnly":"Nette\PhpGenerator\ClassType":private]=> bool(false)
      ["implements":"Nette\PhpGenerator\ClassType":private]=> array(0) {}
      ["consts":"Nette\PhpGenerator\ClassType":private]=> array(0) {}
      ["methods":"Nette\PhpGenerator\ClassType":private]=> array(0) {}
      ["properties":"Nette\PhpGenerator\ClassType":private]=> array(0) {}
      ["traits":"Nette\PhpGenerator\ClassType":private]=> array(0) {}
    }
  }
  ["functions":"Nette\PhpGenerator\PhpNamespace":private]=> array(0) {}
}

output

namespace Me\My\Action;

use Their\Package\ParentClass;

/**
 * {@inheritDoc}
 */
final class MyClass extends \ParentClass
{
}

Expected Behavior

namespace Me\My\Action;

use Their\Package\ParentClass;

/**
 * {@inheritDoc}
 */
final class MyClass extends ParentClass
{
}

If I'm blind and wrong somewhere, point me in the right place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions