Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does PhpStorm allow to skip PHPDoc tags when type hints is declared?

I use PHP strict types declare(strict_types=1); and declare types through the project. Also I have enabled PHPDoc inspections in PhpStorm such as Argument PHPDoc missing, Missing @return tag and others. I want PhpStorm not showing warnings regarding PHPDoc when I have explicit return type and parameter type declarations.

Here is valid the sample code in terms of PhpStorm.

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws DBALException
     */
    public function find(Request $request): JsonResponse
    {
        $user = $this->repository->find($request->get('id'));
        if (!$user) {
            throw new NotFoundHttpException();
        }
        return $this->json($user);
    }

As we can see, I have explicit parameter type Request $request and return type : JsonResponse declarations, so there is no need to duplicate them in PHPDoc.

I want to exclude this lines from PHPDoc

    /**
     * @param Request $request
     * @return JsonResponse
     */

without warnings from PhpStorm, but only in case I have declared type hints. Nonetheless I want to see warnings when my code doesn't have type hints.

Is it possible to achieve? If no, does some JetBrains ticket exists or is there some plugins/tools to cover my case?

like image 380
Spartak Avatar asked Aug 17 '19 00:08

Spartak


1 Answers

Post answer by myself.

It turned out there are configuration options for PHP inspections (version of PHPStorm 2019.2):

  • Ignore PHPDoc with return type hint (disabled by default)
  • Allow missing parameters with type hints (disabled by default)

Screenshot of Inspections configuration

like image 59
Spartak Avatar answered Oct 16 '22 14:10

Spartak