private function buildTree(string $class): void
    {
        $level = 0;
        $stack = new SplStack();

        while (true) {

            //initialize array if not already initialized
            if (empty($this->tree[$level][$class])) {
                $this->tree[$level][$class] = [];
            }

            //get parameter from constructor
            //can return error when constructor not declared
            $parameters = (new ReflectionClass($class))->getConstructor()->getParameters();

            //loop parameter
            foreach ($parameters as $param) {

                //check if argument is already stored
                $notAlreadyStored = !\in_array($param, $this->tree[$level][$class]);

                //if there is parameter with callable type
                if (\class_exists((string) $param->getType()) && $notAlreadyStored) {

                    //push values in stack for simulate later recursive function
                    $stack->push([$level, $class]);

                    //store dependency
                    $this->tree[$level][$class][] = $param;

                    //update values for simulate recursive function
                    $level++;
                    $class = $param->getClass()->name;

                    //return to main while
                    continue 2;
                }

                if ($notAlreadyStored) {
                    //store dependency
                    $this->tree[$level][$class][] = $param;
                }
            }

            //if stack is empty break while end exit from function
            if ($stack->count() === 0) {
                break;
            }

            //get last value pushed into stack;
            list($level, $class) = $stack->pop();
        }
    }
private function buildTree(string $class): void
    {
        $level = 0;
        $stack = new SplStack();

        while (true) {

            //initialize array if not already initialized
            if (empty($this->tree[$level][$class])) {
                $this->tree[$level][$class] = [];
            }

            //get parameter from constructor
            //can return error when constructor not declared
            $parameters = (new ReflectionClass($class))->getConstructor()->getParameters();

            //loop parameter
            foreach ($parameters as $param) {

                //check if argument is already stored
                $notAlreadyStored = !\in_array($param, $this->tree[$level][$class]);

                //if there is parameter with callable type
                if (\class_exists((string) $param->getType()) && $notAlreadyStored) {

                    //push values in stack for simulate later recursive function
                    $stack->push([$level, $class]);

                    //store dependency
                    $this->tree[$level][$class][] = $param;

                    //update values for simulate recursive function
                    $level++;
                    $class = $param->getClass()->name;

                    //return to main while
                    continue 2;
                }

                if ($notAlreadyStored) {
                    //store dependency
                    $this->tree[$level][$class][] = $param;
                }
            }

            //if stack is empty break while end exit from function
            if ($stack->count() === 0) {
                break;
            }

            //get last value pushed into stack;
            list($level, $class) = $stack->pop();
        }
    }
private function buildTree ( string $ class ) : void { $ level = 0 ; $ stack = new SplStack ( ) ; while ( true ) { //initialize array if not already initialized if ( empty ( $ this -> tree [ $ level ] [ $ class ] ) ) { $ this -> tree [ $ level ] [ $ class ] = [ ] ; } //get parameter from constructor //can return error when constructor not declared $ parameters = ( new ReflectionClass ( $ class ) ) -> getConstructor ( ) -> getParameters ( ) ; //loop parameter foreach ( $ parameters as $ param ) { //check if argument is already stored $ notAlreadyStored = ! \ in_array ( $ param , $ this -> tree [ $ level ] [ $ class ] ) ; //if there is parameter with callable type if ( \ class_exists ( ( string ) $ param -> getType ( ) ) && $ notAlreadyStored ) { //push values in stack for simulate later recursive function $ stack -> push ( [ $ level , $ class ] ) ; //store dependency $ this -> tree [ $ level ] [ $ class ] [ ] = $ param ; //update values for simulate recursive function $ level ++ ; $ class = $ param -> getClass ( ) -> name ; //return to main while continue 2 ; } if ( $ notAlreadyStored ) { //store dependency $ this -> tree [ $ level ] [ $ class ] [ ] = $ param ; } } //if stack is empty break while end exit from function if ( $ stack -> count ( ) === 0 ) { break ; } //get last value pushed into stack; list ( $ level , $ class ) = $ stack -> pop ( ) ; } }
Create a dependencies map for a class.

@param string $class

@return void
Create a dependencies map for a class .