Skip to content

Commit

Permalink
Merge branch 'release/0.9.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed Jun 2, 2018
2 parents 4d969a0 + 2a6a616 commit 0951e91
Show file tree
Hide file tree
Showing 28 changed files with 813 additions and 215 deletions.
11 changes: 0 additions & 11 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,3 @@ PsySH follows [PSR-1](http://php-fig.org/psr/psr-1/) and [PSR-2](http://php-fig.
## Branching model

Please branch off and send pull requests to the `develop` branch.

## Building the manual

```sh
svn co https://svn.php.net/repository/phpdoc/en/trunk/reference/ php_manual
bin/build_manual phpdoc_manual ~/.local/share/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 docs.

[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!
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ install: travis_retry composer update --no-interaction $COMPOSER_FLAGS

script:
- vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
- '[[ $TRAVIS_PHP_VERSION = 7.2* ]] && make build || true'
- '[[ $TRAVIS_PHP_VERSION = 7.2* ]] && make build -j 4 || true'

after_success:
- bash <(curl -s https://codecov.io/bash)

before_deploy: make dist
before_deploy: make dist -j 4

deploy:
provider: releases
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ build/%/psysh: vendor/bin/box build/%
# Dist packages

dist/psysh-$(VERSION).tar.gz: build/psysh/psysh
tar -czf $@ $<
@mkdir -p $(@D)
tar -C $(dir $<) -czf $@ $(notdir $<)

dist/psysh-$(VERSION)-%.tar.gz: build/psysh-%/psysh
tar -czf $@ $<
@mkdir -p $(@D)
tar -C $(dir $<) -czf $@ $(notdir $<)
2 changes: 1 addition & 1 deletion src/CodeCleaner/CallTimePassByReferencePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CallTimePassByReferencePass extends CodeCleanerPass
/**
* Validate of use call-time pass-by-reference.
*
* @throws RuntimeException if the user used call-time pass-by-reference in PHP >= 5.4.0
* @throws RuntimeException if the user used call-time pass-by-reference
*
* @param Node $node
*/
Expand Down
4 changes: 1 addition & 3 deletions src/CodeCleaner/ValidClassNamePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ class ValidClassNamePass extends NamespaceAwarePass
const INTERFACE_TYPE = 'interface';
const TRAIT_TYPE = 'trait';

protected $checkTraits;
private $conditionalScopes = 0;
private $atLeastPhp55;

public function __construct()
{
$this->checkTraits = function_exists('trait_exists');
$this->atLeastPhp55 = version_compare(PHP_VERSION, '5.5', '>=');
}

Expand Down Expand Up @@ -365,7 +363,7 @@ protected function interfaceExists($name)
*/
protected function traitExists($name)
{
return $this->checkTraits && (trait_exists($name) || $this->findInScope($name) === self::TRAIT_TYPE);
return trait_exists($name) || $this->findInScope($name) === self::TRAIT_TYPE;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/Command/DocCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Psy\Formatter\DocblockFormatter;
use Psy\Formatter\SignatureFormatter;
use Psy\Input\CodeArgument;
use Psy\Reflection\ReflectionClassConstant;
use Psy\Reflection\ReflectionLanguageConstruct;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -101,6 +102,18 @@ private function getManualDoc($reflector)
$id = $reflector->class . '::$' . $reflector->name;
break;

case 'ReflectionClassConstant':
case 'Psy\Reflection\ReflectionClassConstant':
// @todo this is going to collide with ReflectionMethod ids
// someday... start running the query by id + type if the DB
// supports it.
$id = $reflector->class . '::' . $reflector->name;
break;

case 'Psy\Reflection\ReflectionConstant_':
$id = $reflector->name;
break;

default:
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ListCommand/ClassConstantEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Psy\Command\ListCommand;

use Psy\Reflection\ReflectionConstant;
use Psy\Reflection\ReflectionClassConstant;
use Symfony\Component\Console\Input\InputInterface;

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ protected function getConstants(\Reflector $reflector, $noInherit = false)

$constants = [];
foreach ($reflector->getConstants() as $name => $constant) {
$constReflector = new ReflectionConstant($reflector, $name);
$constReflector = ReflectionClassConstant::create($reflector, $name);

if ($noInherit && $constReflector->getDeclaringClass()->getName() !== $className) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ListCommand/ClassEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function listItems(InputInterface $input, \Reflector $reflector = null
$ret = array_merge($ret, $this->filterClasses('Interfaces', get_declared_interfaces(), $internal, $user));
}

if (function_exists('get_declared_traits') && $input->getOption('traits')) {
if ($input->getOption('traits')) {
$ret = array_merge($ret, $this->filterClasses('Traits', get_declared_traits(), $internal, $user));
}

Expand Down
5 changes: 0 additions & 5 deletions src/Command/ListCommand/TraitEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ public function __construct(Presenter $presenter)
*/
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null)
{
// bail early if current PHP doesn't know about traits.
if (!function_exists('trait_exists')) {
return;
}

// only list traits when no Reflector is present.
//
// @todo make a NamespaceReflector and pass that in for commands like:
Expand Down
9 changes: 8 additions & 1 deletion src/Command/ReflectingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ protected function setCommandScopeVariables(\Reflector $reflector)
break;

case 'ReflectionProperty':
case 'Psy\Reflection\ReflectionConstant':
case 'ReflectionClassConstant':
case 'Psy\Reflection\ReflectionClassConstant':
$classReflector = $reflector->getDeclaringClass();
$vars['__class'] = $classReflector->name;
if ($classReflector->inNamespace()) {
Expand All @@ -281,6 +282,12 @@ protected function setCommandScopeVariables(\Reflector $reflector)
$vars['__dir'] = dirname($fileName);
}
break;

case 'Psy\Reflection\ReflectionConstant_':
if ($reflector->inNamespace()) {
$vars['__namespace'] = $reflector->getNamespaceName();
}
break;
}

if ($reflector instanceof \ReflectionClass || $reflector instanceof \ReflectionFunctionAbstract) {
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ public function getPager()
{
if (!isset($this->pager) && $this->usePcntl()) {
if ($pager = ini_get('cli.pager')) {
// use the default pager (5.4+)
// use the default pager
$this->pager = $pager;
} elseif ($less = exec('which less 2>/dev/null')) {
// check for the presence of less...
Expand Down
21 changes: 18 additions & 3 deletions src/ExecutionLoop/ProcessForker.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,24 @@ public function beforeRun(Shell $shell)
$read = [$down];
$write = null;
$except = null;
if (stream_select($read, $write, $except, null) === false) {
throw new \RuntimeException('Error waiting for execution loop');
}

do {
$n = @stream_select($read, $write, $except, null);

if ($n === 0) {
throw new \RuntimeException('Process timed out waiting for execution loop');
}

if ($n === false) {
$err = error_get_last();
if (!isset($err['message']) || stripos($err['message'], 'interrupted system call') === false) {
$msg = $err['message'] ?
sprintf('Error waiting for execution loop: %s', $err['message']) :
'Error waiting for execution loop';
throw new \RuntimeException($msg);
}
}
} while ($n < 1);

$content = stream_get_contents($down);
fclose($down);
Expand Down
38 changes: 31 additions & 7 deletions src/Formatter/SignatureFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace Psy\Formatter;

use Psy\Reflection\ReflectionConstant;
use Psy\Reflection\ReflectionClassConstant;
use Psy\Reflection\ReflectionConstant_;
use Psy\Reflection\ReflectionLanguageConstruct;
use Psy\Util\Json;
use Symfony\Component\Console\Formatter\OutputFormatter;
Expand Down Expand Up @@ -41,15 +42,19 @@ public static function format(\Reflector $reflector)
case $reflector instanceof \ReflectionClass:
return self::formatClass($reflector);

case $reflector instanceof ReflectionConstant:
return self::formatConstant($reflector);
case $reflector instanceof ReflectionClassConstant:
case $reflector instanceof \ReflectionClassConstant:
return self::formatClassConstant($reflector);

case $reflector instanceof \ReflectionMethod:
return self::formatMethod($reflector);

case $reflector instanceof \ReflectionProperty:
return self::formatProperty($reflector);

case $reflector instanceof ReflectionConstant_:
return self::formatConstant($reflector);

default:
throw new \InvalidArgumentException('Unexpected Reflector class: ' . get_class($reflector));
}
Expand All @@ -70,8 +75,6 @@ public static function formatName(\Reflector $reflector)
/**
* Print the method, property or class modifiers.
*
* Technically this should be a trait. Can't wait for 5.4 :)
*
* @param \Reflector $reflector
*
* @return string Formatted modifiers
Expand Down Expand Up @@ -135,11 +138,11 @@ private static function formatClass(\ReflectionClass $reflector)
/**
* Format a constant signature.
*
* @param ReflectionConstant $reflector
* @param ReflectionClassConstant|\ReflectionClassConstant $reflector
*
* @return string Formatted signature
*/
private static function formatConstant(ReflectionConstant $reflector)
private static function formatClassConstant($reflector)
{
$value = $reflector->getValue();
$style = self::getTypeStyle($value);
Expand All @@ -153,6 +156,27 @@ private static function formatConstant(ReflectionConstant $reflector)
);
}

/**
* Format a constant signature.
*
* @param ReflectionConstant_ $reflector
*
* @return string Formatted signature
*/
private static function formatConstant($reflector)
{
$value = $reflector->getValue();
$style = self::getTypeStyle($value);

return sprintf(
'<keyword>define</keyword>(<string>%s</string>, <%s>%s</%s>)',
OutputFormatter::escape(Json::encode($reflector->getName())),
$style,
OutputFormatter::escape(Json::encode($value)),
$style
);
}

/**
* Helper for getting output style for a given value's type.
*
Expand Down
1 change: 1 addition & 0 deletions src/Input/FilterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ private function validateRegex($pattern)
try {
preg_match($pattern, '');
} catch (ErrorException $e) {
restore_error_handler();
throw new RuntimeException(str_replace('preg_match(): ', 'Invalid regular expression: ', $e->getRawMessage()));
}
restore_error_handler();
Expand Down
Loading

0 comments on commit 0951e91

Please sign in to comment.