Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show usage of dynamic generated callable function name

Is there any possibility in PhpStorm to map the usage of dynamically generated functions between its declaration and usage?

Assume I have the next code:

<?php

class TestExample {
    
    public function __construct($component) {
        $component_parts = $this->get_dynamic_component_part_list($component);
        $this->load_component_parts($component, $component_parts);
    }

    private function get_dynamic_component_part_list($component){
        //Complex logic to get attached parts by $component
        $component_parts = array('part1', 'part2');
        return $component_parts;
    }

    private function load_component_parts(&$component, $component_parts) {
        foreach ($component_parts as $component_part) {
            $component[$component_part] = $this->{'load_' . $component_part}($component['id']);
        }
    }

    private function load_part1($id) {
        //Loading and prepare condition from one source 
        $part1 = new Part1($id);
        // Complex algorithm
        return $part1;
    }

    private function load_part2($id) {
        //Loading and prepare condition from another source 
        $part2 = new Part2($id);
        // Complex algorithm
        return $part2;
    }
}

class Part1 {
    
} 

class Part2 {

} 

I want to see usage of load_part1 and load_part2.

Is there any way to do it by usage phpDoc or in some other way?

At this moment PhpStorm notice me that this function doesn't have usage, but really it used in load_component_parts method.

enter image description here

like image 681
Pavlo Zhukov Avatar asked Oct 16 '25 07:10

Pavlo Zhukov


1 Answers

You can use the phpDoc annotation @see.

For example:

$className = 'SomeClass';
$method = 'methodToCall';
$anArgument = 'bar';

/** @see SomeClass::someMethod() */
$foo = call_user_func([$className, $method], $anArgument);

This annotation will create at least a reference to this code, so that you know to come back here when you review SomeClass::someMethod() before throwing the "unused" method away.

like image 172
Sneakyvv Avatar answered Oct 18 '25 06:10

Sneakyvv