| @@ 9-31 (lines=23) @@ | ||
| 6 | use Padawan\Domain\Completion\Context; |
|
| 7 | use Padawan\Domain\Completion\Entry; |
|
| 8 | ||
| 9 | class NamespaceCompleter extends AbstractFileInfoCompleter |
|
| 10 | { |
|
| 11 | ||
| 12 | public function getEntries(Project $project, Context $context) { |
|
| 13 | $entries = []; |
|
| 14 | $postfix = trim($context->getData()); |
|
| 15 | foreach ($project->getIndex()->getFQCNs() AS $fqcn) { |
|
| 16 | $namespace = $fqcn->getNamespace(); |
|
| 17 | if (!empty($postfix) && strpos($namespace, $postfix) === false) { |
|
| 18 | continue; |
|
| 19 | } |
|
| 20 | $complete = str_replace($postfix, "", $namespace); |
|
| 21 | $entries[$namespace] = new Entry($complete, "", "", $namespace); |
|
| 22 | } |
|
| 23 | $entries = array_values($entries); |
|
| 24 | return $entries; |
|
| 25 | } |
|
| 26 | ||
| 27 | public function canHandle(Project $project, Context $context) |
|
| 28 | { |
|
| 29 | return parent::canHandle($project, $context) && $context->isNamespace(); |
|
| 30 | } |
|
| 31 | } |
|
| 32 | ||
| @@ 9-36 (lines=28) @@ | ||
| 6 | use Padawan\Domain\Completion\Context; |
|
| 7 | use Padawan\Domain\Completion\Entry; |
|
| 8 | ||
| 9 | class UseCompleter extends AbstractFileInfoCompleter |
|
| 10 | { |
|
| 11 | public function getEntries(Project $project, Context $context) |
|
| 12 | { |
|
| 13 | $entries = []; |
|
| 14 | $postfix = trim($context->getData()); |
|
| 15 | $index = $project->getIndex(); |
|
| 16 | $fqcns = array_merge($index->getClasses(), $index->getInterfaces()); |
|
| 17 | foreach ($fqcns as $fqcn => $class) { |
|
| 18 | if (!empty($postfix) && strpos($fqcn, $postfix) === false) { |
|
| 19 | continue; |
|
| 20 | } |
|
| 21 | $complete = str_replace($postfix, "", $fqcn); |
|
| 22 | $entries[] = new Entry( |
|
| 23 | $complete, |
|
| 24 | '', |
|
| 25 | '', |
|
| 26 | $fqcn |
|
| 27 | ); |
|
| 28 | } |
|
| 29 | return $entries; |
|
| 30 | } |
|
| 31 | ||
| 32 | public function canHandle(Project $project, Context $context) |
|
| 33 | { |
|
| 34 | return parent::canHandle($project, $context) && $context->isUse(); |
|
| 35 | } |
|
| 36 | } |
|
| 37 | ||