Skip to content

Commit edbd5ac

Browse files
damyanovgb3nl
authored andcommitted
PHPCS-242 No whitespace allowed before return type colon (backport)
Signed-off-by: Björn Lange <[email protected]>
1 parent 5949647 commit edbd5ac

File tree

9 files changed

+133
-1
lines changed

9 files changed

+133
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ The base for the BestIt Standard is [PSR-12](https://github.com/php-fig/fig-stan
140140
| BestIt.Formatting.OpenTag.LineNotEmpty | The next line after the open tag MUST be empty. | no |
141141
| BestIt.Formatting.OpenTag.NoSpaceAfterOpenTag | There MUST be whitespace after the open tag. | no |
142142
| BestIt.Formatting.OpenTag.OpenTagNotFirstStatement | After the open tag there MUST be an empty line. | no |
143+
| BestIt.Formatting.ReturnTypeHintSpacingSniff.NoSpaceBetweenColonAndTypeHint | There MUST be no whitespace after the return type colon. |
144+
| BestIt.Formatting.ReturnTypeHintSpacingSniff.WhitespaceBeforeColon | There MUST be no whitespace before the return type colon. |
143145
| BestIt.Formatting.SpaceAfterDeclare.GroupBlankLineFound | Multiple declare-statements SHOULD be grouped without a blank line. | no |
144146
| BestIt.Formatting.SpaceAfterDeclare.MuchWhitespaceFound | THERE MUST be just one single line after the declare statement. | no |
145147
| BestIt.Formatting.SpaceAfterDeclare.NoWhitespaceFound | There MUST be one empty line after declare-statement. | no |

phpcs.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

7-
<config name="testVersion" value="7.1" />
7+
<config name="testVersion" value="7.4" />
88

99
<file>./build/</file>
1010
<file>./src/</file>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BestIt\Sniffs\Formatting;
6+
7+
use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSpacingSniff as BaseReturnTypeHintSpacingSniff;
8+
9+
/**
10+
* Checks that there is no whitespace before the return type.
11+
*
12+
* @author blange <[email protected]>
13+
* @package BestIt\Sniffs\Formatting
14+
*/
15+
class ReturnTypeHintSpacingSniff extends BaseReturnTypeHintSpacingSniff
16+
{
17+
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BestIt\Sniffs\Formatting\ReturnTypeHintSpacingSniff\Fixtures;
6+
7+
class CorrectClass
8+
{
9+
public function isCorrect(): bool
10+
{
11+
return true;
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BestIt\Sniffs\Formatting\ReturnTypeHintSpacingSniff\Fixtures;
6+
7+
class NoSpaceBetweenColonAndTypeHint
8+
{
9+
public function isCorrect(): bool
10+
{
11+
return true;
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BestIt\Sniffs\Formatting\ReturnTypeHintSpacingSniff\Fixtures;
6+
7+
class NoSpaceBetweenColonAndTypeHint
8+
{
9+
public function isCorrect():bool
10+
{
11+
return true;
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BestIt\Sniffs\Formatting\ReturnTypeHintSpacingSniff\Fixtures;
6+
7+
class WhitespaceBeforeColon
8+
{
9+
public function isCorrect(): bool
10+
{
11+
return true;
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BestIt\Sniffs\Formatting\ReturnTypeHintSpacingSniff\Fixtures;
6+
7+
class WhitespaceBeforeColon
8+
{
9+
public function isCorrect() : bool
10+
{
11+
return true;
12+
}
13+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BestIt\Sniffs\Formatting;
6+
7+
use BestIt\Sniffs\DefaultSniffIntegrationTestTrait;
8+
use BestIt\SniffTestCase;
9+
use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSpacingSniff as BaseReturnTypeHintSpacingSniff;
10+
11+
/**
12+
* Tests ReturnTypeHintSpacingSniff
13+
*
14+
* @author blange <[email protected]>
15+
* @package BestIt\Sniffs\Formatting
16+
*/
17+
class ReturnTypeHintSpacingSniffTest extends SniffTestCase
18+
{
19+
use DefaultSniffIntegrationTestTrait;
20+
21+
/**
22+
* The tested class.
23+
*
24+
* @var ReturnTypeHintSpacingSniff
25+
*/
26+
private $fixture;
27+
28+
/**
29+
* Sets up the test.
30+
*
31+
* @return void
32+
*/
33+
protected function setUp(): void
34+
{
35+
$this->fixture = new ReturnTypeHintSpacingSniff();
36+
}
37+
38+
/**
39+
* Checks the inheritance of the class.
40+
*
41+
* @return void
42+
*/
43+
public function testInstance(): void
44+
{
45+
static::assertInstanceOf(BaseReturnTypeHintSpacingSniff::class, $this->fixture);
46+
}
47+
}

0 commit comments

Comments
 (0)