Skip to content

Commit

Permalink
DeclareStrictTypesSniff: Renamed option "newlinesCountBetweenOpenTagA…
Browse files Browse the repository at this point in the history
…ndDeclare" to "newlinesCountBeforeDeclare"
  • Loading branch information
kukulich committed Nov 26, 2020
1 parent 23de77f commit a623909
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Enforces having `declare(strict_types = 1)` at the top of each PHP file. Allows

Sniff provides the following settings:

* `newlinesCountBetweenOpenTagAndDeclare`: allows to set 0 to N newlines to be between `<?php` and `declare`
* `newlinesCountBeforeDeclare`: allows to set 0 to N newlines to be between `<?php` and `declare`
* `newlinesCountAfterDeclare`: allows to set 0 to N newlines to be between `declare` and next statement
* `spacesCountAroundEqualsSign`: allows to set number of required spaces around the `=` operator

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DeclareStrictTypesSniff implements Sniff

public const CODE_INCORRECT_STRICT_TYPES_FORMAT = 'IncorrectStrictTypesFormat';

public const CODE_INCORRECT_WHITESPACE_BETWEEN_OPEN_TAG_AND_DECLARE = 'IncorrectWhitespaceBetweenOpenTagAndDeclare';
public const CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE = 'IncorrectWhitespaceBeforeDeclare';

public const CODE_INCORRECT_WHITESPACE_AFTER_DECLARE = 'IncorrectWhitespaceAfterDeclare';

Expand Down Expand Up @@ -167,7 +167,7 @@ public function process(File $phpcsFile, $openTagPointer): void
$fix = $phpcsFile->addFixableError(
'There must be a single space between the PHP open tag and declare statement.',
$declarePointer,
self::CODE_INCORRECT_WHITESPACE_BETWEEN_OPEN_TAG_AND_DECLARE
self::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE
);
if ($fix) {
$phpcsFile->fixer->beginChangeset();
Expand All @@ -183,12 +183,12 @@ public function process(File $phpcsFile, $openTagPointer): void
if ($newlinesCountBefore !== $requiredNewlinesCountBetweenOpenTagAndDeclare) {
$fix = $phpcsFile->addFixableError(
sprintf(
'Expected %d newlines between PHP open tag and declare statement, found %d.',
'Expected %d newlines before declare statement, found %d.',
$requiredNewlinesCountBetweenOpenTagAndDeclare,
$newlinesCountBefore
),
$declarePointer,
self::CODE_INCORRECT_WHITESPACE_BETWEEN_OPEN_TAG_AND_DECLARE
self::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE
);
if ($fix) {
$phpcsFile->fixer->beginChangeset();
Expand Down
18 changes: 9 additions & 9 deletions tests/Sniffs/TypeHints/DeclareStrictTypesSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testDeclareStrictTwoNewlinesBeforeError(): void
self::assertSniffError(
$report,
3,
DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BETWEEN_OPEN_TAG_AND_DECLARE,
DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE,
'There must be a single space between the PHP open tag and declare statement.'
);
}
Expand Down Expand Up @@ -137,8 +137,8 @@ public function testDeclareStrictOneSpaceError(): void
self::assertSniffError(
$report,
1,
DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BETWEEN_OPEN_TAG_AND_DECLARE,
'Expected 2 newlines between PHP open tag and declare statement, found 0.'
DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE,
'Expected 2 newlines before declare statement, found 0.'
);
}

Expand Down Expand Up @@ -166,47 +166,47 @@ public function testFixableNoNewLinesBefore(): void
{
$report = self::checkFile(__DIR__ . '/data/fixableDeclareStrictTypesNoNewLinesBefore.php', [
'newlinesCountBetweenOpenTagAndDeclare' => 0,
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING, DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BETWEEN_OPEN_TAG_AND_DECLARE]);
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING, DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE]);
self::assertAllFixedInFile($report);
}

public function testFixableMissingNoNewLines(): void
{
$report = self::checkFile(__DIR__ . '/data/fixableDeclareStrictTypesMissingNoNewLines.php', [
'newlinesCountBetweenOpenTagAndDeclare' => 0,
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING, DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BETWEEN_OPEN_TAG_AND_DECLARE]);
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING, DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE]);
self::assertAllFixedInFile($report);
}

public function testFixableOneNewLineBefore(): void
{
$report = self::checkFile(__DIR__ . '/data/fixableDeclareStrictTypesOneNewLineBefore.php', [
'newlinesCountBetweenOpenTagAndDeclare' => 1,
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING, DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BETWEEN_OPEN_TAG_AND_DECLARE]);
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING, DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE]);
self::assertAllFixedInFile($report);
}

public function testFixableMissingOneNewLine(): void
{
$report = self::checkFile(__DIR__ . '/data/fixableDeclareStrictTypesMissingOneNewLine.php', [
'newlinesCountBetweenOpenTagAndDeclare' => 1,
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING, DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BETWEEN_OPEN_TAG_AND_DECLARE]);
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING, DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE]);
self::assertAllFixedInFile($report);
}

public function testFixableMoreNewLinesBefore(): void
{
$report = self::checkFile(__DIR__ . '/data/fixableDeclareStrictTypesMoreNewLinesBefore.php', [
'newlinesCountBetweenOpenTagAndDeclare' => 4,
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING, DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BETWEEN_OPEN_TAG_AND_DECLARE]);
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING, DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE]);
self::assertAllFixedInFile($report);
}

public function testFixableMissingMoreNewLines(): void
{
$report = self::checkFile(__DIR__ . '/data/fixableDeclareStrictTypesMissingMoreNewLines.php', [
'newlinesCountBetweenOpenTagAndDeclare' => 4,
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING, DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BETWEEN_OPEN_TAG_AND_DECLARE]);
], [DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING, DeclareStrictTypesSniff::CODE_INCORRECT_WHITESPACE_BEFORE_DECLARE]);
self::assertAllFixedInFile($report);
}

Expand Down

0 comments on commit a623909

Please sign in to comment.