Page MenuHomePhabricator

NoEmptyIfDefinedPlugin does not report use of empty() on function call to check the return value
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • When using mediawiki/mediawiki-phan-config with version 0.13.0 on the Vector skin I would expect the following code to emit a issue about the use of empty()
SkinVector22.php
	private function canHaveLanguages(): bool {
		$action = $this->getContext()->getActionName();

		// FIXME: This logic should be moved into the ULS extension or core given the button is hidden,
		// it should not be rendered, short term fix for T328996.
		if ( $action === 'history' ) {
			return false;
		}

		$title = $this->getTitle();
		// Defensive programming - if a special page has added languages explicitly, best to show it.
		if ( $title && $title->isSpecialPage() && empty( $this->getLanguagesCached() ) ) {   # <!--- not reported
			return false;
		}
		return true;
	}

What happens?:
No warning, it seems the new plugin (from T234237) has a focus on variables/class properties.

What should have happened instead?:
Expected message:

Found usage of empty() on expression $this->getLanguagesCached() that is always set. empty() should only be used to suppress errors. See https://w.wiki/6paE

Event Timeline

Change 967670 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/tools/phan@master] Make NoEmptyIfDefinedPlugin check all node types except AST_DIM

https://gerrit.wikimedia.org/r/967670

This was a deliberate choice to try and start with something simple. With the patch above we will check all node types except for array index access.

Change 967670 merged by jenkins-bot:

[mediawiki/tools/phan@master] Make NoEmptyIfDefinedPlugin check all node types except AST_DIM

https://gerrit.wikimedia.org/r/967670