djoos / Symfony-coding-standard

Development repository for the Symfony coding standard
MIT License
402 stars 102 forks source link

Symfony.Object.ObjectInstantiation.Invalid on variable #147

Closed brianfreytag closed 5 years ago

brianfreytag commented 5 years ago

Symfony.Object.ObjectInstantiation.Invalid does not seem to be working for me when the class is in the form of a variable.

For example, I have a class that instantiates with $class as a string.

abstract class AbstractClass
{
    /** @var string */
    protected $class;

    public function __construct($class)
    {
        $this->class = $class;
    }

    public function create()
    {
        return new $this->class();
    }
}

Historically, I would have just done return new $this->class; but due to this rule, I try to add () to it, but it's still returning an error.

Is this a bug or am I just not doing this right?

mmoll commented 5 years ago

This should be fixed in more recent versions now.

brianfreytag commented 5 years ago

@mmoll Thanks... 9 months later ;)

Honestly, thanks for looking into it. I'll go ahead and close this out and assume it works.