PHP code example of phpactor / completion

1. Go to this page and download the library: Download phpactor/completion library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpactor / completion example snippets


$completor = new MyCompletor();
$suggestions = $completor->complete($sourceCode, $byteOffset);

/** @var Suggestion $suggestion */
foreach ($suggestions as $suggestion) {
    echo $suggestion->name();
    echo $suggestion->shortDescription();
}

$completor = new ChainCompletor([
    new MyCompletor1(),
    new MyCompletor2(),
]);

$suggestions = $completor->complete($sourceCode, $byteOffset);

use Phpactor\WorseReflection\ReflectorBuilder;
use Phpactor\Completion\Bridge\TolerantParser\ChainTolerantCompletor;
use Phpactor\Completion\Bridge\TolerantParser\WorseReflection\WorseLocalVariableCompletor;
use Phpactor\Completion\Bridge\TolerantParser\WorseReflection\WorseClassMemberCompletor;

$reflector = ReflectorBuilder::create()->addSource($sourceCode)->build();
$formatter = new ObjectFormatter([
    // ... instances of ObjectFormatter
]);
$completor = new ChainTolerantCompletor([
    new WorseLocalVariableCompletor($reflector, $formatter),
    new WorseClassMemberCompletor($reflector, $formatter),
]);

$completor->complete($sourceCode, $byteOffset);

$formatter = new ObjectFormatter([
    new TypeFormatter(),
    new TypesFormatter(),
    new FunctionFormatter(),
    new MethodFormatter(),
    new ParameterFormatter(),
    new ParametersFormatter(),
    new PropertyFormatter(),
    new VariableFormatter(),
]);

$reflectionMethod = $reflector->reflectClass(Foobar::class)->methods()->get('barfoo');
$formatter->format($reflectionMethod);