diff --git a/lib/PhpParser/Lexer.php b/lib/PhpParser/Lexer.php index c299045..2a99a3c 100644 --- a/lib/PhpParser/Lexer.php +++ b/lib/PhpParser/Lexer.php @@ -48,13 +48,15 @@ class Lexer * @throws Error on lexing errors (unterminated comment or unexpected character) */ public function startLexing($code) { - $scream = ini_set('xdebug.scream', 0); + $scream = ini_set('xdebug.scream', '0'); $this->resetErrors(); $this->tokens = @token_get_all($code); $this->handleErrors(); - ini_set('xdebug.scream', $scream); + if (false !== $scream) { + ini_set('xdebug.scream', $scream); + } $this->code = $code; // keep the code around for __halt_compiler() handling $this->pos = -1; @@ -76,7 +78,7 @@ class Lexer '~^Unterminated comment starting line ([0-9]+)$~', $error['message'], $matches )) { - throw new Error('Unterminated comment', $matches[1]); + throw new Error('Unterminated comment', (int) $matches[1]); } if (preg_match( diff --git a/lib/PhpParser/Node/Stmt/Namespace_.php b/lib/PhpParser/Node/Stmt/Namespace_.php index 2778d6d..49b1490 100644 --- a/lib/PhpParser/Node/Stmt/Namespace_.php +++ b/lib/PhpParser/Node/Stmt/Namespace_.php @@ -22,7 +22,7 @@ class Namespace_ extends Node\Stmt * Constructs a namespace node. * * @param null|Node\Name $name Name - * @param Node[] $stmts Statements + * @param null|Node[] $stmts Statements * @param array $attributes Additional attributes */ public function __construct(Node\Name $name = null, $stmts = array(), array $attributes = array()) { diff --git a/lib/PhpParser/NodeVisitor/NameResolver.php b/lib/PhpParser/NodeVisitor/NameResolver.php index c825d6e..52b0587 100644 --- a/lib/PhpParser/NodeVisitor/NameResolver.php +++ b/lib/PhpParser/NodeVisitor/NameResolver.php @@ -140,7 +140,7 @@ class NameResolver extends NodeVisitorAbstract protected function resolveClassName(Name $name) { // don't resolve special class names - if (in_array(strtolower($name), array('self', 'parent', 'static'))) { + if (in_array(strtolower($name->toString()), array('self', 'parent', 'static'))) { if (!$name->isUnqualified()) { throw new Error( sprintf("'\\%s' is an invalid class name", $name->toString()), diff --git a/lib/PhpParser/Serializer/XML.php b/lib/PhpParser/Serializer/XML.php index 9a27adb..a21b1ee 100644 --- a/lib/PhpParser/Serializer/XML.php +++ b/lib/PhpParser/Serializer/XML.php @@ -57,7 +57,7 @@ class XML implements Serializer } elseif ($node instanceof Comment) { $this->writer->startElement('comment'); $this->writer->writeAttribute('isDocComment', $node instanceof Comment\Doc ? 'true' : 'false'); - $this->writer->writeAttribute('line', $node->getLine()); + $this->writer->writeAttribute('line', (string) $node->getLine()); $this->writer->text($node->getText()); $this->writer->endElement(); } elseif (is_array($node)) { @@ -69,9 +69,10 @@ class XML implements Serializer } elseif (is_string($node)) { $this->writer->writeElement('scalar:string', $node); } elseif (is_int($node)) { - $this->writer->writeElement('scalar:int', $node); + $this->writer->writeElement('scalar:int', (string) $node); } elseif (is_float($node)) { - $this->writer->writeElement('scalar:float', $node); + // TODO Higher precision conversion? + $this->writer->writeElement('scalar:float', (string) $node); } elseif (true === $node) { $this->writer->writeElement('scalar:true'); } elseif (false === $node) { @@ -82,4 +83,4 @@ class XML implements Serializer throw new \InvalidArgumentException('Unexpected node type'); } } -} \ No newline at end of file +} diff --git a/lib/PhpParser/Unserializer.php b/lib/PhpParser/Unserializer.php index 1e3a7db..bfa6da0 100644 --- a/lib/PhpParser/Unserializer.php +++ b/lib/PhpParser/Unserializer.php @@ -9,7 +9,7 @@ interface Unserializer * * @param string $string Serialized string * - * @return array Statements + * @return mixed Node tree */ public function unserialize($string); } diff --git a/lib/PhpParser/Unserializer/XML.php b/lib/PhpParser/Unserializer/XML.php index dd77b00..1d8405f 100644 --- a/lib/PhpParser/Unserializer/XML.php +++ b/lib/PhpParser/Unserializer/XML.php @@ -102,11 +102,7 @@ class XML implements Unserializer case 'string': return $this->reader->readString(); case 'int': - $text = $this->reader->readString(); - if (false === $int = filter_var($text, FILTER_VALIDATE_INT)) { - throw new DomainException(sprintf('"%s" is not a valid integer', $text)); - } - return $int; + return $this->parseInt($this->reader->readString()); case 'float': $text = $this->reader->readString(); if (false === $float = filter_var($text, FILTER_VALIDATE_FLOAT)) { @@ -125,6 +121,13 @@ class XML implements Unserializer } } + private function parseInt($text) { + if (false === $int = filter_var($text, FILTER_VALIDATE_INT)) { + throw new DomainException(sprintf('"%s" is not a valid integer', $text)); + } + return $int; + } + protected function readComment() { $className = $this->reader->getAttribute('isDocComment') === 'true' ? 'PhpParser\Comment\Doc' @@ -132,7 +135,7 @@ class XML implements Unserializer ; return new $className( $this->reader->readString(), - $this->reader->getAttribute('line') + $this->parseInt($this->reader->getAttribute('line')) ); } diff --git a/test/PhpParser/Builder/InterfaceTest.php b/test/PhpParser/Builder/InterfaceTest.php index 6146120..c0d2fe3 100644 --- a/test/PhpParser/Builder/InterfaceTest.php +++ b/test/PhpParser/Builder/InterfaceTest.php @@ -47,10 +47,10 @@ class InterfaceTest extends \PHPUnit_Framework_TestCase public function testAddConst() { $const = new Stmt\ClassConst(array( - new Node\Const_('SPEED_OF_LIGHT', new DNumber(299792458)) + new Node\Const_('SPEED_OF_LIGHT', new DNumber(299792458.0)) )); $contract = $this->builder->addStmt($const)->getNode(); - $this->assertSame(299792458, $contract->stmts[0]->consts[0]->value->value); + $this->assertSame(299792458.0, $contract->stmts[0]->consts[0]->value->value); } public function testOrder() { diff --git a/test/PhpParser/CodeTestAbstract.php b/test/PhpParser/CodeTestAbstract.php index 774e8e1..d22617e 100644 --- a/test/PhpParser/CodeTestAbstract.php +++ b/test/PhpParser/CodeTestAbstract.php @@ -11,8 +11,8 @@ abstract class CodeTestAbstract extends \PHPUnit_Framework_TestCase $tests = array(); foreach ($it as $file) { - // read file - $fileContents = file_get_contents($file); + $fileName = realpath($file->getPathname()); + $fileContents = file_get_contents($fileName); // evaluate @@{expr}@@ expressions $fileContents = preg_replace_callback( @@ -25,7 +25,6 @@ abstract class CodeTestAbstract extends \PHPUnit_Framework_TestCase $parts = array_map('trim', explode('-----', $fileContents)); // first part is the name - $fileName = realpath($file->getPathname()); $name = array_shift($parts) . ' (' . $fileName . ')'; // multiple sections possible with always two forming a pair