.. _completion: Completion ========== .. contents:: :depth: 2 :backlinks: none :local: Completors ---------- .. note:: Completors can be enabled or disabled in configuration f.e. :ref:`param_completion_worse.completor.worse_parameter.enabled` configuration. ``worse_parameter`` ~~~~~~~~~~~~~~~~~~~ Provides suggestions for arguments. If there are suitable variables in the current scope they will be given priority if they match the type of the method parameter. .. code:: php `` ``$foobar`` will be suggested with a higher priority than ``$barfoo`` and the parameter index will be shown in the completion description. ``worse_constructor`` ~~~~~~~~~~~~~~~~~~~~~ As with ``worse_parameter`` but for constructor arguments. ``worse_class_member`` ~~~~~~~~~~~~~~~~~~~~~~ Provides class member (methods, properties and constants) suggestions. Triggered on ``::`` and ``->``. ``indexed_name`` ~~~~~~~~~~~~~~~~ Provides class and function name completion from the :ref:`indexer`. ``scf_class`` ~~~~~~~~~~~~~ This completor will provide class names by *scanning the vendor directory* and transposing the file names into class names. This completor is disabled by default when using the :ref:`language_server`. ``worse_local_variable`` ~~~~~~~~~~~~~~~~~~~~~~~~ Provide completion for local variables in a scope. Triggered on ``$``. ``declared_function`` ~~~~~~~~~~~~~~~~~~~~~ Provide function name completion based on functions defined at _runtime_ in the Phpactor process. Note that any functions which are not loaded when _Phpactor_ loads will not be available. So this is mainly useful for built-in functions. This completor is disabled by default when using the :ref:`language_server`. ``declared_constant`` ~~~~~~~~~~~~~~~~~~~~~~ Provide constant name completion based on constants defined at _runtime_ in the Phpactor process. This is mainly useful for built-in constants (e.g. ``JSON_PRETTY_PRINT`` or ``PHP_INT_MAX``). ``worse_class_alias`` ~~~~~~~~~~~~~~~~~~~~~~ Provide suggestions for any classes imported into the current class with aliases. ``declared_class`` ~~~~~~~~~~~~~~~~~~ Provide completion for class names from class names defined in the Phpactor process. This is mainly useful when used with the ``scf_class`` completor to provide built-in classes. This completor is disabled by default when using the :ref:`language_server`. Type inference -------------- Assert ~~~~~~ When encountering an ``assert`` with ``instanceof`` it will cast the variable to that type, or a union of that type. See also `#instanceof <#instanceof>`__. .. code:: php // type: Hello|Goodbye Assignments ~~~~~~~~~~~ Phpactor will track assignemnts: .. code:: php // type: MyException } Docblocks ~~~~~~~~~ Docblocks are supported for method parameters, return types, class properties and inline declartaions .. code:: php */ private $iterableOfMyThing; Foreach ~~~~~~~ Understands ``foreach`` with the docblock array annotation: .. code:: php // type:Hello } Also understands simple generics: .. code:: php $foos */ $foos = new ArrayIterator([ new Hello() ]); foreach ($foos as $foo) { $foo-> // type:Hello } FunctionLike ~~~~~~~~~~~~ Understands anonymous functions: .. code:: php // type: Foobar $barfoo-> // type: Barfoo } InstanceOf ~~~~~~~~~~ ``if`` statements are evaluated, if they contain ``instanceof`` then the type is inferred: .. code:: php // type: Hello } .. code:: php // type: Hello .. code:: php // type: Hello|Goodbye } Variables ~~~~~~~~~ Phpactor supports type injection via docblock: .. code:: php // type: Foobar and inference from parameters: .. code:: php */ interface ReflectionCollection extends \IteratorAggregate, \Countable { } /** * @template T of ReflectionMember * @extends ReflectionCollection */ interface ReflectionMemberCollection extends ReflectionCollection { /** * @return ReflectionMemberCollection */ public function byName(string $name): ReflectionMemberCollection; /** * @return ReflectionMemberCollection */ public function byMemberType(string $type): ReflectionMemberCollection; } interface ReflectionClassLike { public function members(): ReflectionMemberCollection; } /** @var ReflectionClassLike $reflection */ $reflection; foreach ($reflection->members()->byMemberType('fii')->byName('__construct') as $constructor) { $reflection-><> }