Mercurial > hg > cmmr2012-drupal-site
comparison vendor/psy/psysh/src/CodeCleaner/NamespaceAwarePass.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of Psy Shell. | |
5 * | |
6 * (c) 2012-2018 Justin Hileman | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Psy\CodeCleaner; | |
13 | |
14 use PhpParser\Node; | |
15 use PhpParser\Node\Name; | |
16 use PhpParser\Node\Name\FullyQualified as FullyQualifiedName; | |
17 use PhpParser\Node\Stmt\Namespace_; | |
18 | |
19 /** | |
20 * Abstract namespace-aware code cleaner pass. | |
21 */ | |
22 abstract class NamespaceAwarePass extends CodeCleanerPass | |
23 { | |
24 protected $namespace; | |
25 protected $currentScope; | |
26 | |
27 /** | |
28 * @todo should this be final? Extending classes should be sure to either | |
29 * use afterTraverse or call parent::beforeTraverse() when overloading. | |
30 * | |
31 * Reset the namespace and the current scope before beginning analysis | |
32 */ | |
33 public function beforeTraverse(array $nodes) | |
34 { | |
35 $this->namespace = []; | |
36 $this->currentScope = []; | |
37 } | |
38 | |
39 /** | |
40 * @todo should this be final? Extending classes should be sure to either use | |
41 * leaveNode or call parent::enterNode() when overloading | |
42 * | |
43 * @param Node $node | |
44 */ | |
45 public function enterNode(Node $node) | |
46 { | |
47 if ($node instanceof Namespace_) { | |
48 $this->namespace = isset($node->name) ? $node->name->parts : []; | |
49 } | |
50 } | |
51 | |
52 /** | |
53 * Get a fully-qualified name (class, function, interface, etc). | |
54 * | |
55 * @param mixed $name | |
56 * | |
57 * @return string | |
58 */ | |
59 protected function getFullyQualifiedName($name) | |
60 { | |
61 if ($name instanceof FullyQualifiedName) { | |
62 return implode('\\', $name->parts); | |
63 } elseif ($name instanceof Name) { | |
64 $name = $name->parts; | |
65 } elseif (!is_array($name)) { | |
66 $name = [$name]; | |
67 } | |
68 | |
69 return implode('\\', array_merge($this->namespace, $name)); | |
70 } | |
71 } |