Skip to content

Commit cc96a93

Browse files
authored
Merge pull request #89 from ldusan84/feature/literal-namespaces-sniff-improvement
Removed class exists checks and added exclude patterns
2 parents 50e189a + fdf7243 commit cc96a93

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

Magento2/Sniffs/PHP/LiteralNamespacesSniff.php

+1-17
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,12 @@ public function process(File $sourceFile, $stackPtr)
5252
$content = preg_replace('|\\\{2,}|', '\\', $content);
5353
}
5454

55-
if (preg_match($this->literalNamespacePattern, $content) === 1 && $this->classExists($content)) {
55+
if (preg_match($this->literalNamespacePattern, $content) === 1) {
5656
$sourceFile->addWarning(
5757
"Use ::class notation instead.",
5858
$stackPtr,
5959
'LiteralClassUsage'
6060
);
6161
}
6262
}
63-
64-
/**
65-
* Checks if class or interface exists.
66-
*
67-
* ToDo: get rig of this check https://github.com/magento/magento-coding-standard/issues/9
68-
*
69-
* @param string $className
70-
* @return bool
71-
*/
72-
private function classExists($className)
73-
{
74-
if (!isset($this->classNames[$className])) {
75-
$this->classNames[$className] = class_exists($className) || interface_exists($className);
76-
}
77-
return $this->classNames[$className];
78-
}
7963
}

Magento2/ruleset.xml

+4
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@
245245
<rule ref="Magento2.PHP.LiteralNamespaces">
246246
<severity>7</severity>
247247
<type>warning</type>
248+
<exclude-pattern>*/_files/*</exclude-pattern>
249+
<exclude-pattern>*/Fixtures/*</exclude-pattern>
250+
<exclude-pattern>*/Test/*</exclude-pattern>
251+
<exclude-pattern>*Test.php</exclude-pattern>
248252
</rule>
249253
<rule ref="Magento2.PHP.Var">
250254
<severity>7</severity>

0 commit comments

Comments
 (0)