diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c8e54c02..80a258da 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -9,7 +9,7 @@ on: - "master" env: - MIN_COVERED_MSI: 93 + MIN_COVERED_MSI: 92 MIN_MSI: 83 REQUIRED_PHP_EXTENSIONS: "mbstring" diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ccda4cf..ae8c610a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased -For a full diff see [`0.14.2...master`][0.14.2...master]. +For a full diff see [`0.14.3...master`][0.14.3...master]. + +## [`0.14.3`][0.14.3] + +For a full diff see [`0.14.2...0.14.3`][0.14.2...0.14.3]. + +### Fixed + +* Ignored first line in `DeclareStrictTypesRule` when it is a shebang ([#186]), by [@Great-Antique] ## [`0.14.2`][0.14.2] @@ -296,6 +304,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [0.14.0]: https://github.com/ergebnis/phpstan-rules/releases/tag/0.14.0 [0.14.1]: https://github.com/ergebnis/phpstan-rules/releases/tag/0.14.1 [0.14.2]: https://github.com/ergebnis/phpstan-rules/releases/tag/0.14.2 +[0.14.3]: https://github.com/ergebnis/phpstan-rules/releases/tag/0.14.3 [362c7ea...0.1.0]: https://github.com/ergebnis/phpstan-rules/compare/362c7ea...0.1.0 [0.1.0...0.2.0]: https://github.com/ergebnis/phpstan-rules/compare/0.1.0...0.2.0 @@ -318,7 +327,8 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [0.13.0...0.14.0]: https://github.com/ergebnis/phpstan-rules/compare/0.13.0...0.14.0 [0.14.0...0.14.1]: https://github.com/ergebnis/phpstan-rules/compare/0.14.0...0.14.1 [0.14.1...0.14.2]: https://github.com/ergebnis/phpstan-rules/compare/0.14.1...0.14.2 -[0.14.2...master]: https://github.com/ergebnis/phpstan-rules/compare/0.14.2...master +[0.14.2...0.14.3]: https://github.com/ergebnis/phpstan-rules/compare/0.14.2...0.14.3 +[0.14.3...master]: https://github.com/ergebnis/phpstan-rules/compare/0.14.3...master [#1]: https://github.com/ergebnis/phpstan-rules/pull/1 [#4]: https://github.com/ergebnis/phpstan-rules/pull/4 @@ -365,6 +375,8 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [#158]: https://github.com/ergebnis/phpstan-rules/pull/158 [#161]: https://github.com/ergebnis/phpstan-rules/pull/161 [#166]: https://github.com/ergebnis/phpstan-rules/pull/166 +[#186]: https://github.com/ergebnis/phpstan-rules/pull/186 [@ergebnis]: https://github.com/ergebnis +[@Great-Antique]: https://github.com/Great-Antique [@localheinz]: https://github.com/localheinz diff --git a/Makefile b/Makefile index b99e92ab..b3190220 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -MIN_COVERED_MSI:=93 +MIN_COVERED_MSI:=92 MIN_MSI:=83 .PHONY: it diff --git a/src/Files/DeclareStrictTypesRule.php b/src/Files/DeclareStrictTypesRule.php index c5fc6d44..bb315d26 100644 --- a/src/Files/DeclareStrictTypesRule.php +++ b/src/Files/DeclareStrictTypesRule.php @@ -44,6 +44,14 @@ public function processNode(Node $node, Scope $scope): array $firstNode = \array_shift($nodes); + if ( + $firstNode instanceof Node\Stmt\InlineHTML + && 2 === $firstNode->getEndLine() + && 0 === \mb_strpos($firstNode->value, '#!') + ) { + $firstNode = \array_shift($nodes); + } + if ($firstNode instanceof Node\Stmt\Declare_) { foreach ($firstNode->declares as $declare) { if ( diff --git a/test/Fixture/Files/DeclareStrictTypesRule/Failure/file-with-shebang-and-another-one-text-line-before-opening-tag.php b/test/Fixture/Files/DeclareStrictTypesRule/Failure/file-with-shebang-and-another-one-text-line-before-opening-tag.php new file mode 100644 index 00000000..af60dc8e --- /dev/null +++ b/test/Fixture/Files/DeclareStrictTypesRule/Failure/file-with-shebang-and-another-one-text-line-before-opening-tag.php @@ -0,0 +1,5 @@ +#!/usr/bin/env php +Another line below shebang + __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-doc-block-and-declare-strict-types-on-and-invalid-casing.php', 'file-with-doc-block-and-declare-strict-types-on-and-multiple-declares' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-doc-block-and-declare-strict-types-on-and-multiple-declares.php', 'file-with-doc-block-and-declare-strict-types-on-and-namespace-declaration' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-doc-block-and-declare-strict-types-on-and-namespace-declaration.php', + 'file-with-shebang-and-declare-strict-types-on' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-shebang-and-declare-strict-types-on.php', ]; foreach ($paths as $description => $path) { @@ -122,6 +123,27 @@ public function providerAnalysisFails(): iterable 7, ], ], + 'file-with-shebang-and-another-one-text-line-before-opening-tag' => [ + __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-shebang-and-another-one-text-line-before-opening-tag.php', + [ + 'File is missing a "declare(strict_types=1)" declaration.', + 1, + ], + ], + 'file-with-shebang-and-declare-strict-types-off' => [ + __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-shebang-and-declare-strict-types-off.php', + [ + 'File is missing a "declare(strict_types=1)" declaration.', + 1, + ], + ], + 'file-with-text-before-opening-tag' => [ + __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-text-before-opening-tag.php', + [ + 'File is missing a "declare(strict_types=1)" declaration.', + 1, + ], + ], 'file-without-declare-strict-types-and-namespace-declaration' => [ __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-without-declare-strict-types-and-namespace-declaration.php', [