Skip to content

Commit

Permalink
Merge branch 'release/0.9.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed Oct 13, 2018
2 parents ed3c32c + 8bcf9cd commit 9aaf295
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 13 deletions.
1 change: 0 additions & 1 deletion box.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"compactors": [
"KevinGH\\Box\\Compactor\\Php"
],
"chmod": "0755",
"blacklist": [
"grammar",
"test_old",
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"symfony/var-dumper": "~2.7|~3.0|~4.0",
"nikic/php-parser": "~1.3|~2.0|~3.0|~4.0",
"dnoegel/php-xdg-base-dir": "0.1",
"jakub-onderka/php-console-highlighter": "0.3.*"
"jakub-onderka/php-console-highlighter": "0.3.*|0.4.*"
},
"require-dev": {
"phpunit/phpunit": "~4.8.35|~5.0|~6.0|~7.0",
Expand Down
14 changes: 7 additions & 7 deletions src/CodeCleaner/ListPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\List_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use Psy\Exception\ParseErrorException;
Expand Down Expand Up @@ -99,14 +101,12 @@ private static function isValidArrayItem(Expr $item)
{
$value = ($item instanceof ArrayItem) ? $item->value : $item;

if ($value instanceof Variable) {
return true;
while ($value instanceof ArrayDimFetch || $value instanceof PropertyFetch) {
$value = $value->var;
}

if ($value instanceof ArrayDimFetch || $value instanceof PropertyFetch) {
return isset($value->var) && $value->var instanceof Variable;
}

return false;
// We just kind of give up if it's a method call. We can't tell if it's
// valid via static analysis.
return $value instanceof Variable || $value instanceof MethodCall || $value instanceof FuncCall;
}
}
4 changes: 3 additions & 1 deletion src/ExecutionLoopClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function __construct(Shell $__psysh__)

try {
// Pull in any new execution scope variables
\extract($__psysh__->getScopeVariablesDiff(\get_defined_vars()));
if ($__psysh__->getLastExecSuccess()) {
\extract($__psysh__->getScopeVariablesDiff(\get_defined_vars()));
}

// Buffer stdout; we'll need it later
\ob_start([$__psysh__, 'writeStdout'], 1);
Expand Down
2 changes: 1 addition & 1 deletion src/Readline/Transient.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function readline($prompt = null)
{
echo $prompt;

return \rtrim(\fgets($this->getStdin(), 1024));
return \rtrim(\fgets($this->getStdin()), "\n\r");
}

/**
Expand Down
18 changes: 17 additions & 1 deletion src/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/
class Shell extends Application
{
const VERSION = 'v0.9.8';
const VERSION = 'v0.9.9';

const PROMPT = '>>> ';
const BUFF_PROMPT = '... ';
Expand All @@ -73,6 +73,7 @@ class Shell extends Application
private $autoCompleter;
private $matchers = [];
private $commandsMatcher;
private $lastExecSuccess = true;

/**
* Create a new Psy Shell.
Expand Down Expand Up @@ -963,6 +964,8 @@ public function writeStdout($out, $phase = PHP_OUTPUT_HANDLER_END)
*/
public function writeReturnValue($ret)
{
$this->lastExecSuccess = true;

if ($ret instanceof NoReturnValue) {
return;
}
Expand All @@ -986,11 +989,24 @@ public function writeReturnValue($ret)
*/
public function writeException(\Exception $e)
{
$this->lastExecSuccess = false;
$this->context->setLastException($e);
$this->output->writeln($this->formatException($e));
$this->resetCodeBuffer();
}

/**
* Check whether the last exec was successful.
*
* Returns true if a return value was logged rather than an exception.
*
* @return bool
*/
public function getLastExecSuccess()
{
return $this->lastExecSuccess;
}

/**
* Helper for formatting an exception for writeException().
*
Expand Down
6 changes: 6 additions & 0 deletions test/CodeCleaner/ListPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ public function validStatements()
['[$a,,$c] = [1,2,3]'],
['[$a,,,] = [1,2,3]'],
['[$a[0], $a[1]] = [1, 2]'],
['[$a[0][0][0], $a[0][0][1]] = [1, 2]'],
['[$a->b, $a->c] = [1, 2]'],
['[$a->b[0], $a->c[1]] = [1, 2]'],
['[$a[0]->b[0], $a[0]->c[1]] = [1, 2]'],
['[$a[$b->c + $b->d]] = [1]'],
['[$a->c()->d, $a->c()->e] = [1, 2]'],
['[x()->a, x()->b] = [1, 2]'],
]);
}

Expand Down
2 changes: 1 addition & 1 deletion vendor-bin/box/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"humbug/box": "^3.0@alpha"
"humbug/box": "^3.1"
}
}

0 comments on commit 9aaf295

Please sign in to comment.