Autocomplete phpstorm for Codeigniter

1

I have the need for phpstorm to recognize methods of classes that I have previously stored in an array. I have searched in various forums and I can not find a solution to this situation that becomes tedious when the number of classes grows considerably. I will try to show a graphic example that is as illustrative as possible.

<?php namespace App\Factory;

use App\Bo\PerfilDocumental;

class PerfilDocumentalCollection
{
    private $collection;

   /**
    * @return PerfilDocumentalCollection
    */
   public function getCollection()
   {
       return $this->collection;
   }

   /**
    * @param PerfilDocumental $perfilDocumental
    */
   public function setCollection(PerfilDocumental $perfilDocumental)
   {
      $this->collection[] = $perfilDocumental;
   }


}

As of this class, I am storing instances of the DocumentType class. The problem with phpstorm I have when I try to access the methods (getters / setters) of the latter in the iterations of the collection.

        $collection = new PerfilDocumentalCollection();
        foreach ( $rows AS $row )
        {
            $perfil = new PerfilDocumentalFactory();
            $collection->setCollection($perfil->get_instance($row));
        }

        foreach ( $collection->getCollection() AS $key => $obj )
        {
            echo "Creado por: " . $obj->getCreatedBy()->getNom() . " el " . $obj->getCreatedAtWeb()."<br>";
            echo "Actualitzado por: " . $obj->getUpdatedBy()->getNom() . " el " . $obj->getUpdatedAtWeb()."<br>";
        } 

That is, inside the second foreach block I try to access the getCreatedBy (), etc methods of the instance of the DocumentType class (variable $ obj), but phpstorm does not suggest anything in the step:

        foreach ( $collection->getCollection() AS $key => $obj )
        {
            echo $obj->.......   

Thank you very much in advance

    
asked by Salvador Mata 07.02.2017 в 21:53
source

1 answer

1

Greetings to everyone,

I have finally achieved what I expected and it has been easier than I thought (I came to think that you could not) ....

By adding a single comment line, phpstorm understands what the developer needs and the autocomplete is activated immediately.

/ * @var $ variable_of_object Object_name_of_object * / With this single line, the autocomplete is activated in the IDE

        /* @var $obj PerfilDocumental */
        foreach ( $collection->getCollection() AS $obj )
        {
            echo "Creado por: " . $obj->getCreatedBy()->getNom() . " el " . $obj->getCreatedAtWeb()."<br>";
            echo "Actualitzado por: " . $obj->getUpdatedBy()->getNom() . " el " . $obj->getUpdatedAtWeb()."<br>";
            echo "<p>&nbsp;</p>";
        }

I hope you find it useful.

    
answered by 11.02.2017 в 12:11