Skip to content

Commit

Permalink
Merge branch '2.15' into 2.16
Browse files Browse the repository at this point in the history
* 2.15:
  Increase PHPStan level to 5
  CombineNestedDirnameFixer - Add space after comma
  • Loading branch information
SpacePossum committed Apr 5, 2020
2 parents 9cf1d2e + 0cb0ed7 commit b476ebb
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
| grep -v tests/TestCase.php \
&& (echo "UNKNOWN FILES DETECTED" && travis_terminate 1) || echo "NO UNKNOWN FILES"
- ./check_trailing_spaces.sh || travis_terminate 1
- php -d auto_prepend_file=dev-tools/vendor/autoload.php ./dev-tools/tools/phpstan analyse
- dev-tools/vendor/bin/phpstan analyse
- if [ -n "$CHANGED_PHP_FILES" ]; then ./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | xargs | sed 's/ /,/g'` text phpmd.xml || travis_terminate 1; fi
- ./dev-tools/tools/composer-require-checker check composer.json --config-file $(realpath .composer-require-checker.json) || travis_terminate 1
- ./dev-tools/tools/composer-normalize composer.json --dry-run
Expand Down
1 change: 1 addition & 0 deletions dev-tools/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"jangregor/phpstan-prophecy": "^0.6",
"mi-schi/phpmd-extension": "^4.3",
"phpmd/phpmd": "^2.6",
"phpstan/phpstan": "0.12.18",
"phpstan/phpstan-phpunit": "^0.12"
},
"conflict": {
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fi
bin/phive --version

echo λλλ phive packages
./bin/phive install --trust-gpg-keys D2CCAC42F6295E7D,8E730BA25823D8B5,C00543248C87FB13,CF1A108D0E7AE720
./bin/phive install --trust-gpg-keys D2CCAC42F6295E7D,8E730BA25823D8B5,C00543248C87FB13

echo λλλ checkbashisms
if [ ! -x bin/checkbashisms ]; then
Expand Down
1 change: 0 additions & 1 deletion dev-tools/phive.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
<phive xmlns="https://phar.io/phive">
<phar name="composer-normalize" version="^2.1.2" installed="2.1.2" location="./tools/composer-normalize" copy="false"/>
<phar name="composer-require-checker" version="^2.0" installed="2.0.0" location="./tools/composer-require-checker" copy="false"/>
<phar name="phpstan" version="^0.12" installed="0.12.9" location="./tools/phpstan" copy="true"/>
</phive>
33 changes: 32 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
includes:
- dev-tools/vendor/jangregor/phpstan-prophecy/src/extension.neon
- dev-tools/vendor/phpstan/phpstan/conf/bleedingEdge.neon
- dev-tools/vendor/phpstan/phpstan-phpunit/extension.neon

parameters:
level: 3
level: 5
paths:
- src
- tests
Expand All @@ -16,3 +17,33 @@ parameters:
-
message: '/^Unsafe usage of new static\(\)\.$/'
path: src/Config.php
-
message: '/^Else branch is unreachable because previous condition is always true\.$/'
path: src/Event/Event.php
-
message: '/^Strict comparison using !== between ''@git-commit@'' and ''@git-commit@'' will always evaluate to false\.$/'
path: src/Console/Application.php
-
message: '/^Result of && is always false\.$/'
path: src/Config.php
-
message: '/^Strict comparison using === between false and true will always evaluate to false\.$/'
path: src/Config.php
-
message: '/^Else branch is unreachable because ternary operator condition is always true\.$/'
paths:
- src/Config.php
- src/Tokenizer/Token.php
-
message: '/^Parameter #1 \$fixers of method PhpCsFixer\\Config::registerCustomFixers\(\) expects iterable<PhpCsFixer\\Fixer\\FixerInterface>, string given\.$/'
path: tests/ConfigTest.php
-
message: '/^Parameter #1 \$options of method PhpCsFixer\\FixerConfiguration\\FixerConfigurationResolverRootless::resolve\(\) expects array<string, mixed>, array<int, string> given\.$/'
path: tests/FixerConfiguration/FixerConfigurationResolverRootlessTest.php
-
message: '/^Parameter #1 \$function of function register_shutdown_function expects callable\(\): void, array\(\$this\(PhpCsFixer\\FileRemoval\), ''clean''\) given\.$/'
path: src/FileRemoval.php
-
message: '/^Parameter #1 \$finder of method PhpCsFixer\\Config::setFinder\(\) expects iterable<string>, int given\.$/'
path: tests/ConfigTest.php
tipsOfTheDay: false
2 changes: 1 addition & 1 deletion src/AbstractNoUselessElseFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private function isInConditionWithoutBraces(Tokens $tokens, $index, $lowerLimitI
return true;
}

if ($token->equals(';', '}')) {
if ($token->equals(';')) {
return false;
}
if ($token->equals('{')) {
Expand Down
9 changes: 1 addition & 8 deletions src/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ public function get($file)

public function set($file, $hash)
{
if (!\is_int($hash)) {
throw new \InvalidArgumentException(sprintf(
'Value needs to be an integer, got "%s".',
\is_object($hash) ? \get_class($hash) : \gettype($hash)
));
}

$this->hashes[$file] = $hash;
}

Expand Down Expand Up @@ -105,7 +98,7 @@ public static function fromJson($json)
if (null === $data && JSON_ERROR_NONE !== json_last_error()) {
throw new \InvalidArgumentException(sprintf(
'Value needs to be a valid JSON string, got "%s", error: "%s".',
\is_object($json) ? \get_class($json) : \gettype($json),
$json,
json_last_error_msg()
));
}
Expand Down
7 changes: 4 additions & 3 deletions src/ConfigurationException/InvalidConfigurationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
class InvalidConfigurationException extends \InvalidArgumentException
{
/**
* @param string $message
* @param null|int $code
* @param string $message
* @param null|int $code
* @param null|\Throwable $previous
*/
public function __construct($message, $code = null, \Exception $previous = null)
public function __construct($message, $code = null, $previous = null)
{
parent::__construct(
$message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ class InvalidFixerConfigurationException extends InvalidConfigurationException
private $fixerName;

/**
* @param string $fixerName
* @param string $message
* @param string $fixerName
* @param string $message
* @param null|\Throwable $previous
*/
public function __construct($fixerName, $message, \Exception $previous = null)
public function __construct($fixerName, $message, $previous = null)
{
parent::__construct(
sprintf('[%s] %s', $fixerName, $message),
Expand Down
10 changes: 5 additions & 5 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ public function doRun(InputInterface $input, OutputInterface $output)
*/
public function getLongVersion()
{
$version = parent::getLongVersion();
if (self::VERSION_CODENAME) {
$version .= ' <info>'.self::VERSION_CODENAME.'</info>';
}
$version .= ' by <comment>Fabien Potencier</comment> and <comment>Dariusz Ruminski</comment>';
$version = sprintf(
'%s <info>%s</info> by <comment>Fabien Potencier</comment> and <comment>Dariusz Ruminski</comment>',
parent::getLongVersion(),
self::VERSION_CODENAME
);

$commit = '@git-commit@';

Expand Down
2 changes: 1 addition & 1 deletion src/Console/ConfigurationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ static function ($path) {
}

return new \CallbackFilterIterator(
$nestedFinder,
new \IteratorIterator($nestedFinder),
static function (\SplFileInfo $current) use ($pathsByType) {
$currentRealPath = $current->getRealPath();

Expand Down
7 changes: 4 additions & 3 deletions src/Fixer/Basic/BracesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,15 @@ private function fixCommentBeforeBrace(Tokens $tokens)
continue;
}

/** @var Token $tokenTmp */
$tokenTmp = $tokens[$braceIndex];

$newBraceIndex = $prevIndex + 1;
for ($i = $braceIndex; $i > $newBraceIndex; --$i) {
// we might be moving one white space next to another, these have to be merged
$tokens[$i] = $tokens[$i - 1];
/** @var Token $previousToken */
$previousToken = $tokens[$i - 1];
$tokens[$i] = $previousToken;
if ($tokens[$i]->isWhitespace() && $tokens[$i + 1]->isWhitespace()) {
$tokens[$i] = new Token([T_WHITESPACE, $tokens[$i]->getContent().$tokens[$i + 1]->getContent()]);
$tokens->clearAt($i + 1);
Expand Down Expand Up @@ -809,8 +812,6 @@ private function findStatementEnd(Tokens $tokens, $parenthesisEndIndex)
return $tokens->getPrevNonWhitespace($index);
}
}

throw new \RuntimeException('Statement end not found.');
}

private function getControlTokens()
Expand Down
1 change: 1 addition & 0 deletions src/Fixer/Basic/EncodingFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$content = $tokens[0]->getContent();

if (0 === strncmp($content, $this->BOM, 3)) {
/** @var false|string $newContent until support for PHP 5.6 is dropped */
$newContent = substr($content, 3);

if (false === $newContent) {
Expand Down
2 changes: 2 additions & 0 deletions src/Fixer/Basic/Psr0Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$dir = \dirname($path);

if ('' !== $this->configuration['dir']) {
/** @var false|string $dir until support for PHP 5.6 is dropped */
$dir = substr($dir, \strlen(realpath($this->configuration['dir'])) + 1);

if (false === $dir) {
Expand All @@ -120,6 +121,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
}
}

/** @var false|string $dir until support for PHP 5.6 is dropped */
$dir = substr($dir, -\strlen($normNamespace));
if (false === $dir) {
$dir = '';
Expand Down
2 changes: 0 additions & 2 deletions src/Fixer/ClassNotation/OrderedClassElementsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ private function getElements(Tokens $tokens, $startIndex)
$elements[] = $element;
$startIndex = $element['end'] + 1;
}

return [];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private function combineDirnames(Tokens $tokens, array $dirnameInfoArray)
$prev = $tokens->getPrevMeaningfulToken($outerDirnameInfo['end']);
$items = [];
if (!$tokens[$prev]->equals(',')) {
$items[] = new Token(',');
$items = [new Token(','), new Token([T_WHITESPACE, ' '])];
}
$items[] = $levelsToken;
$tokens->insertAt($outerDirnameInfo['end'], $items);
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocAlignFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private function fixDocBlock(DocBlock $docBlock)
* @param string $line
* @param bool $matchCommentOnly
*
* @return null|string[]
* @return null|array<string, null|string>
*/
private function getMatches($line, $matchCommentOnly = false)
{
Expand Down
6 changes: 5 additions & 1 deletion src/Runner/FileFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ final class FileFilterIterator extends \FilterIterator
private $visitedElements = [];

public function __construct(
\Iterator $iterator,
\Traversable $iterator,
EventDispatcherInterface $eventDispatcher = null,
CacheManagerInterface $cacheManager
) {
if (!$iterator instanceof \Iterator) {
$iterator = new \IteratorIterator($iterator);
}

parent::__construct($iterator);

$this->eventDispatcher = $eventDispatcher;
Expand Down
19 changes: 9 additions & 10 deletions src/Tokenizer/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* @extends \SplFixedArray<Token>
*
* @method Token current()
* @method Token offsetGet($index)
*/
class Tokens extends \SplFixedArray
{
Expand Down Expand Up @@ -315,7 +312,7 @@ public function offsetSet($index, $newval)
{
$this->blockEndCache = [];

if (!$this[$index] || !$this[$index]->equals($newval)) {
if (!isset($this[$index]) || !$this[$index]->equals($newval)) {
$this->changed = true;

if (isset($this[$index])) {
Expand Down Expand Up @@ -365,7 +362,9 @@ public function clearEmptyTokens()

for ($count = $index; $index < $limit; ++$index) {
if (!$this->isEmptyAt($index)) {
$this[$count++] = $this[$index];
/** @var Token $token */
$token = $this[$index];
$this[$count++] = $token;
}
}

Expand Down Expand Up @@ -870,8 +869,8 @@ public function findSequence(array $sequence, $start = 0, $end = null, $caseSens
/**
* Insert instances of Token inside collection.
*
* @param int $index start inserting index
* @param Token|Token[]|Tokens $items instances of Token to insert
* @param int $index start inserting index
* @param array<Token>|Token|Tokens $items instances of Token to insert
*/
public function insertAt($index, $items)
{
Expand Down Expand Up @@ -963,9 +962,9 @@ public function overrideAt($index, $token)
/**
* Override tokens at given range.
*
* @param int $indexStart start overriding index
* @param int $indexEnd end overriding index
* @param Token[]|Tokens $items tokens to insert
* @param int $indexStart start overriding index
* @param int $indexEnd end overriding index
* @param array<Token>|Tokens $items tokens to insert
*/
public function overrideRange($indexStart, $indexEnd, $items)
{
Expand Down
13 changes: 0 additions & 13 deletions tests/Cache/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,6 @@ public function testDefaults()
static::assertNull($cache->get($file));
}

public function testSetThrowsInvalidArgumentExceptionIfValueIsNotAnInteger()
{
$this->expectException(\InvalidArgumentException::class);

$signature = $this->getSignatureDouble();

$cache = new Cache($signature);

$file = 'test.php';

$cache->set($file, null);
}

public function testCanSetAndGetValue()
{
$signature = $this->getSignatureDouble();
Expand Down
16 changes: 8 additions & 8 deletions tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ public function provideFixCases()
'<?php dirname($path, 3);',
],
[
'<?php dirname($path,2);',
'<?php dirname($path, 2);',
'<?php dirname(dirname($path));',
],
[
'<?php dirname /* a */ ( /* b */ /* c */ $path /* d */,2);',
'<?php dirname /* a */ ( /* b */ /* c */ $path /* d */, 2);',
'<?php dirname /* a */ ( /* b */ dirname( /* c */ $path) /* d */);',
],
[
'<?php dirname($path,3);',
'<?php dirname($path, 3);',
'<?php dirname(\dirname(dirname($path)));',
],
[
'<?php dirname($path,4);',
'<?php dirname($path, 4);',
'<?php dirname(dirname($path, 3));',
],
[
Expand All @@ -72,7 +72,7 @@ public function provideFixCases()
'<?php dirname(dirname($path, 2), 3);',
],
[
'<?php dirname($path,5);',
'<?php dirname($path, 5);',
'<?php dirname(dirname(dirname($path), 3));',
],
[
Expand All @@ -88,11 +88,11 @@ public function provideFixCases()
'<?php foo\dirname(dirname($path));',
],
[
'<?php dirname(foo(dirname($path,2)),2);',
'<?php dirname(foo(dirname($path, 2)), 2);',
'<?php dirname(dirname(foo(dirname(dirname($path)))));',
],
[
'<?php new dirname(dirname($path,2));',
'<?php new dirname(dirname($path, 2));',
'<?php new dirname(dirname(dirname($path)));',
],
];
Expand Down Expand Up @@ -122,7 +122,7 @@ public function provideFix73Cases()
{
return [
[
'<?php dirname($path,3);',
'<?php dirname($path, 3);',
'<?php dirname(dirname(dirname($path, ), ));',
],
[
Expand Down
2 changes: 0 additions & 2 deletions tests/Fixer/PhpTag/NoClosingTagFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public function testWithShortOpenTag($expected, $input = null)
{
if (!ini_get('short_open_tag')) {
static::markTestSkipped('The short_open_tag option is required to be enabled.');

return;
}

$this->doTest($expected, $input);
Expand Down

0 comments on commit b476ebb

Please sign in to comment.