Exemplo n.º 1
0
 private function getNamespaceUseDeclarations(Tokens $tokens, array $useIndexes)
 {
     $uses = array();
     foreach ($useIndexes as $index) {
         $declarationEndIndex = null;
         $tokens->getNextTokenOfKind($index, array(';'), $declarationEndIndex);
         $declarationContent = $tokens->generatePartialCode($index + 1, $declarationEndIndex - 1);
         // ignore multiple use statements like: `use BarB, BarC as C, BarD;`
         // that should be split into few separate statements
         if (false !== strpos($declarationContent, ',')) {
             continue;
         }
         $declarationParts = preg_split('/\\s+as\\s+/i', $declarationContent);
         if (1 === count($declarationParts)) {
             $fullName = $declarationContent;
             $declarationParts = explode('\\', $fullName);
             $shortName = end($declarationParts);
             $aliased = false;
         } else {
             $fullName = $declarationParts[0];
             $shortName = $declarationParts[1];
             $declarationParts = explode('\\', $fullName);
             $aliased = $shortName !== end($declarationParts);
         }
         $shortName = trim($shortName);
         $uses[$shortName] = array('shortName' => $shortName, 'fullName' => trim($fullName), 'aliased' => $aliased, 'declarationStart' => $index, 'declarationEnd' => $declarationEndIndex);
     }
     return $uses;
 }