-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/fix/resolving-const-root-namespace'
* origin/fix/resolving-const-root-namespace: Fix code-style issues from Nitpick Add root namespace normalization, resolves #39 Conflicts: src/ReflectionEngine.php
- Loading branch information
Showing
6 changed files
with
129 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Parser Reflection API | ||
* | ||
* @copyright Copyright 2016, Lisachenko Alexander <[email protected]> | ||
* | ||
* This source file is subject to the license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Go\ParserReflection\NodeVisitor; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Name\FullyQualified; | ||
use PhpParser\Node\Stmt\Namespace_; | ||
use PhpParser\NodeVisitorAbstract; | ||
|
||
/** | ||
* Visitor to normalize the root namespace for the files without the namespace (root namespace) | ||
* | ||
* File->Namespace->Statements | ||
*/ | ||
class RootNamespaceNormalizer extends NodeVisitorAbstract | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function beforeTraverse(array $nodes) | ||
{ | ||
// namespaces can be only top-level nodes, so we can scan them directly | ||
foreach ($nodes as $topLevelNode) { | ||
if ($topLevelNode instanceof Namespace_) { | ||
// file has namespace in it, nothing to change, returning null | ||
return null; | ||
} | ||
} | ||
|
||
// if we don't have a namespaces at all, this is global namespace, wrap everything in it | ||
$globalNamespaceNode = new Namespace_(new FullyQualified(''), $nodes); | ||
|
||
return [$globalNamespaceNode]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,66 @@ | ||
<?php | ||
|
||
namespace Go\ParserReflection\Stub; | ||
|
||
use Go\ParserReflection\ReflectionParameter; | ||
|
||
const TEST_PARAMETER = 42; | ||
|
||
function noParameters() {} | ||
function singleParameter($test) {} | ||
function miscParameters( | ||
array $arrayParam, | ||
array $arrayParamWithDefault = array(1,2,3), | ||
array $arrayNullable = null, | ||
callable $callableParam, | ||
callable $callableNullable = null, | ||
\stdClass $objectParam, | ||
\stdClass $objectNullable = null, | ||
ReflectionParameter $typehintedParamWithNs, | ||
&$byReferenceParam, | ||
&$byReferenceNullable = __CLASS__, | ||
$constParam = TEST_PARAMETER, | ||
$constValueParam = __NAMESPACE__, // This line is long and should be truncated | ||
\Traversable $traversable | ||
) {} | ||
|
||
class Foo { | ||
const CLASS_CONST = __CLASS__; | ||
|
||
public function methodParam($firstParam, $optionalParam = null) {} | ||
public function methodParamConst($firstParam = self::CLASS_CONST, $another = __CLASS__, $ns = TEST_PARAMETER) {} | ||
namespace { | ||
function testResolveDefaults($a = null, $b = false, $c = true) | ||
{ | ||
} | ||
|
||
class TestParametersForRootNsClass | ||
{ | ||
public function foo($a = null, $b = false, $c = true) | ||
{ | ||
} | ||
} | ||
} | ||
|
||
class SubFoo extends Foo { | ||
public function anotherMethodParam(self $selfParam, parent $parentParam) {} | ||
namespace Go\ParserReflection\Stub { | ||
|
||
use Go\ParserReflection\ReflectionParameter; | ||
|
||
const TEST_PARAMETER = 42; | ||
|
||
function noParameters() | ||
{ | ||
} | ||
|
||
function singleParameter($test) | ||
{ | ||
} | ||
|
||
function miscParameters( | ||
array $arrayParam, | ||
array $arrayParamWithDefault = array(1, 2, 3), | ||
array $arrayNullable = null, | ||
callable $callableParam, | ||
callable $callableNullable = null, | ||
\stdClass $objectParam, | ||
\stdClass $objectNullable = null, | ||
ReflectionParameter $typehintedParamWithNs, | ||
&$byReferenceParam, | ||
&$byReferenceNullable = __CLASS__, | ||
$constParam = TEST_PARAMETER, | ||
$constValueParam = __NAMESPACE__, // This line is long and should be truncated | ||
\Traversable $traversable | ||
) { | ||
} | ||
|
||
class Foo | ||
{ | ||
const CLASS_CONST = __CLASS__; | ||
|
||
public function methodParam($firstParam, $optionalParam = null) | ||
{ | ||
} | ||
|
||
public function methodParamConst($firstParam = self::CLASS_CONST, $another = __CLASS__, $ns = TEST_PARAMETER) | ||
{ | ||
} | ||
} | ||
|
||
class SubFoo extends Foo | ||
{ | ||
public function anotherMethodParam(self $selfParam, parent $parentParam) | ||
{ | ||
} | ||
} | ||
} |