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

Require space after Block Control Structures #137

Merged
merged 1 commit into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"require": {
"php": "^7.2",
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"slevomat/coding-standard": "dev-master#9401aac3b076250dfcbfe391a53f9fea4b2c5201",
"slevomat/coding-standard": "dev-master#469368cc6d8fe83aceba259ef65f1c0a2f63055b",
greg0ire marked this conversation as resolved.
Show resolved Hide resolved
"squizlabs/php_codesniffer": "^3.5.0"
},
"config": {
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@
<rule ref="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment"/>
<!-- Forbid assignments in conditions -->
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
<!-- Require consistent spacing for block structures -->
<rule ref="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing"/>
<!-- Forbid fancy yoda conditions -->
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
<!-- Require usage of early exit -->
Expand Down
6 changes: 3 additions & 3 deletions tests/expected_report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tests/input/constants-var.php 4 0
tests/input/doc-comment-spacing.php 10 0
tests/input/duplicate-assignment-variable.php 1 0
tests/input/EarlyReturn.php 6 0
tests/input/example-class.php 37 0
tests/input/example-class.php 48 0
tests/input/forbidden-comments.php 8 0
tests/input/forbidden-functions.php 6 0
tests/input/inline_type_hint_assertions.php 7 0
Expand All @@ -37,9 +37,9 @@ tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
A TOTAL OF 278 ERRORS AND 0 WARNINGS WERE FOUND IN 33 FILES
A TOTAL OF 289 ERRORS AND 0 WARNINGS WERE FOUND IN 33 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 221 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 232 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


27 changes: 27 additions & 0 deletions tests/fixed/example-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Fancy\TestCase;
use InvalidArgumentException;
use IteratorAggregate;
use Throwable;
use function assert;
use function strlen as stringLength;
use function substr;
Expand Down Expand Up @@ -122,4 +123,30 @@ public function throwWhenInvalid() : void

throw new InvalidArgumentException();
}

public function trySwitchSpace() : void
{
try {
switch (self::VERSION) {
default:
}

foreach ([] as $item) {
echo $item;
}

while (true) {
echo 2;
}

if (true) {
echo 3;
}

echo 1;
} catch (Throwable $throwable) {
}

echo 2;
}
}
22 changes: 22 additions & 0 deletions tests/input/example-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Example;

use Throwable;
use function strlen as stringLength;
use Fancy\TestCase as TestCase;
use const PHP_RELEASE_VERSION as PHP_PATCH_VERSION;
Expand Down Expand Up @@ -118,4 +119,25 @@ public function throwWhenInvalid() : void
throw new \InvalidArgumentException();
}

public function trySwitchSpace() : void
{
try {
switch (self::VERSION) {
default:
}
foreach ([] as $item) {
echo $item;
}
while (true) {
echo 2;
}
if (true) {
echo 3;
}
echo 1;
} catch (Throwable $throwable) {
}
echo 2;
}

}