drupal-check icon indicating copy to clipboard operation
drupal-check copied to clipboard

#280: allow custom configuration

Open Dropa opened this issue 2 years ago • 1 comments

Provides ability to create custom file like custom-phpstan.neon

# See https://phpstan.org/user-guide/ignoring-errors#generate-an-ignoreerrors-entry for formatting
parameters:
	ignoreErrors:
		- '#^Access to an undefined property Drupal\\Core\\Field\\FieldItemListInterface<Drupal\\Core\\Field\\FieldItemInterface>\:\:\$date\.$#'

and use it with

drupal-check -i custom-phpstan.neon web/modules/custom

Dropa avatar Aug 12 '22 15:08 Dropa

To clarify, the example can be reached two ways, either

$date = $entity->get('field_datefield')->date;

and ignore with

- '#^Access to an undefined property Drupal\\Core\\Field\\FieldItemListInterface<Drupal\\Core\\Field\\FieldItemInterface>\:\:\$date\.$#'

but it could make more sense to be precise when you accept the error, meaning the code would need to be

/** @var \Drupal\datetime\Plugin\Field\FieldType\DateTimeItem $dateField */
$dateField = $entity->get('field_datefield');
$date = $dateField->date;

and then ignore it with

- '#^Access to an undefined property Drupal\\datetime\\Plugin\\Field\\FieldType\\DateTimeItem\:\:\$date.#'

Dropa avatar Aug 18 '22 11:08 Dropa

Folks should be using PHPStan directly to overcome these issues.

mglaman avatar Mar 27 '23 21:03 mglaman

Could you elaborate? What exactly is drupal-check acceptable way of writing line

$date = $entity->get('field_datefield')->date;

There are a lot of cases where drupal-check prints out errors where you're really not doing anything wrong, such as implementing hooks where original API didn't specify variable types, calling method or property of known(/provided) field etc.

Also, drupal-check some times fails to load certain vendor module files, I assume that's because of different PSR, but once again, allowing custom phpstan rules (including given vendor files) to be added to the ones already provided nicely working solution.

Dropa avatar Mar 27 '23 22:03 Dropa

I closed this for the request of "allow custom configuration"

Can you open a discussion at https://github.com/mglaman/phpstan-drupal/discussions for ways to write:

$date = $entity->get('field_datefield')->date;

That way others can join in. There isn't one straight forward way.

You can always implement types in your hooks, it doesn't matter. And you should be doing so.

fails to load certain vendor module files

That is a bug you should open for phpstan-drupal, it's not drupal-check which is merely a wrapper.

mglaman avatar Mar 28 '23 13:03 mglaman