Skip to content

Commit

Permalink
Adopt PSR-12 for imports statements separation
Browse files Browse the repository at this point in the history
[PSR-12](https://www.php-fig.org/psr/psr-12) is an extension of the PSR-2 set of rules
that aims to standardize the code style.

As per PSR-12, under the [item 3](https://www.php-fig.org/psr/psr-12/#3-declare-statements-namespace-and-import-statements):

The header of a PHP file may consist of a number of different blocks. If present,
each of the blocks below MUST be separated by a single blank line, and MUST NOT
contain a blank line. Each block MUST be in the order listed below, although
blocks that are not relevant may be omitted.

For context on why this was voted in the past, see #9.
  • Loading branch information
carusogabriel committed Mar 20, 2020
1 parent 7e7aff6 commit 1ede95a
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
<properties>
<property name="linesCountAfterLastUse" value="1"/>
<property name="linesCountBeforeFirstUse" value="1"/>
<property name="linesCountBetweenUseTypes" value="0"/>
<property name="linesCountBetweenUseTypes" value="1"/>
</properties>
</rule>
<!-- Forbid useless alias for classes, constants and functions -->
Expand Down
1 change: 1 addition & 0 deletions tests/fixed/ControlStructures.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use InvalidArgumentException;
use Throwable;

use const PHP_VERSION;

class ControlStructures
Expand Down
2 changes: 2 additions & 0 deletions tests/fixed/example-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
use Fancy\TestCase;
use InvalidArgumentException;
use IteratorAggregate;

use function assert;
use function strlen as stringLength;
use function substr;

use const PHP_MINOR_VERSION;
use const PHP_RELEASE_VERSION as PHP_PATCH_VERSION;
use const PHP_VERSION;
Expand Down
2 changes: 2 additions & 0 deletions tests/fixed/namespaces-spacing.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use DateInterval;
use DateTimeImmutable;
use DateTimeZone;

use function strrev;
use function time;

use const DATE_RFC3339;

strrev(
Expand Down
2 changes: 2 additions & 0 deletions tests/fixed/use-ordering.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use DateTimeImmutable;
use DateTimeInterface;

use function sprintf;

use const PHP_EOL;

echo sprintf('Current date and time is %s', (new DateTimeImmutable())->format(DateTimeInterface::ATOM)) . PHP_EOL;
1 change: 1 addition & 0 deletions tests/input/ControlStructures.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use InvalidArgumentException;
use Throwable;

use const PHP_VERSION;

class ControlStructures
Expand Down
4 changes: 4 additions & 0 deletions tests/input/example-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
namespace Example;

use Throwable;

use function strlen as stringLength;

use Fancy\TestCase as TestCase;

use const PHP_RELEASE_VERSION as PHP_PATCH_VERSION;

use Doctrine\Sniffs\Spacing\ControlStructureSniff;

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/input/namespaces-spacing.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
use DateInterval;
use DateTimeImmutable;
use DateTimeZone;

use function strrev;
use function time;

use const DATE_RFC3339;
strrev(
(new DateTimeImmutable('@' . time(), new DateTimeZone('UTC')))
Expand Down
3 changes: 3 additions & 0 deletions tests/input/use-ordering.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
namespace Foo;

use function sprintf;

use DateTimeImmutable;

use const PHP_EOL;

use DateTimeInterface;

echo sprintf('Current date and time is %s', (new DateTimeImmutable())->format(DateTimeInterface::ATOM)) . PHP_EOL;

0 comments on commit 1ede95a

Please sign in to comment.