Skip to content

find indirect references, sharing same interface #809

Open

Description

@kermorgant

Hi,

I was looking at #698 and started wondering if one option would have been to use find-references with some extra metadata (leaving the client doing the filtering to solve #698), but then realised this would not going to work because find-references would not have the desired reference.

For example :

Interface SomeRepository
{
    public function find(int $id): Object;
}

class SomeDoctrineRepository implements SomeRepository
{
    public function find(int $id): Object
    {
         ...
    }
}

class RandomService
{
    public function __construct(SomeRepository $repo)
    {
        $this->repo = $repo;
    }

    public function doSomething()
    {
        $object = $this->repo->find(1);
    }
}

using phpactor's find-references on find on this line $object = $this->repo->find(1); will only suggest the definition from the Interface, not the one in the concrete SomeDoctrineRepository.

Maybe that's a good thing but maybe having a way to also get this indirect reference in the same search would be useful ?

Activity

  1. dantleech commented on Aug 23, 2019

    @dantleech
    Collaborator
    phpactor references:member "Phpactor\\Application" --filesystem=git
    # References:
    +---------------------------------------+-----+--------------------------------------------------------------------------------------------------------------+------+------+
    | Path                                  | LN  | Line                                                                                                         | OS   | OE   |
    +---------------------------------------+-----+--------------------------------------------------------------------------------------------------------------+------+------+
    | lib/Application.php                   | 22  |     private $$container                                                                                      | 666  | 675  |
    | lib/Application.php                   | 27  |     private $$vendorDir                                                                                      | 726  | 735  |
    | lib/Application.php                   | 29  |     public function __construct(string $vendorDir)                                                           | 758  | 769  |
    | lib/Application.php                   | 32  |         $this->vendorDir = $vendorDir;                                                                       | 894  | 903  |
    | lib/Application.php                   | 35  |     public function doRun(InputInterface $input, OutputInterface $output)                                    | 945  | 950  |
    | lib/Application.php                   | 37  |         $this->initialize($input);                                                                           | 1020 | 1030 |
    | lib/Application.php                   | 38  |         $this->setCatchExceptions(false);                                                                    | 1055 | 1073 |
    | lib/Application.php                   | 41  |             $this->container->get(LoggingExtension::SERVICE_LOGGER)->pushHandler(new StreamHandler(STDERR)); | 1138 | 1147 |
    | lib/Application.php                   | 59  |                 return $this->handleException($output, $input->getOption('format'), $e);                     | 1964 | 1979 |
    | lib/Application.php                   | 63  |                 $this->renderException($e, $output->getErrorOutput());                                       | 2122 | 2137 |
    | lib/Application.php                   | 70  |     protected function getDefaultInputDefinition()                                                           | 2249 | 2274 |
    | lib/Application.php                   | 78  |     private function handleException(OutputInterface $output, string $dumper, \Exception $e)                 | 2518 | 2533 |
    | lib/Application.php                   | 81  |             'error' => $this->serializeException($e),                                                        | 2646 | 2664 |
    | lib/Application.php                   | 86  |         $this->container->get('logging.logger')->error($e->getMessage());                                    | 2740 | 2749 |
    | lib/Application.php                   | 89  |             $errors['previous'][] = $this->serializeException($e);                                           | 2884 | 2902 |
    | lib/Application.php                   | 92  |         $this->container->get('console.dumper_registry')->get($dumper)->dump($output, $errors);              | 2934 | 2943 |
    | lib/Application.php                   | 97  |     private function serializeException(\Exception $e)                                                       | 3063 | 3081 |
    | lib/Application.php                   | 106 |     private function initialize(InputInterface $input)                                                       | 3277 | 3287 |
    | lib/Application.php                   | 108 |         $this->container = Phpactor::boot($input, $this->vendorDir);                                         | 3332 | 3341 |
    | lib/Application.php                   | 108 |         $this->container = Phpactor::boot($input, $this->vendorDir);                                         | 3374 | 3383 |
    | lib/Application.php                   | 110 |         $this->setCommandLoader($this->container->get(ConsoleExtension::SERVICE_COMMAND_LOADER));            | 3402 | 3418 |
    | lib/Application.php                   | 110 |         $this->setCommandLoader($this->container->get(ConsoleExtension::SERVICE_COMMAND_LOADER));            | 3426 | 3435 |
    | tests/Integration/ApplicationTest.php | 42  |         $application->setAutoExit(false);                                                                    | 1040 | 1051 |
    | tests/Integration/ApplicationTest.php | 43  |         $application->setCatchExceptions(false);                                                             | 1082 | 1100 |
    | tests/Integration/ApplicationTest.php | 44  |         $application->run(new ArrayInput([                                                                   | 1131 | 1134 |
    | tests/Integration/ApplicationTest.php | 56  |         $application->setAutoExit(false);                                                                    | 1447 | 1458 |
    | tests/Integration/ApplicationTest.php | 57  |         $application->run(new ArrayInput([                                                                   | 1489 | 1492 |
    | tests/Integration/ApplicationTest.php | 73  |         $application->setAutoExit(false);                                                                    | 1929 | 1940 |
    | tests/Integration/ApplicationTest.php | 74  |         $application->setCatchExceptions(false);                                                             | 1971 | 1989 |
    | tests/Integration/ApplicationTest.php | 75  |         $exitCode = $application->run(new ArrayInput([                                                       | 2032 | 2035 |
    +---------------------------------------+-----+--------------------------------------------------------------------------------------------------------------+------+------+
    
    30 reference(s), 43 risky references
    
    

    (i.e. member search without specifying the member) will currently find all the members of Phpactor\\Application in theory. But it is slow
    as we have to parse all the files in the project - if we pass the member name
    we can at least pre-filter. I guess it could possibly be optimized further
    though.

  2. kermorgant commented on Aug 24, 2019

    @kermorgant
    ContributorAuthor

    I've tried the cli and could reproduce my issue using fs composer like this (I can't paste the real example)

    phpactor references:member "\RandomService" "find" --filesystem=composer
    
    src/SomeRepository.php   xx   public function find(int $id): Object;
    src/RandomService.php    yy  $object = $this->repo->find(1);
    

    but using fs simple or git would fail on ClassToFileSourceLocator : Could not locate a candidate for someclass

    But anyway, when I run phpactor status, the detected filesystems are simple and composer, not git (probably because the project root from phpactor's perspective is a subfolder of the main project (which is using git))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions