Skip to content

Commit

Permalink
Merge branch 'release/0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed Dec 27, 2014
2 parents 72a20b8 + f21175d commit b2c76a6
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 38 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
6 changes: 3 additions & 3 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use Symfony\CS\Config\Config;
use Symfony\CS\FixerInterface;

$config = Config::create()
// use default level and extra fixers:
// use symfony level and extra fixers:
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers(array('-concat_without_spaces', 'concat_with_spaces', 'strict'))
->setUsingCache(true)
->setUsingLinter(false);

$finder = $config->getFinder()
->in('src')
->in('test');

return $config;
return $config;
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ bin/build_manual phpdoc_manual ~/.psysh/php_manual.sqlite

To build the manual for another language, switch out `en` above for `de`, `es`, or any of the other languages listed in the README.

[Partial or outdated documentation is available for other languages](http://www.php.net/manual/help-translate.php) but these translations are outdated, so their content may be completely wrong or insecure!
[Partial or outdated documentation is available for other languages](http://www.php.net/manual/help-translate.php) but these translations are outdated, so their content may be completely wrong or insecure!
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"symfony/console": "~2.3.10|~2.4.2|~2.5",
"nikic/php-parser": "~1.0",
"dnoegel/php-xdg-base-dir": "0.1",
"jakub-onderka/php-console-highlighter": "dev-master"
"jakub-onderka/php-console-highlighter": "0.3.*"
},
"require-dev": {
"phpunit/phpunit": ">=3.7, <4.3",
"phpunit/phpunit": "~3.7|~4.0",
"symfony/finder": "~2.1",
"squizlabs/php_codesniffer": "~2.0",
"fabpot/php-cs-fixer": "2.0.*@dev"
"fabpot/php-cs-fixer": "~1.3"
},
"suggest": {
"ext-pcntl": "Enabling the PCNTL extension makes PsySH a lot happier :)",
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
<directory suffix=".php">./src/Psy</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
25 changes: 20 additions & 5 deletions src/Psy/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// list available commands
$commands = $this->getApplication()->all();

$table = $this->getApplication()->getHelperSet()->get('table')
->setRows(array())
->setLayout(TableHelper::LAYOUT_BORDERLESS)
->setHorizontalBorderChar('')
->setCrossingChar('');
$table = $this->getTable();

foreach ($commands as $name => $command) {
if ($name !== $command->getName()) {
Expand All @@ -95,4 +91,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
});
}
}

/**
* Get a TableHelper instance.
*
* @return TableHelper
*/
protected function getTable()
{
$old = error_reporting();
error_reporting($old & ~E_USER_DEPRECATED);
$table = $this->getApplication()->getHelperSet()->get('table');
error_reporting($old);

return $table
->setRows(array())
->setLayout(TableHelper::LAYOUT_BORDERLESS)
->setHorizontalBorderChar('')
->setCrossingChar('');
}
}
7 changes: 6 additions & 1 deletion src/Psy/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,12 @@ private function validateInput(InputInterface $input)
*/
private function getTable()
{
return $this->getApplication()->getHelperSet()->get('table')
$old = error_reporting();
error_reporting($old & ~E_USER_DEPRECATED);
$table = $this->getApplication()->getHelperSet()->get('table');
error_reporting($old);

return $table
->setLayout(TableHelper::LAYOUT_BORDERLESS)
->setHorizontalBorderChar('')
->setCrossingChar('');
Expand Down
9 changes: 6 additions & 3 deletions src/Psy/Command/ShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Psy\Command;

use Psy\Exception\RuntimeException;
use Psy\Formatter\CodeFormatter;
use Psy\Formatter\SignatureFormatter;
use Psy\Output\ShellOutput;
Expand Down Expand Up @@ -52,9 +53,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
list($value, $reflector) = $this->getTargetAndReflector($input->getArgument('value'));

$output->page(function (ShellOutput $output) use ($reflector) {
try {
$output->page(CodeFormatter::format($reflector), ShellOutput::OUTPUT_RAW);
} catch (RuntimeException $e) {
$output->writeln(SignatureFormatter::format($reflector));
$output->writeln(CodeFormatter::format($reflector), ShellOutput::OUTPUT_RAW);
});
throw $e;
}
}
}
7 changes: 5 additions & 2 deletions src/Psy/Command/WhereamiCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class WhereamiCommand extends Command
public function __construct()
{
$this->backtrace = debug_backtrace();

return parent::__construct();
}

Expand All @@ -36,7 +37,7 @@ protected function configure()
$this
->setName('whereami')
->setDefinition(array(
new InputOption('num', 'n', InputOption::VALUE_OPTIONAL, 'Number of lines before and after.', '5')
new InputOption('num', 'n', InputOption::VALUE_OPTIONAL, 'Number of lines before and after.', '5'),
))
->setDescription('Show where you are in the code.')
->setHelp(
Expand Down Expand Up @@ -69,6 +70,7 @@ protected function trace()
return $backtrace;
}
}

return $backtrace[count($backtrace) - 1];
}

Expand All @@ -88,6 +90,7 @@ protected function fileInfo()
$file = $backtrace['file'];
$line = $backtrace['line'];
}

return compact('file', 'line');
}

Expand All @@ -102,6 +105,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$colors->addTheme('line_number', array('blue'));
$highlighter = new Highlighter($colors);
$contents = file_get_contents($file);
$output->page($highlighter->getCodeSnippet($contents, $line, $num, $num));
$output->page($highlighter->getCodeSnippet($contents, $line, $num, $num), ShellOutput::OUTPUT_RAW);
}
}
13 changes: 9 additions & 4 deletions src/Psy/Formatter/CodeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Psy\Formatter;

use JakubOnderka\PhpConsoleColor\ConsoleColor;
use JakubOnderka\PhpConsoleHighlighter\Highlighter;
use Psy\Exception\RuntimeException;

/**
Expand All @@ -33,11 +35,14 @@ public static function format(\Reflector $reflector)
}

$file = file_get_contents($fileName);
$lines = preg_split('/\r?\n/', $file);

$start = $reflector->getStartLine() - 1;
$start = $reflector->getStartLine();
$end = $reflector->getEndLine() - $start;
$code = array_slice($lines, $start, $end);

$colors = new ConsoleColor();
$colors->addTheme('line_number', array('blue'));
$highlighter = new Highlighter($colors);

return $highlighter->getCodeSnippet($file, $start, 0, $end);

// no need to escape this bad boy, since (for now) it's being output raw.
// return OutputFormatter::escape(implode(PHP_EOL, $code));
Expand Down
2 changes: 1 addition & 1 deletion src/Psy/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
class Shell extends Application
{
const VERSION = 'v0.3.0';
const VERSION = 'v0.3.1';

const PROMPT = '>>> ';
const BUFF_PROMPT = '... ';
Expand Down
27 changes: 14 additions & 13 deletions test/Psy/Test/Formatter/CodeFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,25 @@

class CodeFormatterTest extends \PHPUnit_Framework_TestCase
{
public function testFormat()
{
$expected = <<<EOS
private function ignoreThisMethod(\$arg)
private function ignoreThisMethod($arg)
{
echo "whot!";
}

public function testFormat()
{
$expected = <<<EOS
> 18| private function ignoreThisMethod(\$arg)
19| {
20| echo "whot!";
21| }
EOS;

$this->assertEquals(
str_replace("\n", PHP_EOL, $expected),
CodeFormatter::format(new \ReflectionMethod($this, 'ignoreThisMethod'))
);
$formatted = CodeFormatter::format(new \ReflectionMethod($this, 'ignoreThisMethod'));
$formattedWithoutColors = preg_replace('#' . chr(27) . '\[\d\d?m#', '', $formatted);

$this->assertEquals($expected, rtrim($formattedWithoutColors));
$this->assertNotEquals($expected, rtrim($formatted));
}

/**
Expand All @@ -52,9 +58,4 @@ public function filenames()
{
return array(array(null), array('not a file'));
}

private function ignoreThisMethod($arg)
{
echo "whot!";
}
}
1 change: 0 additions & 1 deletion test/Psy/Test/Presenter/ArrayPresenterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Psy\Presenter\ObjectPresenter;
use Psy\Presenter\PresenterManager;
use Psy\Presenter\ScalarPresenter;
use Psy\Test\Presenter\FakeArrayObject;

class ArrayPresenterTest extends \PHPUnit_Framework_TestCase
{
Expand Down

0 comments on commit b2c76a6

Please sign in to comment.