From 3672887bcb0f8c26487bc8b51090efe17d2b1124 Mon Sep 17 00:00:00 2001 From: Dieter Holvoet Date: Wed, 11 Jan 2023 12:29:33 +0100 Subject: [PATCH] StringToClassRule: Add option to require strict casing --- conf/slam-rules.neon | 11 +++++++++++ lib/StringToClassRule.php | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/conf/slam-rules.neon b/conf/slam-rules.neon index 3761d12..d08bf0d 100644 --- a/conf/slam-rules.neon +++ b/conf/slam-rules.neon @@ -1,3 +1,12 @@ +parameters: + stringToClassRule: + strictCasing: false + +parametersSchema: + stringToClassRule: structure([ + strictCasing: bool() + ]) + services: - class: SlamPhpStan\ClassNotationRule @@ -15,6 +24,8 @@ services: class: SlamPhpStan\StringToClassRule tags: - phpstan.rules.rule + arguments: + strictCasing: %stringToClassRule.strictCasing% - class: SlamPhpStan\UnusedVariableRule tags: diff --git a/lib/StringToClassRule.php b/lib/StringToClassRule.php index 95d8a8b..2734232 100644 --- a/lib/StringToClassRule.php +++ b/lib/StringToClassRule.php @@ -16,10 +16,12 @@ final class StringToClassRule implements Rule { private Broker $broker; + private bool $strictCasing; - public function __construct(Broker $broker) + public function __construct(Broker $broker, bool $strictCasing) { $this->broker = $broker; + $this->strictCasing = $strictCasing; } public function getNodeType(): string @@ -45,7 +47,7 @@ public function processNode(Node $node, Scope $scope): array } $classRef = $this->broker->getClass($className)->getNativeReflection(); - if ($classRef->isInternal() && $classRef->getName() !== $className) { + if (($classRef->isInternal() || $this->strictCasing) && $classRef->getName() !== $className) { return $messages; }