chim
chim

Reputation: 8573

Is there an annotation to turn off an inspection for a file in PHPStorm?

In view templates, I'm seeing a lot of warnings to do with undefined fields on objects and undefined variables. I want to disable them.

Upvotes: 2

Views: 1031

Answers (1)

LazyOne
LazyOne

Reputation: 165471

You can provide type hints via standard PHPDoc comments -- just place such block at the top of the file and declare all variables used so they will be recognized and offered in code completion (yes, you can provide type hint for $this this way as well):

<?php
/** @var \My\ViewRendererClass $this */
/** @var string $abcd */
...
?>
<div class="container">
...

In case if you actually need to disable certain inspection in whole file (or bunch of files) -- do this at Scope/Inspection level:

  1. Create new Scope (Settings/Preferences | Appearance & Behaviour | Scopes) and include all such files
  2. In Settings/Preferences | Editor | Inspections find desired inspection and add new rule for that scope, e.g. disable for that scope but enabled in all other places.

Upvotes: 3

Related Questions