Skip to content

Commit

Permalink
PHPCS-242 No whitespace allowed before return type colon (backport)
Browse files Browse the repository at this point in the history
Signed-off-by: Björn Lange <[email protected]>
  • Loading branch information
damyanovg authored and b3nl committed Aug 17, 2020
1 parent 5949647 commit edbd5ac
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ The base for the BestIt Standard is [PSR-12](https://github.com/php-fig/fig-stan
| BestIt.Formatting.OpenTag.LineNotEmpty | The next line after the open tag MUST be empty. | no |
| BestIt.Formatting.OpenTag.NoSpaceAfterOpenTag | There MUST be whitespace after the open tag. | no |
| BestIt.Formatting.OpenTag.OpenTagNotFirstStatement | After the open tag there MUST be an empty line. | no |
| BestIt.Formatting.ReturnTypeHintSpacingSniff.NoSpaceBetweenColonAndTypeHint | There MUST be no whitespace after the return type colon. |
| BestIt.Formatting.ReturnTypeHintSpacingSniff.WhitespaceBeforeColon | There MUST be no whitespace before the return type colon. |
| BestIt.Formatting.SpaceAfterDeclare.GroupBlankLineFound | Multiple declare-statements SHOULD be grouped without a blank line. | no |
| BestIt.Formatting.SpaceAfterDeclare.MuchWhitespaceFound | THERE MUST be just one single line after the declare statement. | no |
| BestIt.Formatting.SpaceAfterDeclare.NoWhitespaceFound | There MUST be one empty line after declare-statement. | no |
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<rule ref="./src/Standards/BestIt/ruleset.xml" />

<config name="testVersion" value="7.1" />
<config name="testVersion" value="7.4" />

<file>./build/</file>
<file>./src/</file>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace BestIt\Sniffs\Formatting;

use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSpacingSniff as BaseReturnTypeHintSpacingSniff;

/**
* Checks that there is no whitespace before the return type.
*
* @author blange <[email protected]>
* @package BestIt\Sniffs\Formatting
*/
class ReturnTypeHintSpacingSniff extends BaseReturnTypeHintSpacingSniff
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace BestIt\Sniffs\Formatting\ReturnTypeHintSpacingSniff\Fixtures;

class CorrectClass
{
public function isCorrect(): bool
{
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace BestIt\Sniffs\Formatting\ReturnTypeHintSpacingSniff\Fixtures;

class NoSpaceBetweenColonAndTypeHint
{
public function isCorrect(): bool
{
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace BestIt\Sniffs\Formatting\ReturnTypeHintSpacingSniff\Fixtures;

class NoSpaceBetweenColonAndTypeHint
{
public function isCorrect():bool
{
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace BestIt\Sniffs\Formatting\ReturnTypeHintSpacingSniff\Fixtures;

class WhitespaceBeforeColon
{
public function isCorrect(): bool
{
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace BestIt\Sniffs\Formatting\ReturnTypeHintSpacingSniff\Fixtures;

class WhitespaceBeforeColon
{
public function isCorrect() : bool
{
return true;
}
}
47 changes: 47 additions & 0 deletions tests/Sniffs/Formatting/ReturnTypeHintSpacingSniffTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace BestIt\Sniffs\Formatting;

use BestIt\Sniffs\DefaultSniffIntegrationTestTrait;
use BestIt\SniffTestCase;
use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSpacingSniff as BaseReturnTypeHintSpacingSniff;

/**
* Tests ReturnTypeHintSpacingSniff
*
* @author blange <[email protected]>
* @package BestIt\Sniffs\Formatting
*/
class ReturnTypeHintSpacingSniffTest extends SniffTestCase
{
use DefaultSniffIntegrationTestTrait;

/**
* The tested class.
*
* @var ReturnTypeHintSpacingSniff
*/
private $fixture;

/**
* Sets up the test.
*
* @return void
*/
protected function setUp(): void
{
$this->fixture = new ReturnTypeHintSpacingSniff();
}

/**
* Checks the inheritance of the class.
*
* @return void
*/
public function testInstance(): void
{
static::assertInstanceOf(BaseReturnTypeHintSpacingSniff::class, $this->fixture);
}
}

0 comments on commit edbd5ac

Please sign in to comment.