From 000f12c26d55ee883f6dea02ad5fac141db7410a Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sun, 14 Sep 2014 00:19:31 -0400 Subject: [PATCH 1/7] Switch to stable php-parser release. Just one more to go :) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 70b8302c8..9fadd3b11 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require": { "php": ">=5.3.0", "symfony/console": ">=2.3.10, <2.6.0", - "nikic/php-parser": "~1.0@dev", + "nikic/php-parser": "~1.0", "dnoegel/php-xdg-base-dir": "dev-master@dev" }, "require-dev": { From 1e703a483c5dec2e6551084d9df87f910bbb660d Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Thu, 23 Oct 2014 17:50:27 +0200 Subject: [PATCH 2/7] Fixed closures issue --- .gitignore | 1 + src/Psy/CodeCleaner/ValidFunctionNamePass.php | 9 +++++++-- .../Test/CodeCleaner/ValidFunctionNamePassTest.php | 2 ++ test/Psy/Test/ShellTest.php | 11 +++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 74df2cee9..df066ece4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor/ composer.lock manual/ __pycache__ +.idea diff --git a/src/Psy/CodeCleaner/ValidFunctionNamePass.php b/src/Psy/CodeCleaner/ValidFunctionNamePass.php index 2741238cf..70ecab0a8 100644 --- a/src/Psy/CodeCleaner/ValidFunctionNamePass.php +++ b/src/Psy/CodeCleaner/ValidFunctionNamePass.php @@ -12,7 +12,10 @@ namespace Psy\CodeCleaner; use PhpParser\Node; +use PhpParser\Node\Expr\Assign; +use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\Function_ as FunctionStmt; use Psy\Exception\FatalErrorException; @@ -45,10 +48,12 @@ public function leaveNode(Node $node) } elseif ($node instanceof FuncCall) { // if function name is an expression, give it a pass for now. $name = $node->name; - if (!$name instanceof Expression) { + if ($name instanceof Variable) { + $fullName = sprintf('\\Closure::%s', $name->name); + $this->currentScope[$fullName] = true; + }else if (!$name instanceof Expression) { $shortName = implode('\\', $name->parts); $fullName = $this->getFullyQualifiedName($name); - if ( !isset($this->currentScope[strtolower($fullName)]) && !function_exists($shortName) && diff --git a/test/Psy/Test/CodeCleaner/ValidFunctionNamePassTest.php b/test/Psy/Test/CodeCleaner/ValidFunctionNamePassTest.php index 1d85e966d..0087eee62 100644 --- a/test/Psy/Test/CodeCleaner/ValidFunctionNamePassTest.php +++ b/test/Psy/Test/CodeCleaner/ValidFunctionNamePassTest.php @@ -109,6 +109,8 @@ function theta() {} theta(); } "), + // closures + array('$test = function(){};$test()'), array(" namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass { function theta() {} diff --git a/test/Psy/Test/ShellTest.php b/test/Psy/Test/ShellTest.php index 02ba3c2cf..284ef0a6f 100644 --- a/test/Psy/Test/ShellTest.php +++ b/test/Psy/Test/ShellTest.php @@ -212,6 +212,17 @@ public function testCodeBufferThrowsParseExceptions() $shell->flushCode(); } + public function testClosuresSupport() + { + $shell = new Shell($this->getConfig()); + $code = '$test = function () {}'; + $shell->addCode($code); + $shell->flushCode(); + $code = '$test()'; + $shell->addCode($code); + $shell->flushCode(); + } + public function testWriteStdout() { $output = $this->getOutput(); From af92aa91eb89ed063a027dc562ec5fb86b902b13 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Thu, 23 Oct 2014 11:12:16 -0700 Subject: [PATCH 3/7] This belongs in `~/.gitignore` :) --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index df066ece4..74df2cee9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ vendor/ composer.lock manual/ __pycache__ -.idea From 0392d49ac8352d7397dea051cb399e31aa87379d Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Thu, 23 Oct 2014 11:12:36 -0700 Subject: [PATCH 4/7] No need to store the variable name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …we won’t use it anyway. --- src/Psy/CodeCleaner/ValidFunctionNamePass.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Psy/CodeCleaner/ValidFunctionNamePass.php b/src/Psy/CodeCleaner/ValidFunctionNamePass.php index 70ecab0a8..91c59d524 100644 --- a/src/Psy/CodeCleaner/ValidFunctionNamePass.php +++ b/src/Psy/CodeCleaner/ValidFunctionNamePass.php @@ -12,8 +12,6 @@ namespace Psy\CodeCleaner; use PhpParser\Node; -use PhpParser\Node\Expr\Assign; -use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\Function_ as FunctionStmt; @@ -46,12 +44,9 @@ public function leaveNode(Node $node) $this->currentScope[strtolower($name)] = true; } elseif ($node instanceof FuncCall) { - // if function name is an expression, give it a pass for now. + // if function name is an expression or a variable, give it a pass for now. $name = $node->name; - if ($name instanceof Variable) { - $fullName = sprintf('\\Closure::%s', $name->name); - $this->currentScope[$fullName] = true; - }else if (!$name instanceof Expression) { + if (!$name instanceof Expression && !$name instanceof Variable) { $shortName = implode('\\', $name->parts); $fullName = $this->getFullyQualifiedName($name); if ( From 7fb63b90270e67618a5d96580cd32fb3cc770efe Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Fri, 24 Oct 2014 07:51:56 -0700 Subject: [PATCH 5/7] Use php-xdg-base-dir v0.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … so we can tag a stable release! --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9fadd3b11..e5f46cfde 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "php": ">=5.3.0", "symfony/console": ">=2.3.10, <2.6.0", "nikic/php-parser": "~1.0", - "dnoegel/php-xdg-base-dir": "dev-master@dev" + "dnoegel/php-xdg-base-dir": "0.1" }, "require-dev": { "phpunit/phpunit": ">=3.7, <4.3", From 0eeb1caff7c56c6ea4820f8684d1acd515941728 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Fri, 24 Oct 2014 08:08:20 -0700 Subject: [PATCH 6/7] Use dev-develop instead of dev-master MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Technically that’s where 0.2.x development happens. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e5f46cfde..4323b4e49 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "bin": ["bin/psysh"], "extra": { "branch-alias": { - "dev-master": "0.2.0-dev" + "dev-develop": "0.2.x-dev" } } } From 7d982152d2504fa94fdfa2155fdb4a331cf28c26 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Fri, 24 Oct 2014 08:08:42 -0700 Subject: [PATCH 7/7] Version bump to v0.2.1 --- src/Psy/Shell.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Psy/Shell.php b/src/Psy/Shell.php index 99f3c4fd8..fa339b018 100644 --- a/src/Psy/Shell.php +++ b/src/Psy/Shell.php @@ -39,7 +39,7 @@ */ class Shell extends Application { - const VERSION = 'v0.2.0'; + const VERSION = 'v0.2.1'; const PROMPT = '>>> '; const BUFF_PROMPT = '... ';