Navigation¶

Phpactor provides some functionality for navigating to (and generating) contextually relevant files such as parent classes, definitions, unit tests, references etc.

  • Class References

  • Class Member References

  • Hover

  • Jump to definition

  • Jump to type

  • Jump to Implementation

  • Jump to or generate related file

Class References¶

Navigate / list all references to a given class.

$ phpactor references:class path/to/Class.php

Class context menu > Find references.

:PhpactorFindReferences

Supported via. the textDocument/references action.

Description¶

Keep track of where a class is being used or perform an initial survey before deciding to rename a class.

The VIM plugin will load the class references into a quick fix list which you can navigate through (see :help quickfix).

The CLI command will list the references and show a highlighted line where the references were found.

Class references

Class references¶

Class Member References¶

Navigate / list all references to a given class member (method, property or constant).

$ phpactor references:member path/to/Class.php memberName

Member context menu > Find references.

:PhpactorFindReferences

Supported via. the textDocument/references action.

Description¶

Scan for all references to a class member in the project.

This functionality is very similar to Class References with the exception that it is possible that not all members will be found as PHP is a loosely typed language and it may not be possible to determine all the class types of methods matching the query.

Hover¶

While not a navigation function as such, this RPC command will show brief information about the symbol underneath the cursor.

Context menu > Hover.

:PhpactorHover

Supported via. the textDocument/hover action.

Jump to definition¶

Jump to the definition of a class or class member.

Member/class context menu > Goto definition.

:PhpactorGotoDefinition

Supported via. the textDocument/definition action.

Description¶

Open the file containing the class or class member under the cursor and move the cursor to the place where class or class member is defined.

This feature is extremely useful! Be sure to map it to a keyboard shortcut and use it often to quickly navigate through your source code.

Jump to type¶

Jump to the type of the symbol under the cursor.

_Member/class context menu > Goto type.

:PhpactorGotoType()

Supported via. the textDocument/typeDefinition action.

Description¶

Sometimes you will want to jump to the type (i.e. the class) of a symbol, for example if you reference a property in code, $this->locator, you can invoke goto type on the property and jump to the, for example, Locator type.

Jump to Implementation¶

Jump to the implementatoin(s) of an interface or class

Member/class context menu > Goto implementation.

:PhpactorGotoImplementations

Supported via. the textDocument/implementation action.

Jump to implementations of the interface or class under the cursor.

Note that this feature only works when used with the Indexer.

Jump to or generate related file¶

Jump to a related file (e.g. parent class, interfaces, unit test, integration test, benchmark), and optionally generate it if it doesn’t exist (where supported).

Jumping¶

Class context menu > Navigate.

:PhpactorNavigate

You specify the jump patterns in .phpactor.json with navigator.destinations:

{
    "navigator.destinations":
    {
      "source": "lib/<kernel>.php",
      "unit_test": "tests/Unit/<kernel>Test.php"
    }
}
This would enable you to jump from

lib/Acme/Post.php to tests/Unit/Acme/Post.php and vice-versa.

Generating¶

If the file doesn’t exist you automatically create it by mapping the navigation targets to template variants:

{
    "code_transform.class_new.variants":
    {
        "source": "default",
        "unit_test": "phpunit_test",
        "exception": "exception",
        "symfony_command": "symfony_command"
    }
}

Now Phpactor should prompt you to create the navigation target if it doesn’t exist.

Description¶

Often classes will have a one-to-one relationship with another class, for example a single class will often have a matching unit test.

Phpactor provides a way to define this relationship:

# .phpactor.yml
navigator.destinations:
    source: lib/<kernel>.php
    unit_test: tests/Unit/<kernel>Test.php

navigator.autocreate:
    source: default
    unit_test: phpunit_test

Above we define a pattern which will match the source code of the project (and assign it an identifier source). We also identify a pattern to identify unit_test classes.

When you are in a source file, the navigate option will offer you the possiblity of jumping to the unit test, and vice-versa.

Above we additionally (and optionally) tell Phpactor that it can autogenerate these classes based on templates.

Logo

Phpactor

Intelligent completion and refactoring tool for PHP


  • Usage
    • Getting Started
    • Configuration
    • Language Server
    • VIM RPC Plugin
    • Other RPC Clients
    • Standalone
  • Reference
    • Completion
    • Configuration
    • Indexer
    • Navigation
    • Refactoring
    • Legacy RPC Commands
    • Templates
    • Types
    • Language Server
  • Tips
    • Performance
  • Integrations
    • Behat
    • Drupal 8
    • PHP-CS-Fixer
    • PHPStan
    • PHPUnit
    • Prophecy
    • Psalm
    • Symfony
  • Other Topics
    • Development
    • Links and Resources
    • RPC Protocol
    • Support

Related Topics

  • Documentation overview
    • Reference
      • Previous: Indexer
      • Next: Refactoring
©2020, Phpactor Community. | Powered by Sphinx 5.0.0 & Alabaster 0.7.13 | Page source
Fork me on GitHub