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