Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squiz/ScopeKeywordSpacing: add additional tests #793

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

if (isset($tokens[($stackPtr + 1)]) === false) {
$nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
if ($nextNonWhitespace === false) {
// Parse error/live coding. Bow out.
return;
}

Expand Down Expand Up @@ -126,9 +128,6 @@ public function process(File $phpcsFile, $stackPtr)

if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
$spacing = 0;
} else if (isset($tokens[($stackPtr + 2)]) === false) {
// Parse error/live coding. Bow out.
return;
} else {
if ($tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']) {
$spacing = 'newline';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,27 @@ class MyOtherClass
$varQ = 'string',
$varR = 123;

// Intentionally missing a semicolon for testing.
public
$varS,
$varT
}
$varT,
$varU;

// Issue #3188 - static as return type.
public static function fCreate($attributes = []): static
{
return static::factory()->create($attributes);
}
// Issue #3188 - static as return type.
public static function staticAsReturnType($attributes = []): static
{
return static::factory()->create($attributes);
}

public static function fCreate($attributes = []): ?static
{
return static::factory()->create($attributes);
}
public static function nullableStaticReturnType($attributes = []): ?static
{
return static::factory()->create($attributes);
}

// Also account for static used within union types.
public function staticLast($attributes = []): object|static {}
public function staticMiddle(): string|static|object {}
public function staticFirst(): static|object {}
// Also account for static used within union types.
public function staticLast($attributes = []): object|static {}
public function staticMiddle(): string|static|object {}
public function staticFirst(): static|object {}
}

// Ensure that static as a scope keyword when preceeded by a colon which is not for a type declaration is still handled.
$callback = $cond ? get_fn_name() : static function ($a) { return $a * 10; };
Expand Down Expand Up @@ -174,3 +174,16 @@ final class FinalSpacingCorrect {
abstract class AbstractSpacingCorrect {
public abstract function spacingCorrect() {}
}

$closure = static function() { return 'spacing correct'; };
$closure = static function() { return 'spacing incorrect'; };

class ConstantVisibility {
public const PUBLIC_SPACING_CORRECT = true;
protected const PROTECTED_SPACING_CORRECT = true;
private const PRIVATE_SPACING_CORRECT = true;

public const PUBLIC_SPACING_INCORRECT = true;
protected const PROTECTED_SPACING_INCORRECT = true;
private const PRIVATE_SPACING_INCORRECT = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,27 @@ class MyOtherClass
$varQ = 'string',
$varR = 123;

// Intentionally missing a semicolon for testing.
public
$varS,
$varT
}
$varT,
$varU;

// Issue #3188 - static as return type.
public static function fCreate($attributes = []): static
{
return static::factory()->create($attributes);
}
// Issue #3188 - static as return type.
public static function staticAsReturnType($attributes = []): static
{
return static::factory()->create($attributes);
}

public static function fCreate($attributes = []): ?static
{
return static::factory()->create($attributes);
}
public static function nullableStaticReturnType($attributes = []): ?static
{
return static::factory()->create($attributes);
}

// Also account for static used within union types.
public function staticLast($attributes = []): object|static {}
public function staticMiddle(): string|static|object {}
public function staticFirst(): static|object {}
// Also account for static used within union types.
public function staticLast($attributes = []): object|static {}
public function staticMiddle(): string|static|object {}
public function staticFirst(): static|object {}
}

// Ensure that static as a scope keyword when preceeded by a colon which is not for a type declaration is still handled.
$callback = $cond ? get_fn_name() : static function ($a) { return $a * 10; };
Expand Down Expand Up @@ -167,3 +167,16 @@ final class FinalSpacingCorrect {
abstract class AbstractSpacingCorrect {
public abstract function spacingCorrect() {}
}

$closure = static function() { return 'spacing correct'; };
$closure = static function() { return 'spacing incorrect'; };

class ConstantVisibility {
public const PUBLIC_SPACING_CORRECT = true;
protected const PROTECTED_SPACING_CORRECT = true;
private const PRIVATE_SPACING_CORRECT = true;

public const PUBLIC_SPACING_INCORRECT = true;
protected const PROTECTED_SPACING_INCORRECT = true;
private const PRIVATE_SPACING_INCORRECT = true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

// Intentional parse error.
// Testing handling of multi-property statements during live coding (missing semicolon after statement).
// This must be the only test in this file.
class MyOtherClass
{
public
$varS,
$varT
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public function getErrorList($testFile='')
163 => 1,
166 => 1,
167 => 1,
179 => 1,
186 => 1,
187 => 1,
188 => 1,
];

case 'ScopeKeywordSpacingUnitTest.3.inc':
Expand Down
Loading