14

I can't understand why PhpStorm gives me the following warning PHPDoc comment does not match function or method signature over this method:

/**
 * Create a new instance of the class
 * @param string $classname Class to instantiate
 * @return object the instance
 * @throw FactoryException If the class is not instantiable
 */
private function newInstance($classname) {
    $reflectionClass = new \ReflectionClass($classname);
    if (! $reflectionClass->isInstantiable()) {
        throw new FactoryException("The class $classname is not instantiable.");
    }
    return new $classname;
}

The warning isn't very specific, I've tried several things like changing the return type to "Object", "mixed" or even "int" (to try) but it didn't change. What is the problem here ?

0

3 Answers 3

12

It should be @throws not @throw.

If you just type /** over the line of a function or class var declaration it'll auto insert a base PHPDoc for you. That's how I noticed the difference.

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

I tried @throws but the warning is still there (I did the same as you did with typing /** but even the auto-generated docblock had the warning). Actually I have a beta version of PhpStorm 4.0, maybe it's just a bug?
Funky, yeah I'm using 4.0 as well.
@Matthieu 1) It definitely should be throws 2) There are few issues with current v4 EAP build (116.101) in this regard (I'm having the same). From what I see (based on your comments) this function is in class that extends another class or implements interface and this function overrides one in parent class/interface. If so -- please compare PHPDoc blocks for them -- even if 1 character is different (e.g. "Create a new instance ..." vs "Create new instance ...") PhpStorm will report such error.
New EAP build should be available later today or tomorrow .. but I do not expect this to be fixed there (at least based on related tickets statuses).
OK I'll go with a bug then, even though one this method there is no overriding, that is the cas for another method of this class (implementing an interface).
1

If this method happens to implement/override from a parent class where a docblock exists for it, see if your tags match across both. Normally, tags in the parent will be inherited by the child, such that if the parent's method docblock already has those same tags (param, return, throws), then it is not necessary to list them in the child's docblock, unless they specifically need to say something different than the parent's does.

1 Comment

That could be, but it's a private method ;), no overriding here
1

Please refer to this link https://blog.jetbrains.com/webide/2011/05/phpdoc-inspections/ It is mentioned there that "The inspection reports a problem if a number of parameters described in PHPDoc comment and/or their types do not match a corresponding function or method declaration"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.