Skip to content

Commit 23ab62d

Browse files
committed
Bugfix for alias in use statements
1 parent 228000a commit 23ab62d

14 files changed

Lines changed: 166 additions & 171 deletions

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"require" : {
1818
"php" : ">=5.4.0",
1919
"gossi/docblock" : "~1",
20-
"doctrine/annotations" : "~1",
21-
"symfony/options-resolver" : "~2"
20+
"symfony/options-resolver" : "~2",
21+
"gossi/tokenizer" : "~0"
2222
},
2323
"autoload" : {
2424
"psr-4" : {

composer.lock

Lines changed: 44 additions & 126 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/model/AbstractPhpStruct.php

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use gossi\codegen\model\parts\QualifiedNameTrait;
2121
use gossi\codegen\model\parts\DocblockTrait;
2222
use gossi\codegen\model\parts\LongDescriptionTrait;
23-
use Doctrine\Common\Annotations\PhpParser;
2423

2524
/**
2625
* Represents an abstract php struct.
@@ -64,13 +63,6 @@ protected static function createMethod(\ReflectionMethod $method) {
6463
protected static function createProperty(\ReflectionProperty $property) {
6564
return PhpProperty::fromReflection($property);
6665
}
67-
68-
protected static function getUseStatementsFromReflection(\ReflectionClass $ref) {
69-
if (null === self::$phpParser) {
70-
self::$phpParser = new PhpParser();
71-
}
72-
return self::$phpParser->parseClass($ref);
73-
}
7466

7567
public function __construct($name = null) {
7668
$this->setQualifiedName($name);
@@ -94,7 +86,10 @@ public function addRequiredFile($file) {
9486
}
9587

9688
public function setUseStatements(array $useStatements) {
97-
$this->useStatements = $useStatements;
89+
$this->useStatements = [];
90+
foreach ($useStatements as $alias => $useStatement) {
91+
$this->addUseStatement($useStatement, $alias);
92+
}
9893

9994
return $this;
10095
}
@@ -106,7 +101,7 @@ public function setUseStatements(array $useStatements) {
106101
* @return $this
107102
*/
108103
public function addUseStatement($qualifiedName, $alias = null) {
109-
if (null === $alias) {
104+
if (!is_string($alias)) {
110105
if (false === strpos($qualifiedName, '\\')) {
111106
$alias = $qualifiedName;
112107
} else {
@@ -130,29 +125,6 @@ public function hasUseStatement($qualifiedName) {
130125
return isset($flipped[$qualifiedName]);
131126
}
132127

133-
// public function declareUses()
134-
// {
135-
// foreach (func_get_args() as $name) {
136-
// $this->declareUse($name);
137-
// }
138-
// }
139-
140-
// /**
141-
// * @param string $fullClassName
142-
// * @param null|string $alias
143-
// *
144-
// * @return string
145-
// */
146-
// public function declareUse($fullClassName, $alias = null)
147-
// {
148-
// $fullClassName = trim($fullClassName, '\\');
149-
// if (!$this->hasUseStatement($fullClassName)) {
150-
// $this->addUseStatement($fullClassName, $alias);
151-
// }
152-
153-
// return $this->getUseAlias($fullClassName);
154-
// }
155-
156128
/**
157129
* @param string $qualifiedName
158130
* @return string
@@ -253,7 +225,5 @@ public function generateDocblock() {
253225
foreach ($this->methods as $method) {
254226
$method->generateDocblock();
255227
}
256-
257-
// $this->setDocblock($docblock);
258228
}
259229
}

src/model/PhpClass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use gossi\codegen\model\parts\ConstantsTrait;
1010
use gossi\codegen\model\parts\PropertiesTrait;
1111
use gossi\codegen\model\parts\TraitsTrait;
12+
use gossi\codegen\utils\ReflectionUtils;
1213

1314
class PhpClass extends AbstractPhpStruct implements GenerateableInterface, TraitsInterface, ConstantsInterface {
1415

@@ -27,7 +28,7 @@ public static function fromReflection(\ReflectionClass $ref) {
2728
->setAbstract($ref->isAbstract())
2829
->setFinal($ref->isFinal())
2930
->setConstants($ref->getConstants())
30-
->setUseStatements(static::getUseStatementsFromReflection($ref));
31+
->setUseStatements(ReflectionUtils::getUseStatements($ref));
3132

3233
if ($ref->getDocComment()) {
3334
$docblock = new Docblock($ref);

src/model/PhpInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use gossi\docblock\Docblock;
55
use gossi\codegen\model\parts\InterfacesTrait;
66
use gossi\codegen\model\parts\ConstantsTrait;
7+
use gossi\codegen\utils\ReflectionUtils;
78

89
class PhpInterface extends AbstractPhpStruct implements GenerateableInterface, ConstantsInterface {
910

@@ -14,7 +15,7 @@ public static function fromReflection(\ReflectionClass $ref) {
1415
$interface = new static();
1516
$interface->setQualifiedName($ref->name)
1617
->setConstants($ref->getConstants())
17-
->setUseStatements(static::getUseStatementsFromReflection($ref));
18+
->setUseStatements(ReflectionUtils::getUseStatements($ref));
1819

1920
$docblock = new Docblock($ref);
2021
$interface->setDocblock($docblock);

src/model/PhpTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use gossi\docblock\Docblock;
55
use gossi\codegen\model\parts\PropertiesTrait;
66
use gossi\codegen\model\parts\TraitsTrait;
7-
use Doctrine\Common\Annotations\PhpParser;
7+
use gossi\codegen\utils\ReflectionUtils;
88

99
class PhpTrait extends AbstractPhpStruct implements GenerateableInterface, TraitsInterface {
1010

@@ -14,7 +14,7 @@ class PhpTrait extends AbstractPhpStruct implements GenerateableInterface, Trait
1414
public static function fromReflection(\ReflectionClass $ref) {
1515
$trait = new static();
1616
$trait->setQualifiedName($ref->name);
17-
$trait->setUseStatements(static::getUseStatementsFromReflection($ref));
17+
$trait->setUseStatements(ReflectionUtils::getUseStatements($ref));
1818

1919
$docblock = new Docblock($ref);
2020
$trait->setDocblock($docblock);

0 commit comments

Comments
 (0)