Skip to content

Commit

Permalink
Merge branch '2.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
julienfalque committed Dec 9, 2019
2 parents f7d0e08 + 50a3a58 commit fef1bab
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private function fixSpaceBelowClassMethod(Tokens $tokens, $classEndIndex, $eleme
*/
private function fixSpaceAboveClassElement(Tokens $tokens, $classStartIndex, $elementIndex)
{
static $methodAttr = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC, T_STRING, T_NS_SEPARATOR, T_VAR, CT::T_NULLABLE_TYPE];
static $methodAttr = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC, T_STRING, T_NS_SEPARATOR, T_VAR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT];

$nonWhiteAbove = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private function expandElement(Tokens $tokens, $type, $startIndex, $endIndex)
private function getModifiersSequences(Tokens $tokens, $type, $startIndex, $endIndex)
{
if ('property' === $type) {
$tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_VAR, T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE];
$tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_VAR, T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT];
} else {
$tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_CONST];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocVarAnnotationCorrectOrderFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
}

$newContent = Preg::replace(
'/(@(?:type|var)\s*)(\$\S+)(\s+)([^\$](?:[^<\s]|<[^>]*>)*)(\s|\*)/i',
'/(@(?:type|var)\s*)(\$\S+)(\h+)([^\$](?:[^<\s]|<[^>]*>)*)(\s|\*)/i',
'$1$4$3$2$5',
$token->getContent()
);
Expand Down
4 changes: 3 additions & 1 deletion src/Fixer/StringNotation/ExplicitStringVariableFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$nextIndex = $index + 1;
$squareBracketCount = 0;
while (!$this->isStringPartToken($tokens[$nextIndex])) {
if ($tokens[$nextIndex]->isGivenKind(T_VARIABLE) && 1 !== $squareBracketCount) {
if ($tokens[$nextIndex]->isGivenKind(T_CURLY_OPEN)) {
$nextIndex = $tokens->getNextTokenOfKind($nextIndex, [[CT::T_CURLY_CLOSE]]);
} elseif ($tokens[$nextIndex]->isGivenKind(T_VARIABLE) && 1 !== $squareBracketCount) {
$distinctVariableIndex = $nextIndex;
$variableTokens[$distinctVariableIndex] = [
'tokens' => [$nextIndex => $tokens[$nextIndex]],
Expand Down
4 changes: 2 additions & 2 deletions src/Tokenizer/TokensAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function isConstantInvocation($index)
$prevIndex = $this->tokens->getPrevMeaningfulToken($prevIndex);
}

if ($this->tokens[$prevIndex]->isGivenKind([CT::T_CONST_IMPORT, T_EXTENDS, CT::T_FUNCTION_IMPORT, T_IMPLEMENTS, T_INSTANCEOF, T_INSTEADOF, T_NAMESPACE, T_NEW, CT::T_NULLABLE_TYPE, T_USE, CT::T_USE_TRAIT])) {
if ($this->tokens[$prevIndex]->isGivenKind([CT::T_CONST_IMPORT, T_EXTENDS, CT::T_FUNCTION_IMPORT, T_IMPLEMENTS, T_INSTANCEOF, T_INSTEADOF, T_NAMESPACE, T_NEW, CT::T_NULLABLE_TYPE, CT::T_TYPE_COLON, T_USE, CT::T_USE_TRAIT])) {
return false;
}

Expand All @@ -353,7 +353,7 @@ public function isConstantInvocation($index)
$checkIndex = $this->tokens->getPrevMeaningfulToken($checkIndex);
}

if ($this->tokens[$checkIndex]->isGivenKind([T_EXTENDS, CT::T_GROUP_IMPORT_BRACE_OPEN, T_IMPLEMENTS, CT::T_USE_TRAIT])) {
if ($this->tokens[$checkIndex]->isGivenKind([T_EXTENDS, CT::T_GROUP_IMPORT_BRACE_OPEN, T_IMPLEMENTS, T_USE, CT::T_USE_TRAIT])) {
return false;
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1115,5 +1115,19 @@ class Foo {
var ? Foo\Bar $qux;
}',
];

yield [
'<?php
class Foo {
private array $foo;
private array $bar;
}',
'<?php
class Foo {
private array $foo;
private array $bar;
}',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,8 @@ public function provideFix74Cases()
yield [
'<?php class Foo { protected ? string $bar = null; }',
];
yield [
'<?php class Foo { protected ? array $bar = null; }',
];
}
}
4 changes: 2 additions & 2 deletions tests/Fixer/ClassNotation/OrderedClassElementsFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -862,13 +862,13 @@ class Foo {
'<?php
class Foo {
public string $bar;
public iterable $baz;
public array $baz;
public ?int $foo;
public ? Foo\Bar $qux;
}',
'<?php
class Foo {
public iterable $baz;
public array $baz;
public ? Foo\Bar $qux;
public string $bar;
public ?int $foo;
Expand Down
4 changes: 4 additions & 0 deletions tests/Fixer/ClassNotation/ProtectedToPrivateFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public function provideFix74Cases()
'<?php final class Foo { private ?string $foo; }',
'<?php final class Foo { protected ?string $foo; }',
];
yield [
'<?php final class Foo { private array $foo; }',
'<?php final class Foo { protected array $foo; }',
];
}

private function getAttributesAndMethods($original)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,5 +874,14 @@ public function provideTestFix74Cases()
var ? Foo\Bar $foo, $bar;
}',
];
yield [
'<?php class Foo {
var array $foo;
var array $bar;
}',
'<?php class Foo {
var array $foo, $bar;
}',
];
}
}
4 changes: 4 additions & 0 deletions tests/Fixer/Naming/NoHomoglyphNamesFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public function provideFix74Cases()
'<?php class A { private ? Foo\Bar $name; }',
'<?php class A { private ? Foo\Bar $nаmе; }',
],
[
'<?php class A { private array $name; }',
'<?php class A { private array $nаmе; }',
],
];
}
}
9 changes: 9 additions & 0 deletions tests/Fixer/Phpdoc/PhpdocToCommentFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,15 @@ class Foo {
var ? Foo\Bar $foo;
}',
],
[
'<?php
class Foo {
/**
* Do not convert this
*/
var ? array $foo;
}',
],
];
}
}
12 changes: 12 additions & 0 deletions tests/Fixer/Phpdoc/PhpdocVarAnnotationCorrectOrderFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,17 @@ public function provideFixCases()
/** @var $foo Foo|array<int, int>|null */
',
];

yield [
'<?php
class Foo
{
/**
* @var $bar
*/
private $bar;
}
',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ public function provideTestFixCases()
'<?php $mobileNumberVisible = "***-***-{$last4Digits[0]}{$last4Digits[1]}-{$last4Digits[2]}{$last4Digits[3]}";',
'<?php $mobileNumberVisible = "***-***-$last4Digits[0]$last4Digits[1]-$last4Digits[2]$last4Digits[3]";',
],
[
'<?php $pair = "${foo} {$bar[0]}";',
'<?php $pair = "$foo {$bar[0]}";',
],
[
'<?php $pair = "${foo}{$bar[0]}";',
'<?php $pair = "$foo{$bar[0]}";',
],
];
}

Expand Down
10 changes: 9 additions & 1 deletion tests/Tokenizer/TokensAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function testGetClassyElementsWithNullableProperties()
class Foo
{
public int $prop0;
protected ?int $prop1;
protected ?array $prop1;
private string $prop2 = 1;
var ? Foo\Bar $prop3 = array(1,2,3);
}
Expand Down Expand Up @@ -786,6 +786,10 @@ public function provideIsConstantInvocationCases()
'<?php interface Foo extends Bar, Baz, Qux {}',
[7 => false, 10 => false, 13 => false],
],
[
'<?php use Foo\Bar, Foo\Baz, Foo\Qux;',
[3 => false, 5 => false, 8 => false, 10 => false, 13 => false, 15 => false],
],
];
}

Expand Down Expand Up @@ -852,6 +856,10 @@ public function provideIsConstantInvocation71Cases()
'<?php interface Foo { public function bar(): Baz; }',
[16 => false],
],
[
'<?php interface Foo { public function bar(): \Baz; }',
[17 => false],
],
[
'<?php interface Foo { public function bar(): ?Baz; }',
[17 => false],
Expand Down

0 comments on commit fef1bab

Please sign in to comment.