Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get a PHPDoc warning in PhpStorm over this code

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 ?

like image 979
Matthieu Napoli Avatar asked Mar 22 '12 13:03

Matthieu Napoli


People also ask

What is PHPDoc in PhpStorm?

Using PHPDoc code inspections PhpStorm provides a set of predefined code inspections targeted at PHPDoc blocks. These inspections check whether classes, methods, functions, variables, and constants are supplied with a PHPDoc comment and whether the tags in the comment match the documented item.

What is PHPDoc comment?

phpDoc blocks are descriptive comments that are part of the application code. They are used to describe the PHP element in the exact location in the code where the element appears. The block consists of a short description, long description, and phpDoc tags.

What language does PhpStorm use?

Supported languages With PhpStorm, you can develop applications in PHP 5.3, PHP 5.4, PHP 5.5, PHP 5.6, PHP 7, PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, and PHP 8.1.

What is PhpStorm used for?

PhpStorm provides tools and code assistance features for working with databases and SQL in your projects. Connect to databases, edit schemas and table data, run queries, and even analyze schemas with UML diagrams.


Video Answer


1 Answers

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

like image 144
MetalFrog Avatar answered Oct 25 '22 00:10

MetalFrog