| 217 | } |
| 218 | |
| 219 | public function getAlias(string $classContent, $import) { |
| 220 | $useStatement = $import->name; |
| 221 | $alias = $import->getShortName(); |
| 222 | |
| 223 | // Regex to find the use statement for the specified class/interface/trait |
| 224 | $pattern = '/use\s+' . preg_quote($useStatement, '/') . '\s*(?:as\s+(.*?))?\s*;/'; |
| 225 | preg_match($pattern, $classContent, $matches); |
| 226 | |
| 227 | if (!empty($matches)) { |
| 228 | // If an alias is defined, use it; otherwise, use the last part of the use statement (class/interface/trait name) |
| 229 | $alias = isset($matches[1]) ? $matches[1] : basename(str_replace('\\', '/', $useStatement)); |
| 230 | } |
| 231 | |
| 232 | return $alias; |
| 233 | } |
| 234 | |
| 235 | public function getAllImports($model) |
| 236 | { |