From 118f28344daf154e47e73e79779a60bc7430a40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Thu, 23 Jan 2014 13:33:02 +0100 Subject: [PATCH] Synchronized error messages with native php error messages --- grammar/zend_language_parser.phpy | 2 +- lib/PHPParser/Lexer.php | 4 ++-- lib/PHPParser/Node/Stmt/Class.php | 10 ++++----- lib/PHPParser/Node/Stmt/ClassMethod.php | 15 ++++++++----- lib/PHPParser/Node/Stmt/Interface.php | 6 ++--- lib/PHPParser/Node/Stmt/Namespace.php | 4 ++-- lib/PHPParser/Node/Stmt/UseUse.php | 4 ++-- lib/PHPParser/Parser.php | 2 +- .../code/parser/stmt/class/modifier.test-fail | 4 ++-- test/code/parser/stmt/class/name.test-fail | 22 +++++++++---------- .../parser/stmt/class/staticMethod.test-fail | 18 ++++++++++++--- .../stmt/haltCompilerInvalidSyntax.test-fail | 2 +- .../stmt/haltCompilerOutermostScope.test-fail | 2 +- .../code/parser/stmt/namespace/name.test-fail | 10 ++++----- 14 files changed, 61 insertions(+), 44 deletions(-) diff --git a/grammar/zend_language_parser.phpy b/grammar/zend_language_parser.phpy index 85d72b2..08ed192 100644 --- a/grammar/zend_language_parser.phpy +++ b/grammar/zend_language_parser.phpy @@ -166,7 +166,7 @@ inner_statement: statement { $$ = $1; } | function_declaration_statement { $$ = $1; } | class_declaration_statement { $$ = $1; } - | T_HALT_COMPILER { error('__halt_compiler() can only be used from the outermost scope'); } + | T_HALT_COMPILER { error('__HALT_COMPILER() can only be used from the outermost scope'); } ; statement: diff --git a/lib/PHPParser/Lexer.php b/lib/PHPParser/Lexer.php index b4202fc..35ece08 100644 --- a/lib/PHPParser/Lexer.php +++ b/lib/PHPParser/Lexer.php @@ -148,7 +148,7 @@ class PHPParser_Lexer // this simplifies the situation, by not allowing any comments // in between of the tokens. if (!preg_match('~\s*\(\s*\)\s*(?:;|\?>\r?\n?)~', $textAfter, $matches)) { - throw new PHPParser_Error('__halt_compiler must be followed by "();"'); + throw new PHPParser_Error('__HALT_COMPILER must be followed by "();"'); } // prevent the lexer from returning any further tokens @@ -192,4 +192,4 @@ class PHPParser_Lexer return $tokenMap; } -} \ No newline at end of file +} diff --git a/lib/PHPParser/Node/Stmt/Class.php b/lib/PHPParser/Node/Stmt/Class.php index 2585d98..d02d160 100644 --- a/lib/PHPParser/Node/Stmt/Class.php +++ b/lib/PHPParser/Node/Stmt/Class.php @@ -46,16 +46,16 @@ class PHPParser_Node_Stmt_Class extends PHPParser_Node_Stmt $this->name = $name; if (isset(self::$specialNames[(string) $this->name])) { - throw new PHPParser_Error(sprintf('Cannot use "%s" as class name as it is reserved', $this->name)); + throw new PHPParser_Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name)); } if (isset(self::$specialNames[(string) $this->extends])) { - throw new PHPParser_Error(sprintf('Cannot use "%s" as class name as it is reserved', $this->extends)); + throw new PHPParser_Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->extends)); } foreach ($this->implements as $interface) { if (isset(self::$specialNames[(string) $interface])) { - throw new PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $interface)); + throw new PHPParser_Error(sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface)); } } } @@ -96,7 +96,7 @@ class PHPParser_Node_Stmt_Class extends PHPParser_Node_Stmt } if ($a & 48 && $b & 48) { - throw new PHPParser_Error('Cannot use the final and abstract modifier at the same time'); + throw new PHPParser_Error('Cannot use the final modifier on an abstract class member'); } } -} \ No newline at end of file +} diff --git a/lib/PHPParser/Node/Stmt/ClassMethod.php b/lib/PHPParser/Node/Stmt/ClassMethod.php index 99c0c3d..c7945e3 100644 --- a/lib/PHPParser/Node/Stmt/ClassMethod.php +++ b/lib/PHPParser/Node/Stmt/ClassMethod.php @@ -33,10 +33,15 @@ class PHPParser_Node_Stmt_ClassMethod extends PHPParser_Node_Stmt ); $this->name = $name; - if (($this->type & PHPParser_Node_Stmt_Class::MODIFIER_STATIC) - && ('__construct' == $this->name || '__destruct' == $this->name || '__clone' == $this->name) - ) { - throw new PHPParser_Error(sprintf('"%s" method cannot be static', $this->name)); + if ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_STATIC) { + switch (strtolower($this->name)) { + case '__construct': + throw new PHPParser_Error(sprintf('Constructor %s() cannot be static', $this->name)); + case '__destruct': + throw new PHPParser_Error(sprintf('Destructor %s() cannot be static', $this->name)); + case '__clone': + throw new PHPParser_Error(sprintf('Clone method %s() cannot be static', $this->name)); + } } } @@ -63,4 +68,4 @@ class PHPParser_Node_Stmt_ClassMethod extends PHPParser_Node_Stmt public function isStatic() { return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_STATIC); } -} \ No newline at end of file +} diff --git a/lib/PHPParser/Node/Stmt/Interface.php b/lib/PHPParser/Node/Stmt/Interface.php index 8fc0241..ec811c9 100644 --- a/lib/PHPParser/Node/Stmt/Interface.php +++ b/lib/PHPParser/Node/Stmt/Interface.php @@ -33,13 +33,13 @@ class PHPParser_Node_Stmt_Interface extends PHPParser_Node_Stmt $this->name = $name; if (isset(self::$specialNames[(string) $this->name])) { - throw new PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $this->name)); + throw new PHPParser_Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name)); } foreach ($this->extends as $interface) { if (isset(self::$specialNames[(string) $interface])) { - throw new PHPParser_Error(sprintf('Cannot use "%s" as interface name as it is reserved', $interface)); + throw new PHPParser_Error(sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface)); } } } -} \ No newline at end of file +} diff --git a/lib/PHPParser/Node/Stmt/Namespace.php b/lib/PHPParser/Node/Stmt/Namespace.php index 7647239..f4064ce 100644 --- a/lib/PHPParser/Node/Stmt/Namespace.php +++ b/lib/PHPParser/Node/Stmt/Namespace.php @@ -29,7 +29,7 @@ class PHPParser_Node_Stmt_Namespace extends PHPParser_Node_Stmt ); if (isset(self::$specialNames[(string) $this->name])) { - throw new PHPParser_Error(sprintf('Cannot use "%s" as namespace name as it is reserved', $this->name)); + throw new PHPParser_Error(sprintf('Cannot use \'%s\' as namespace name', $this->name)); } if (null !== $this->stmts) { @@ -119,4 +119,4 @@ class PHPParser_Node_Stmt_Namespace extends PHPParser_Node_Stmt return $newStmts; } } -} \ No newline at end of file +} diff --git a/lib/PHPParser/Node/Stmt/UseUse.php b/lib/PHPParser/Node/Stmt/UseUse.php index 2287af0..d7d4fd6 100644 --- a/lib/PHPParser/Node/Stmt/UseUse.php +++ b/lib/PHPParser/Node/Stmt/UseUse.php @@ -20,7 +20,7 @@ class PHPParser_Node_Stmt_UseUse extends PHPParser_Node_Stmt if ('self' == $alias || 'parent' == $alias) { throw new PHPParser_Error(sprintf( - 'Cannot use "%s" as "%s" because "%2$s" is a special class name', + 'Cannot use %s as %s because \'%2$s\' is a special class name', $name, $alias )); } @@ -33,4 +33,4 @@ class PHPParser_Node_Stmt_UseUse extends PHPParser_Node_Stmt $attributes ); } -} \ No newline at end of file +} diff --git a/lib/PHPParser/Parser.php b/lib/PHPParser/Parser.php index fb30ce6..393aa80 100644 --- a/lib/PHPParser/Parser.php +++ b/lib/PHPParser/Parser.php @@ -1226,7 +1226,7 @@ class PHPParser_Parser } protected function yyn29($attributes) { - throw new PHPParser_Error('__halt_compiler() can only be used from the outermost scope'); + throw new PHPParser_Error('__HALT_COMPILER() can only be used from the outermost scope'); } protected function yyn30($attributes) { diff --git a/test/code/parser/stmt/class/modifier.test-fail b/test/code/parser/stmt/class/modifier.test-fail index b1bfc72..7272b4c 100644 --- a/test/code/parser/stmt/class/modifier.test-fail +++ b/test/code/parser/stmt/class/modifier.test-fail @@ -22,8 +22,8 @@ Multiple final modifiers are not allowed on line 1 -----