From 94e57df8f5afa272f866d229b93a455ef2446d36 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 13 Dec 2024 23:47:37 +0700 Subject: [PATCH 1/2] chore: preparation for PHPStan 2: remove CheckUseStatementsAfterLicenseRule --- phpstan.neon.dist | 6 -- .../CheckUseStatementsAfterLicenseRule.php | 77 ------------------- 2 files changed, 83 deletions(-) delete mode 100644 utils/src/PHPStan/CheckUseStatementsAfterLicenseRule.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c67aa93fcb04..ee5b2b822a8d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,9 +1,3 @@ -services: - - - class: Utils\PHPStan\CheckUseStatementsAfterLicenseRule - tags: - - phpstan.rules.rule - includes: - phpstan-baseline.php diff --git a/utils/src/PHPStan/CheckUseStatementsAfterLicenseRule.php b/utils/src/PHPStan/CheckUseStatementsAfterLicenseRule.php deleted file mode 100644 index 4b23d3204ca1..000000000000 --- a/utils/src/PHPStan/CheckUseStatementsAfterLicenseRule.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ - -namespace Utils\PHPStan; - -use PhpParser\Comment\Doc; -use PhpParser\Node; -use PhpParser\Node\Stmt; -use PhpParser\Node\Stmt\Use_; -use PHPStan\Analyser\Scope; -use PHPStan\Rules\IdentifierRuleError; -use PHPStan\Rules\Rule; -use PHPStan\Rules\RuleErrorBuilder; - -/** - * @implements Rule - */ -final class CheckUseStatementsAfterLicenseRule implements Rule -{ - private const ERROR_MESSAGE = 'Use statement must be located after license docblock'; - private const COPYRIGHT_REGEX = '/\* \(c\) CodeIgniter Foundation /m'; - - public function getNodeType(): string - { - return Stmt::class; - } - - /** - * @param Stmt $node - * - * @return list - */ - public function processNode(Node $node, Scope $scope): array - { - $comments = $node->getComments(); - - if ($comments === []) { - return []; - } - - foreach ($comments as $comment) { - if (! $comment instanceof Doc) { - continue; - } - - if (! preg_match(self::COPYRIGHT_REGEX, $comment->getText())) { - continue; - } - - $previous = $node->getAttribute('previous'); - - while ($previous) { - if ($previous instanceof Use_) { - return [ - RuleErrorBuilder::message(self::ERROR_MESSAGE) - ->identifier('codeigniter.useStmtAfterLicense') - ->build(), - ]; - } - - $previous = $previous->getAttribute('previous'); - } - } - - return []; - } -} From 6644b79927af145001c35e94eaea237411f0aecd Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 13 Dec 2024 23:50:15 +0700 Subject: [PATCH 2/2] chore: fix ci run --- phpstan.neon.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ee5b2b822a8d..929ac4409664 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -12,7 +12,6 @@ parameters: - app - system - tests - - utils/src/PHPStan excludePaths: - app/Views/errors/cli/* - app/Views/errors/html/*