17 private $classNameExtractor;
27 $this->classNameExtractor = $classNameExtractor;
36 public function find($fileContent)
41 '/(get|create)\(\s*([a-z0-9\\\\]+)::class\s*\)/im',
46 if (isset($shortNameMatches[2])) {
47 foreach ($shortNameMatches[2] as $shortName) {
48 if (substr($shortName, 0, 1) !==
'\\') {
49 $class = $this->matchPartialNamespace($fileContent, $shortName);
59 $className = $this->classNameExtractor->getNameWithNamespace($fileContent);
79 private function getConstructorArguments(
$className)
85 $classParameters = $constructor->getParameters();
86 foreach ($classParameters as $classParameter) {
87 if ($classParameter->getType()) {
88 $parameterType = $classParameter->getType();
103 private function matchPartialNamespace($fileContent, $shortName)
106 '/^use\s([a-z0-9\\\\]+' . str_replace(
'\\',
'\\\\', $shortName) .
');$/im',
110 if (isset($fullNameMatches[1][0])) {
111 $class = $fullNameMatches[1][0];
114 '/^use\s([a-z0-9\\\\]+)\sas\s' . str_replace(
'\\',
'\\\\', $shortName) .
';$/im',
116 $fullNameAliasMatches
118 if (isset($fullNameAliasMatches[1][0])) {
119 $class = $fullNameAliasMatches[1][0];
121 $forwardSlashPos = strpos($shortName,
'\\');
122 $partialNamespace = substr($shortName, 0, $forwardSlashPos);
124 '/^use\s([a-z0-9\\\\]+)' . $partialNamespace .
';$/im',
126 $partialNamespaceMatches
128 if ($forwardSlashPos && isset($partialNamespaceMatches[1][0])) {
129 $class = $partialNamespaceMatches[1][0] . $shortName;
131 $class = $this->classNameExtractor->getNamespace($fileContent) .
'\\' . $shortName;
__construct(ClassNameExtractor $classNameExtractor)
$_option $_optionId $class