update v 1.0.7.5
This commit is contained in:
		
							
								
								
									
										51
									
								
								vendor/psy/psysh/src/Psy/CodeCleaner.php
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										51
									
								
								vendor/psy/psysh/src/Psy/CodeCleaner.php
									
									
									
									
										vendored
									
									
								
							| @@ -1,9 +1,9 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * This file is part of Psy Shell | ||||
|  * This file is part of Psy Shell. | ||||
|  * | ||||
|  * (c) 2012-2014 Justin Hileman | ||||
|  * (c) 2012-2015 Justin Hileman | ||||
|  * | ||||
|  * For the full copyright and license information, please view the LICENSE | ||||
|  * file that was distributed with this source code. | ||||
| @@ -11,7 +11,6 @@ | ||||
|  | ||||
| namespace Psy; | ||||
|  | ||||
| use PhpParser\Lexer; | ||||
| use PhpParser\NodeTraverser; | ||||
| use PhpParser\Parser; | ||||
| use PhpParser\PrettyPrinter\Standard as Printer; | ||||
| @@ -19,6 +18,7 @@ use Psy\CodeCleaner\AbstractClassPass; | ||||
| use Psy\CodeCleaner\AssignThisVariablePass; | ||||
| use Psy\CodeCleaner\CalledClassPass; | ||||
| use Psy\CodeCleaner\CallTimePassByReferencePass; | ||||
| use Psy\CodeCleaner\ExitPass; | ||||
| use Psy\CodeCleaner\FunctionReturnInWriteContextPass; | ||||
| use Psy\CodeCleaner\ImplicitReturnPass; | ||||
| use Psy\CodeCleaner\InstanceOfPass; | ||||
| @@ -27,6 +27,7 @@ use Psy\CodeCleaner\LegacyEmptyPass; | ||||
| use Psy\CodeCleaner\MagicConstantsPass; | ||||
| use Psy\CodeCleaner\NamespacePass; | ||||
| use Psy\CodeCleaner\StaticConstructorPass; | ||||
| use Psy\CodeCleaner\StrictTypesPass; | ||||
| use Psy\CodeCleaner\UseStatementPass; | ||||
| use Psy\CodeCleaner\ValidClassNamePass; | ||||
| use Psy\CodeCleaner\ValidConstantPass; | ||||
| @@ -53,7 +54,12 @@ class CodeCleaner | ||||
|      */ | ||||
|     public function __construct(Parser $parser = null, Printer $printer = null, NodeTraverser $traverser = null) | ||||
|     { | ||||
|         $this->parser    = $parser    ?: new Parser(new Lexer()); | ||||
|         if ($parser === null) { | ||||
|             $parserFactory = new ParserFactory(); | ||||
|             $parser        = $parserFactory->createParser(); | ||||
|         } | ||||
|  | ||||
|         $this->parser    = $parser; | ||||
|         $this->printer   = $printer   ?: new Printer(); | ||||
|         $this->traverser = $traverser ?: new NodeTraverser(); | ||||
|  | ||||
| @@ -81,11 +87,13 @@ class CodeCleaner | ||||
|             new ImplicitReturnPass(), | ||||
|             new UseStatementPass(),      // must run before namespace and validation passes | ||||
|             new NamespacePass($this),    // must run after the implicit return pass | ||||
|             new StrictTypesPass(), | ||||
|             new StaticConstructorPass(), | ||||
|             new ValidFunctionNamePass(), | ||||
|             new ValidClassNamePass(), | ||||
|             new ValidConstantPass(), | ||||
|             new MagicConstantsPass(), | ||||
|             new ExitPass(), | ||||
|         ); | ||||
|     } | ||||
|  | ||||
| @@ -101,7 +109,7 @@ class CodeCleaner | ||||
|      */ | ||||
|     public function clean(array $codeLines, $requireSemicolons = false) | ||||
|     { | ||||
|         $stmts = $this->parse("<?php " . implode(PHP_EOL, $codeLines) . PHP_EOL, $requireSemicolons); | ||||
|         $stmts = $this->parse('<?php ' . implode(PHP_EOL, $codeLines) . PHP_EOL, $requireSemicolons); | ||||
|         if ($stmts === false) { | ||||
|             return false; | ||||
|         } | ||||
| @@ -149,6 +157,10 @@ class CodeCleaner | ||||
|         try { | ||||
|             return $this->parser->parse($code); | ||||
|         } catch (\PhpParser\Error $e) { | ||||
|             if ($this->parseErrorIsUnclosedString($e, $code)) { | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             if (!$this->parseErrorIsEOF($e)) { | ||||
|                 throw ParseErrorException::fromParseError($e); | ||||
|             } | ||||
| @@ -170,6 +182,33 @@ class CodeCleaner | ||||
|     { | ||||
|         $msg = $e->getRawMessage(); | ||||
|  | ||||
|         return ($msg === "Unexpected token EOF") || (strpos($msg, "Syntax error, unexpected EOF") !== false); | ||||
|         return ($msg === 'Unexpected token EOF') || (strpos($msg, 'Syntax error, unexpected EOF') !== false); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * A special test for unclosed single-quoted strings. | ||||
|      * | ||||
|      * Unlike (all?) other unclosed statements, single quoted strings have | ||||
|      * their own special beautiful snowflake syntax error just for | ||||
|      * themselves. | ||||
|      * | ||||
|      * @param \PhpParser\Error $e | ||||
|      * @param string           $code | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     private function parseErrorIsUnclosedString(\PhpParser\Error $e, $code) | ||||
|     { | ||||
|         if ($e->getRawMessage() !== 'Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE') { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         try { | ||||
|             $this->parser->parse($code . "';"); | ||||
|         } catch (\Exception $e) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sujit Prasad
					Sujit Prasad