Skip to content

Commit

Permalink
Merge branch 'release/0.9.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed Aug 11, 2018
2 parents 4a2ce86 + cbad8ce commit 4f5b6c0
Show file tree
Hide file tree
Showing 142 changed files with 1,011 additions and 983 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
],
"require": {
"php": ">=5.4.0",
"ext-json": "*",
"ext-tokenizer": "*",
"symfony/console": "~2.3.10|^2.4.2|~3.0|~4.0",
"symfony/var-dumper": "~2.7|~3.0|~4.0",
"nikic/php-parser": "~1.3|~2.0|~3.0|~4.0",
Expand Down
22 changes: 11 additions & 11 deletions src/CodeCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private function addImplicitDebugContext(array $passes)
}

try {
$code = @file_get_contents($file);
$code = @\file_get_contents($file);
if (!$code) {
return;
}
Expand Down Expand Up @@ -169,15 +169,15 @@ private function addImplicitDebugContext(array $passes)
*/
private static function getDebugFile()
{
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$trace = \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);

foreach (array_reverse($trace) as $stackFrame) {
foreach (\array_reverse($trace) as $stackFrame) {
if (!self::isDebugCall($stackFrame)) {
continue;
}

if (preg_match('/eval\(/', $stackFrame['file'])) {
preg_match_all('/([^\(]+)\((\d+)/', $stackFrame['file'], $matches);
if (\preg_match('/eval\(/', $stackFrame['file'])) {
\preg_match_all('/([^\(]+)\((\d+)/', $stackFrame['file'], $matches);

return $matches[1][0];
}
Expand Down Expand Up @@ -214,7 +214,7 @@ private static function isDebugCall(array $stackFrame)
*/
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;
}
Expand All @@ -223,13 +223,13 @@ public function clean(array $codeLines, $requireSemicolons = false)
$stmts = $this->traverser->traverse($stmts);

// Work around https://github.com/nikic/PHP-Parser/issues/399
$oldLocale = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, 'C');
$oldLocale = \setlocale(LC_NUMERIC, 0);
\setlocale(LC_NUMERIC, 'C');

$code = $this->printer->prettyPrint($stmts);

// Now put the locale back
setlocale(LC_NUMERIC, $oldLocale);
\setlocale(LC_NUMERIC, $oldLocale);

return $code;
}
Expand Down Expand Up @@ -307,7 +307,7 @@ private function parseErrorIsEOF(\PhpParser\Error $e)
{
$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);
}

/**
Expand Down Expand Up @@ -344,6 +344,6 @@ private function parseErrorIsUnterminatedComment(\PhpParser\Error $e, $code)

private function parseErrorIsTrailingComma(\PhpParser\Error $e, $code)
{
return ($e->getRawMessage() === 'A trailing comma is not allowed here') && (substr(rtrim($code), -1) === ',');
return ($e->getRawMessage() === 'A trailing comma is not allowed here') && (\substr(\rtrim($code), -1) === ',');
}
}
10 changes: 5 additions & 5 deletions src/CodeCleaner/AbstractClassPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function enterNode(Node $node)
$this->abstractMethods = [];
} elseif ($node instanceof ClassMethod) {
if ($node->isAbstract()) {
$name = sprintf('%s::%s', $this->class->name, $node->name);
$name = \sprintf('%s::%s', $this->class->name, $node->name);
$this->abstractMethods[] = $name;

if ($node->stmts !== null) {
$msg = sprintf('Abstract function %s cannot contain body', $name);
$msg = \sprintf('Abstract function %s cannot contain body', $name);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
}
Expand All @@ -55,14 +55,14 @@ public function enterNode(Node $node)
public function leaveNode(Node $node)
{
if ($node instanceof Class_) {
$count = count($this->abstractMethods);
$count = \count($this->abstractMethods);
if ($count > 0 && !$node->isAbstract()) {
$msg = sprintf(
$msg = \sprintf(
'Class %s contains %d abstract method%s must therefore be declared abstract or implement the remaining methods (%s)',
$node->name,
$count,
($count === 1) ? '' : 's',
implode(', ', $this->abstractMethods)
\implode(', ', $this->abstractMethods)
);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
Expand Down
8 changes: 4 additions & 4 deletions src/CodeCleaner/CalledClassPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public function enterNode(Node $node)
return;
}

$name = strtolower($node->name);
if (in_array($name, ['get_class', 'get_called_class'])) {
$msg = sprintf('%s() called without object from outside a class', $name);
$name = \strtolower($node->name);
if (\in_array($name, ['get_class', 'get_called_class'])) {
$msg = \sprintf('%s() called without object from outside a class', $name);
throw new ErrorException($msg, 0, E_USER_WARNING, null, $node->getLine());
}
}
Expand All @@ -78,6 +78,6 @@ public function leaveNode(Node $node)

private function isNull(Node $node)
{
return $node->value instanceof ConstFetch && strtolower($node->value->name) === 'null';
return $node->value instanceof ConstFetch && \strtolower($node->value->name) === 'null';
}
}
8 changes: 4 additions & 4 deletions src/CodeCleaner/FinalClassPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public function enterNode(Node $node)
if ($node->extends) {
$extends = (string) $node->extends;
if ($this->isFinalClass($extends)) {
$msg = sprintf('Class %s may not inherit from final class (%s)', $node->name, $extends);
$msg = \sprintf('Class %s may not inherit from final class (%s)', $node->name, $extends);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
}

if ($node->isFinal()) {
$this->finalClasses[strtolower($node->name)] = true;
$this->finalClasses[\strtolower($node->name)] = true;
}
}
}
Expand All @@ -59,8 +59,8 @@ public function enterNode(Node $node)
*/
private function isFinalClass($name)
{
if (!class_exists($name)) {
return isset($this->finalClasses[strtolower($name)]);
if (!\class_exists($name)) {
return isset($this->finalClasses[\strtolower($name)]);
}

$refl = new \ReflectionClass($name);
Expand Down
2 changes: 1 addition & 1 deletion src/CodeCleaner/FunctionReturnInWriteContextPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FunctionReturnInWriteContextPass extends CodeCleanerPass

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

/**
Expand Down
10 changes: 5 additions & 5 deletions src/CodeCleaner/ImplicitReturnPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private function addImplicitReturn(array $nodes)
return [new Return_(NoReturnValue::create())];
}

$last = end($nodes);
$last = \end($nodes);

// Special case a few types of statements to add an implicit return
// value (even though they technically don't have any return value)
Expand All @@ -68,22 +68,22 @@ private function addImplicitReturn(array $nodes)
} elseif ($last instanceof Switch_) {
foreach ($last->cases as $case) {
// only add an implicit return to cases which end in break
$caseLast = end($case->stmts);
$caseLast = \end($case->stmts);
if ($caseLast instanceof Break_) {
$case->stmts = $this->addImplicitReturn(array_slice($case->stmts, 0, -1));
$case->stmts = $this->addImplicitReturn(\array_slice($case->stmts, 0, -1));
$case->stmts[] = $caseLast;
}
}
} elseif ($last instanceof Expr && !($last instanceof Exit_)) {
// @codeCoverageIgnoreStart
$nodes[count($nodes) - 1] = new Return_($last, [
$nodes[\count($nodes) - 1] = new Return_($last, [
'startLine' => $last->getLine(),
'endLine' => $last->getLine(),
]);
// @codeCoverageIgnoreEnd
} elseif ($last instanceof Expression && !($last->expr instanceof Exit_)) {
// For PHP Parser 4.x
$nodes[count($nodes) - 1] = new Return_($last->expr, [
$nodes[\count($nodes) - 1] = new Return_($last->expr, [
'startLine' => $last->getLine(),
'endLine' => $last->getLine(),
]);
Expand Down
6 changes: 3 additions & 3 deletions src/CodeCleaner/LegacyEmptyPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LegacyEmptyPass extends CodeCleanerPass

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

/**
Expand All @@ -49,7 +49,7 @@ public function enterNode(Node $node)
}

if (!$node->expr instanceof Variable) {
$msg = sprintf('syntax error, unexpected %s', $this->getUnexpectedThing($node->expr));
$msg = \sprintf('syntax error, unexpected %s', $this->getUnexpectedThing($node->expr));

throw new ParseErrorException($msg, $node->expr->getLine());
}
Expand All @@ -61,7 +61,7 @@ private function getUnexpectedThing(Node $node)
case 'Scalar_String':
case 'Scalar_LNumber':
case 'Scalar_DNumber':
return json_encode($node->value);
return \json_encode($node->value);

case 'Expr_ConstFetch':
return (string) $node->name;
Expand Down
2 changes: 1 addition & 1 deletion src/CodeCleaner/ListPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ListPass extends CodeCleanerPass

public function __construct()
{
$this->atLeastPhp71 = version_compare(PHP_VERSION, '7.1', '>=');
$this->atLeastPhp71 = \version_compare(PHP_VERSION, '7.1', '>=');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/CodeCleaner/LoopContextPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ public function enterNode(Node $node)
$operator = $node instanceof Break_ ? 'break' : 'continue';

if ($this->loopDepth === 0) {
$msg = sprintf("'%s' not in the 'loop' or 'switch' context", $operator);
$msg = \sprintf("'%s' not in the 'loop' or 'switch' context", $operator);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}

if ($node->num instanceof LNumber || $node->num instanceof DNumber) {
$num = $node->num->value;
if ($node->num instanceof DNumber || $num < 1) {
$msg = sprintf("'%s' operator accepts only positive numbers", $operator);
$msg = \sprintf("'%s' operator accepts only positive numbers", $operator);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}

if ($num > $this->loopDepth) {
$msg = sprintf("Cannot '%s' %d levels", $operator, $num);
$msg = \sprintf("Cannot '%s' %d levels", $operator, $num);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
} elseif ($node->num) {
$msg = sprintf("'%s' operator with non-constant operand is no longer supported", $operator);
$msg = \sprintf("'%s' operator with non-constant operand is no longer supported", $operator);
throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
}
break;
Expand Down
6 changes: 3 additions & 3 deletions src/CodeCleaner/NamespaceAwarePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public function enterNode(Node $node)
protected function getFullyQualifiedName($name)
{
if ($name instanceof FullyQualifiedName) {
return implode('\\', $name->parts);
return \implode('\\', $name->parts);
} elseif ($name instanceof Name) {
$name = $name->parts;
} elseif (!is_array($name)) {
} elseif (!\is_array($name)) {
$name = [$name];
}

return implode('\\', array_merge($this->namespace, $name));
return \implode('\\', \array_merge($this->namespace, $name));
}
}
2 changes: 1 addition & 1 deletion src/CodeCleaner/NamespacePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function beforeTraverse(array $nodes)
return $nodes;
}

$last = end($nodes);
$last = \end($nodes);

if ($last instanceof Namespace_) {
$kind = $last->getAttribute('kind');
Expand Down
2 changes: 1 addition & 1 deletion src/CodeCleaner/PassableByReferencePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function enterNode(Node $node)
}

foreach ($refl->getParameters() as $key => $param) {
if (array_key_exists($key, $node->args)) {
if (\array_key_exists($key, $node->args)) {
$arg = $node->args[$key];
if ($param->isPassedByReference() && !$this->isPassableByReference($arg)) {
throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
Expand Down
8 changes: 4 additions & 4 deletions src/CodeCleaner/RequirePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ public static function resolve($file, $lineNumber = null)
// @todo Shell::handleError would be better here, because we could
// fake the file and line number, but we can't call it statically.
// So we're duplicating some of the logics here.
if (E_WARNING & error_reporting()) {
if (E_WARNING & \error_reporting()) {
ErrorException::throwException(E_WARNING, 'Filename cannot be empty', null, $lineNumber);
} else {
// @todo trigger an error as fallback? this is pretty ugly…
// trigger_error('Filename cannot be empty', E_USER_WARNING);
}
}

if ($file === '' || !stream_resolve_include_path($file)) {
$msg = sprintf("Failed opening required '%s'", $file);
if ($file === '' || !\stream_resolve_include_path($file)) {
$msg = \sprintf("Failed opening required '%s'", $file);
throw new FatalErrorException($msg, 0, E_ERROR, null, $lineNumber);
}

Expand All @@ -97,6 +97,6 @@ public static function resolve($file, $lineNumber = null)

private function isRequireNode(Node $node)
{
return $node instanceof Include_ && in_array($node->type, self::$requireTypes);
return $node instanceof Include_ && \in_array($node->type, self::$requireTypes);
}
}
6 changes: 3 additions & 3 deletions src/CodeCleaner/StrictTypesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class StrictTypesPass extends CodeCleanerPass

public function __construct()
{
$this->atLeastPhp7 = version_compare(PHP_VERSION, '7.0', '>=');
$this->atLeastPhp7 = \version_compare(PHP_VERSION, '7.0', '>=');
}

/**
Expand Down Expand Up @@ -75,10 +75,10 @@ public function beforeTraverse(array $nodes)
}

if ($prependStrictTypes) {
$first = reset($nodes);
$first = \reset($nodes);
if (!$first instanceof Declare_) {
$declare = new Declare_([new DeclareDeclare('strict_types', new LNumber(1))]);
array_unshift($nodes, $declare);
\array_unshift($nodes, $declare);
}
}

Expand Down
Loading

0 comments on commit 4f5b6c0

Please sign in to comment.