X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FPsy%2FCodeCleaner%2FStaticConstructorPass.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FPsy%2FCodeCleaner%2FStaticConstructorPass.php;h=f0748a42bd16b789732bac24d6d80d34b68d1aa5;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/psy/psysh/src/Psy/CodeCleaner/StaticConstructorPass.php b/vendor/psy/psysh/src/Psy/CodeCleaner/StaticConstructorPass.php new file mode 100644 index 000000000..f0748a42b --- /dev/null +++ b/vendor/psy/psysh/src/Psy/CodeCleaner/StaticConstructorPass.php @@ -0,0 +1,87 @@ + + */ +class StaticConstructorPass extends CodeCleanerPass +{ + private $isPHP533; + private $namespace; + + public function __construct() + { + $this->isPHP533 = version_compare(PHP_VERSION, '5.3.3', '>='); + } + + public function beforeTraverse(array $nodes) + { + $this->namespace = array(); + } + + /** + * Validate that the old-style constructor function is not static. + * + * @throws FatalErrorException if the old-style constructor function is static + * + * @param Node $node + */ + public function enterNode(Node $node) + { + if ($node instanceof NamespaceStmt) { + $this->namespace = isset($node->name) ? $node->name->parts : array(); + } elseif ($node instanceof ClassStmt) { + // Bail early if this is PHP 5.3.3 and we have a namespaced class + if (!empty($this->namespace) && $this->isPHP533) { + return; + } + + $constructor = null; + foreach ($node->stmts as $stmt) { + if ($stmt instanceof ClassMethod) { + // Bail early if we find a new-style constructor + if ('__construct' === strtolower($stmt->name)) { + return; + } + + // We found a possible old-style constructor + // (unless there is also a __construct method) + if (strtolower($node->name) === strtolower($stmt->name)) { + $constructor = $stmt; + } + } + } + + if ($constructor && $constructor->isStatic()) { + throw new FatalErrorException(sprintf( + 'Constructor %s::%s() cannot be static', + implode('\\', array_merge($this->namespace, (array) $node->name)), + $constructor->name + )); + } + } + } +}