Skip to content

Commit

Permalink
Merge branch '2.12' into 3869-phpdoc_no_empty_return-less-greedy
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacePossum committed Aug 15, 2018
2 parents 034e00a + 76238aa commit e04702a
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 36 deletions.
23 changes: 23 additions & 0 deletions .circleci/config.yml
@@ -0,0 +1,23 @@
version: 2

jobs:
build:
macos:
xcode: '9.0'
steps:
- checkout

- save_cache:
key: dependency-cache
paths:
- ~/.composer
- ~/Library/Caches/Homebrew

- run: brew update
- run: brew install php72
- run: echo "memory_limit = 512M" > $(brew --prefix)/etc/php/7.2/conf.d/memory.ini
- run: curl -sS https://getcomposer.org/installer | php
- run: php composer.phar global show hirak/prestissimo -q || php composer.phar global require --no-interaction --no-progress --optimize-autoloader hirak/prestissimo
- run: php composer.phar install --optimize-autoloader --no-interaction --no-progress --no-suggest
- run: vendor/bin/phpunit
- run: PHP_CS_FIXER_FUTURE_MODE=1 php php-cs-fixer --diff --dry-run -v fix
1 change: 1 addition & 0 deletions .gitattributes
Expand Up @@ -9,6 +9,7 @@ tests/Test/AbstractFixerWithAliasedOptionsTestCase.php export-ignore
tests/Test/AbstractTransformerTestCase.php export-ignore

.appveyor.yml export-ignore
.circleci/ export-ignore
.composer-require-checker.json export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
Expand Down
25 changes: 0 additions & 25 deletions circle.yml

This file was deleted.

10 changes: 10 additions & 0 deletions src/Fixer/Import/FullyQualifiedStrictTypesFixer.php
Expand Up @@ -70,6 +70,16 @@ public function doSomething(\Foo\Bar $foo): \Foo\Bar\Baz
);
}

/**
* {@inheritdoc}
*/
public function getPriority()
{
// should run after PhpdocToReturnTypeFixer
// should run before NoSuperfluousPhpdocTagsFixer
return 7;
}

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php
Expand Up @@ -139,7 +139,7 @@ private function findDocumentedFunction(Tokens $tokens, $index)
do {
$index = $tokens->getNextMeaningfulToken($index);

if ($tokens[$index]->isGivenKind(T_FUNCTION)) {
if (null === $index || $tokens[$index]->isGivenKind(T_FUNCTION)) {
return $index;
}
} while ($tokens[$index]->isGivenKind([T_ABSTRACT, T_FINAL, T_STATIC, T_PRIVATE, T_PROTECTED, T_PUBLIC]));
Expand Down
6 changes: 3 additions & 3 deletions src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php
Expand Up @@ -78,14 +78,14 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$content = $annotation->getContent();

if (
1 !== Preg::match('/[.。]$/u', $content)
|| 0 !== Preg::match('/[.。](?!$)/u', $content, $matches)
1 !== Preg::match('/[.。]\h*$/u', $content)
|| 0 !== Preg::match('/[.。](?!\h*$)/u', $content, $matches)
) {
continue;
}

$endLine = $doc->getLine($annotation->getEnd());
$endLine->setContent(Preg::replace('/(?<![.。])[.。](\s+)$/u', '\1', $endLine->getContent()));
$endLine->setContent(Preg::replace('/(?<![.。])[.。]\h*(\H+)$/u', '\1', $endLine->getContent()));

$startLine = $doc->getLine($annotation->getStart());
$optionalTypeRegEx = $annotation->supportTypes()
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Strict/StrictParamFixer.php
Expand Up @@ -77,7 +77,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)

$previousIndex = $tokens->getPrevMeaningfulToken($index);
if (null !== $previousIndex && $tokens[$previousIndex]->isGivenKind(CT::T_FUNCTION_IMPORT)) {
return;
continue;
}

$lowercaseContent = strtolower($token->getContent());
Expand Down
6 changes: 6 additions & 0 deletions src/Fixer/StringNotation/ExplicitStringVariableFixer.php
Expand Up @@ -95,6 +95,12 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
foreach ($variableTokens as $variablePartIndex => $variablePartToken) {
if ($variablePartToken->isGivenKind(T_NUM_STRING)) {
$tokens[$variablePartIndex] = new Token([T_LNUMBER, $variablePartToken->getContent()]);

continue;
}

if ($variablePartToken->isGivenKind(T_STRING) && $tokens[$variablePartIndex + 1]->equals(']')) {
$tokens[$variablePartIndex] = new Token([T_CONSTANT_ENCAPSED_STRING, "'".$variablePartToken->getContent()."'"]);
}
}

Expand Down
26 changes: 23 additions & 3 deletions src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php
Expand Up @@ -62,17 +62,37 @@ public function isCandidate(Tokens $tokens)
*/
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
{
foreach ($tokens as $index => $token) {
for ($index = count($tokens) - 1; $index >= 0; --$index) {
$token = $tokens[$index];
if (
$token->isGivenKind(T_OPEN_TAG)
&& $tokens->offsetExists($index + 1)
&& $tokens[$index + 1]->isWhitespace()
&& 1 === Preg::match('/(.*)\h$/', $token->getContent(), $openTagMatches)
&& 1 === Preg::match('/^(\R)(.*)$/s', $tokens[$index + 1]->getContent(), $whitespaceMatches)
) {
$tokens[$index] = new Token([T_OPEN_TAG, $openTagMatches[1].$whitespaceMatches[1]]);
if ('' === $whitespaceMatches[2]) {
$tokens->clearAt($index + 1);
} else {
$tokens[$index + 1] = new Token([T_WHITESPACE, $whitespaceMatches[2]]);
}

continue;
}

if (!$token->isWhitespace()) {
continue;
}

$lines = Preg::split("/([\r\n]+)/", $token->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE);
$lines = Preg::split('/(\\R+)/', $token->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE);
$linesSize = count($lines);

// fix only multiline whitespaces or singleline whitespaces at the end of file
if ($linesSize > 1 || !isset($tokens[$index + 1])) {
$lines[0] = rtrim($lines[0], " \t");
if (!$tokens[$index - 1]->isGivenKind(T_OPEN_TAG) || 1 !== Preg::match('/(.*)\R$/', $tokens[$index - 1]->getContent())) {
$lines[0] = rtrim($lines[0], " \t");
}

for ($i = 1; $i < $linesSize; ++$i) {
$trimmedLine = rtrim($lines[$i], " \t");
Expand Down
2 changes: 1 addition & 1 deletion src/Tokenizer/Analyzer/ArgumentsAnalyzer.php
Expand Up @@ -107,7 +107,7 @@ public function getArgumentInfo(Tokens $tokens, $argumentStart, $argumentEnd)
$sawName = false;
for ($index = $argumentStart; $index <= $argumentEnd; ++$index) {
$token = $tokens[$index];
if ($token->isComment() || $token->isWhitespace() || $token->isGivenKind(T_ELLIPSIS)) {
if ($token->isComment() || $token->isWhitespace() || $token->isGivenKind(T_ELLIPSIS) || $token->equals('&')) {
continue;
}
if ($token->isGivenKind(T_VARIABLE)) {
Expand Down
1 change: 1 addition & 0 deletions tests/AutoReview/FixerFactoryTest.php
Expand Up @@ -83,6 +83,7 @@ public function provideFixersPriorityCases()
[$fixers['elseif'], $fixers['braces']],
[$fixers['escape_implicit_backslashes'], $fixers['heredoc_to_nowdoc']],
[$fixers['escape_implicit_backslashes'], $fixers['single_quote']],
[$fixers['fully_qualified_strict_types'], $fixers['no_superfluous_phpdoc_tags']],
[$fixers['function_to_constant'], $fixers['native_function_casing']],
[$fixers['function_to_constant'], $fixers['no_extra_blank_lines']],
[$fixers['function_to_constant'], $fixers['no_singleline_whitespace_before_semicolons']],
Expand Down
7 changes: 7 additions & 0 deletions tests/Fixer/Import/FullyQualifiedStrictTypesFixerTest.php
Expand Up @@ -371,6 +371,13 @@ public function doSomething(
){}
}',
],
// Test reference
[
'<?php
function withReference(Exception &$e) {}',
'<?php
function withReference(\Exception &$e) {}',
],
];
}
}
6 changes: 6 additions & 0 deletions tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php
Expand Up @@ -264,6 +264,12 @@ class Foo {
public function doFoo(array $bar, callable $baz) {}
}',
],
'PHPDoc at the end of file' => [
'<?php
/**
* Foo
*/',
],
];
}

Expand Down
20 changes: 20 additions & 0 deletions tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php
Expand Up @@ -137,6 +137,26 @@ public function provideFixCases()
/**
* @return bool|null Returns `true` if the class has a single-column ID
* and Returns `false` otherwise.
*/',
],
[
'<?php
/**
* @throws \Exception having whitespaces after dot, yet I am fixed
*/',
'<?php
/**
* @throws \Exception having whitespaces after dot, yet I am fixed. '.'
*/',
],
[
'<?php
/**
* @throws \Exception having tabs after dot, yet I am fixed
*/',
'<?php
/**
* @throws \Exception having tabs after dot, yet I am fixed. '.'
*/',
],
];
Expand Down
18 changes: 18 additions & 0 deletions tests/Fixer/Strict/StrictParamFixerTest.php
Expand Up @@ -135,6 +135,24 @@ public function provideFixCases()
class Foo
{
public function __construct($foo, $bar) {}
}',
],
[
'<?php
namespace Foo {
array_keys($foo, $bar, true);
}
namespace Bar {
use function Foo\LoremIpsum;
array_keys($foo, $bar, true);
}',
'<?php
namespace Foo {
array_keys($foo, $bar);
}
namespace Bar {
use function Foo\LoremIpsum;
array_keys($foo, $bar);
}',
],
];
Expand Down
Expand Up @@ -114,8 +114,8 @@ public function provideTestFixCases()
'<?php $a = "My name is $array[1] !";',
],
[
'<?php $a = "My name is {$array[MY_CONSTANT]} !";',
'<?php $a = "My name is $array[MY_CONSTANT] !";',
'<?php $a = "My name is {$array[\'foo\']} !";',
'<?php $a = "My name is $array[foo] !";',
],
[
'<?php $a = "Closure not allowed ${closure}() text";',
Expand Down
38 changes: 38 additions & 0 deletions tests/Fixer/Whitespace/NoTrailingWhitespaceFixerTest.php
Expand Up @@ -96,6 +96,44 @@ public function provideFixCases()
[
"<?php\necho <<<'EOT'\nInline Il y eut un \r\nrire éclatant \n \n \r\nEOT;\n\n",
],
[
"<?php\necho 'Hello World';",
"<?php \necho 'Hello World';",
],
[
"<?php\n\necho 'Hello World';",
"<?php \n\necho 'Hello World';",
],
[
"<?php\r\necho 'Hello World';",
"<?php \r\necho 'Hello World';",
],
[
"<?php\necho 'Hello World';",
"<?php \necho 'Hello World';",
],
[
"<?php\necho 'Hello World';",
"<?php \necho 'Hello World';",
],
[
'<?php ',
'<?php ',
],
[
"<?php\t",
"<?php\t\t",
],
[
'<?php ', // do not trim this as "<?php" is not valid PHP
],
[
"<?php\n \n \n ",
],
[
"<?php\n \n ",
"<?php \n \n ",
],
];
}
}
@@ -0,0 +1,20 @@
--TEST--
Integration of fixers: fully_qualified_strict_types,no_superfluous_phpdoc_tags.
--RULESET--
{"fully_qualified_strict_types": true, "no_superfluous_phpdoc_tags": true}
--EXPECT--
<?php
// No namespace
/**
* @param bool $expected
*/
function testSomething(Foo $foo, $expected) {}

--INPUT--
<?php
// No namespace
/**
* @param Foo $foo
* @param bool $expected
*/
function testSomething(\Foo $foo, $expected) {}
10 changes: 10 additions & 0 deletions tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php
Expand Up @@ -116,6 +116,16 @@ public function provideArgumentsInfoCases()
3
)
)],
['<?php function(array &$a = array()){};', 3, 12, new ArgumentAnalysis(
'$a',
6,
'array()',
new TypeAnalysis(
'array',
3,
3
)
)],
['<?php function(array ... $a){};', 3, 7, new ArgumentAnalysis(
'$a',
7,
Expand Down

0 comments on commit e04702a

Please sign in to comment.