Search code examples
interfacephpstormtraitsphp-7

PhpStorm: variable member visibility with class, based on interface and trait


I'm working with a simple setup for API provider traits. Each provider works off of a trait and a interface, declaring functionality and required functions, as per the PHP documentation on both respective declarations.

My PhpStorm clearly indexes the interfaces and traits functions, but doesn't index the variable members. I've declared them public, protected or private -- nothing seems to work. They clearly work in the PHP7 environment, but my PhpStorm thinks I've declared them dynamically.

Basically, this is my setup.

interface ProviderInterface
{

    const TYPE_ELECTRICITY = 'electricity';

    const TYPE_GAS = 'gas';

    /**
     * @param ContainerInterface $container
     *
     * @return void
     */
    function setContainer(ContainerInterface $container);

    /**
     * @return Client|\SoapClient
     */
    function client();

}

trait ProviderTrait
{

    /**
     * @var string
     */
    private $endpoint = '';


    public function setContainer($container) {
        /** void for demo purposes */
    }
}


class Provider implements ProviderInterface
{

    use ProviderTrait;

    /**
     * @var string
     */
    private $username;

    /**
     * @var string
     */
    private $password;

    /**
     * constructor.
     *
     * @param ContainerInterface $container
     */
    final public function __construct(ContainerInterface $container)
    {
        $this->setContainer($container);

        /**
         * While $username and $password are declared within this class, the $endpoint is declared in the ProviderTrait. PHP works fine. PhpStorm ignores it and says it is declared "dynamically".
         */
        $this->endpoint = $this->container->getParameter('api.endpoint');
        $this->username = $this->container->getParameter('api.username');
        $this->password = $this->container->getParameter('api.password');
    }

Trait variable member declared dynamically

I've tried clearing the cache ("Invalidate & Restart") but after a index the same occurs.

Anyone got an idea?


Solution

  • I wasn't aware that there was a new minor version available. Updated to the following version fixed my problem completely.

    PhpStorm 2017.2.2
    Build #PS-172.3968.35, built on August 31, 2017
    JRE: 1.8.0_152-release-915-b11 amd64
    JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
    Windows 10 10.0
    

    Symfony plugin version 0.14.151 PHP Annotations version 5.1

    Completely fixed! Thanks @LazyOne for pointing me in the right direction.

    Reference issue @ JetBrains: https://youtrack.jetbrains.com/issue/WI-36285