Problem/Motivation

Follow up from #3565604: Remove an unnecessary isset() from Renderer::doRender()

PHPStan level 1 reports 47 isset.variable violations.

Variable $foo in isset() always exists and is not nullable.

I suspect they are all fairly simple to fix.

Steps to reproduce

Violation count:

$ grep 'isset.variable' core/.phpstan-baseline.php | wc -l
47

Violation list:

grep 'isset.variable' core/.phpstan-baseline.php -B2 -A3

But this doesn't give you the actual line numbers, that requires removing the violations from the baseline and rescanning:

# Clear the baseline
$ rm core/.phpstan-baseline.php && echo "<?php return [];" > core/.phpstan-baseline.php
# Run phpstan and grep for the error
$ ./vendor/bin/phpstan analyse -c core/phpstan.neon.dist --error-format=raw \
  | sed "s|$PWD|.|g" \
  | grep -F 'isset() always exists and is not nullable'
# Reset the baseline
$ git checkout main core/.phpstan-baseline.php

I've attached the output to this issue.

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
isset-variable.txt7.5 KBmstrelan

Issue fork drupal-3569099

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mstrelan created an issue. See original summary.

mstrelan’s picture

I was going to tag this as novice, but I don't think they are necessarily all straightforward. For example, \Drupal\Core\Config\Entity\Query\Condition::match calls isset($value), which is documented as a string, but since it is not strictly typed, it could be null. It would make sense to update the typehint from string to string|null.

skifdesu made their first commit to this issue’s fork.

nitinkumar_7’s picture

Assigned: Unassigned » nitinkumar_7
skifdesu’s picture

Assigned: nitinkumar_7 » skifdesu
Status: Active » Needs review

Added MR which fixes all isset.variable PHPStan violations.

nitinkumar_7’s picture

Tested the MR !16013 and the full CI pipeline shows Job succeeded with no errors. All isset.variable PHPStan violations appear to be correctly fixed. No issues found.