X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FCodeCleaner%2FAbstractClassPass.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FCodeCleaner%2FAbstractClassPass.php;h=66eaf42c144ac995e6e45ae77ec6e973e0a9fcd4;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/psy/psysh/src/CodeCleaner/AbstractClassPass.php b/vendor/psy/psysh/src/CodeCleaner/AbstractClassPass.php new file mode 100644 index 000000000..66eaf42c1 --- /dev/null +++ b/vendor/psy/psysh/src/CodeCleaner/AbstractClassPass.php @@ -0,0 +1,71 @@ +class = $node; + $this->abstractMethods = []; + } elseif ($node instanceof ClassMethod) { + if ($node->isAbstract()) { + $name = sprintf('%s::%s', $this->class->name, $node->name); + $this->abstractMethods[] = $name; + + if ($node->stmts !== null) { + $msg = sprintf('Abstract function %s cannot contain body', $name); + throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine()); + } + } + } + } + + /** + * @throws RuntimeException if the node is a non-abstract class with abstract methods + * + * @param Node $node + */ + public function leaveNode(Node $node) + { + if ($node instanceof Class_) { + $count = count($this->abstractMethods); + if ($count > 0 && !$node->isAbstract()) { + $msg = sprintf( + 'Class %s contains %d abstract method%s must therefore be declared abstract or implement the remaining methods (%s)', + $node->name, + $count, + ($count === 1) ? '' : 's', + implode(', ', $this->abstractMethods) + ); + throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine()); + } + } + } +}