diff --git a/specs/string-literal/array-var.php b/specs/string-literal/array-var.php index f0a0469f..93d9f7c3 100644 --- a/specs/string-literal/array-var.php +++ b/specs/string-literal/array-var.php @@ -70,6 +70,31 @@ PHP, + 'String argument referencing a namespaced internal class' => <<<'PHP' + 'Random\\Randomizer', + 'PDO\\Mysql' => 'PDO\\Mysql', + 'Filter\\FilterFailedException' => 'Filter\\FilterFailedException', + ]; + + ---- + 'Random\Randomizer', 'PDO\Mysql' => 'PDO\Mysql', 'Filter\FilterFailedException' => 'Filter\FilterFailedException']; + + PHP, + 'Array item of a list with class-like symbols' => <<<'PHP' <<<'PHP' + SpecWithConfig::create( exposeClasses: ['Symfony\Component\Yaml\Yaml'], spec: <<<'PHP' diff --git a/specs/string-literal/var.php b/specs/string-literal/var.php index 5765a2c6..70a4a151 100644 --- a/specs/string-literal/var.php +++ b/specs/string-literal/var.php @@ -50,6 +50,28 @@ PHP, + 'FQCN string argument referencing a namespaced internal class' => <<<'PHP' + <<<'PHP' belongsToTheGlobalNamespace($string) - ? $string - : $this->createPrefixedString($string); + return $this->createPrefixedStringIfDoesNotBelongToGlobalNamespace($string); } private function prefixStringArg(String_ $string, Arg $parentNode, string $normalizedValue): String_ @@ -379,9 +377,15 @@ private static function isConstantNode(String_ $node): bool private function createPrefixedStringIfDoesNotBelongToGlobalNamespace(String_ $string): String_ { // If belongs to the global namespace then we cannot differentiate the value from a symbol and a regular string - return $this->belongsToTheGlobalNamespace($string) - ? $string - : $this->createPrefixedString($string); + if ($this->belongsToTheGlobalNamespace($string)) { + return $string; + } + + if ($this->enrichedReflector->isClassExcluded(ltrim($string->value, '\\'))) { + return $string; + } + + return $this->createPrefixedString($string); } private function belongsToTheGlobalNamespace(String_ $string): bool