Search code examples
phpsymfonynetbeansphpdoccode-completion

Code Completion When Using Factory Class


I am using Netbeans 8 for a Symfony2 project.
I have created a factory class for my model queries (they are static calls and mess up testing).
E.g

<?php
namespace My\Custom\Bundle\Classes\Factories;

use My\Custom\Bundle\Model\UserQuery;

class QueryFactory
{
    /**
     * Class name
     * @access public
     */
    const CLASS_NAME = __CLASS__;

    /**
     * newUserQuery()
     *
     * Creates a new user query object.
     * @access public
     * @return My\Custom\Bundle\Model\UserQuery
     */
    public function newUserQuery()
    {
        return UserQuery::create();
    }
}

What I want is for the auto complete to work on a variable that is created from a factory method (in this case the Propel methods for the User query).

<?php
namespace My\Custom\Bundle\Controller;

use My\Custom\Bundle\Classes\Factories\QueryFactory;

class ReportingController
{
    private $queryFactory;

    public function __construct(QueryFactory $query_factory)
    {
        $this->queryFactory = $query_factory;
    }

    public function fubar()
    {
        $user = $this->queryFactory->newUserQuery();
        // now want auto complete on the $user (in this case the propel methods)
        // $user->filterById(1);
    }
}

Any ideas?


Solution

  • I think the problem is @return pointing to My\Custom\Bundle\Classes\Factories\My\Custom\Bundle\Model\UserQuery

    try changing it to this

    /**
    * ...
    * @return UserQuery
    */
    

    Without the use statement it should be like this

    /**
     * ...
     * @return \My\Custom\Bundle\Model\UserQuery
     */