Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions conf/slam-rules.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
parameters:
stringToClassRule:
strictCasing: false

parametersSchema:
stringToClassRule: structure([
strictCasing: bool()
])

services:
-
class: SlamPhpStan\ClassNotationRule
Expand All @@ -15,6 +24,8 @@ services:
class: SlamPhpStan\StringToClassRule
tags:
- phpstan.rules.rule
arguments:
strictCasing: %stringToClassRule.strictCasing%
-
class: SlamPhpStan\UnusedVariableRule
tags:
Expand Down
6 changes: 4 additions & 2 deletions lib/StringToClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down