Page MenuHomePhabricator

FunctionCommentSniff fails on substr_compare
Closed, ResolvedPublic

Description

FILE: ...\CirrusSearch\includes\SearchConfig.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 1 | ERROR | An error occurred during processing; checking has been
   |       | aborted. The error message was: substr_compare(): The start
   |       | position cannot exceed initial string length in
   |       | \CirrusSearch\vendor\mediawiki\mediawiki-codesniffer\MediaWiki\Sniffs\Commenting\FunctionCommentSniff.php
   |       | on line 533 (Internal.Exception)
----------------------------------------------------------------------

Caused by https://gerrit.wikimedia.org/r/#/c/403940/3/MediaWiki/Sniffs/Commenting/FunctionCommentSniff.php

Code to sniff is possible:

	/** 
 	 * Get chain of elements from config array 
 	 * @param string $configName 
 	 * @param string ... list of path elements 
 	 * @return mixed Returns value or null if not present 
 	 */

Maybe just switch to a substr() ===

Related Objects

Event Timeline

Having a simple example like

	/**
	 * @param array $m
	 */
	public function match( $m ) {
	}

inside a unit test, it does not fail

Having it as part of a sniff class and running phpcs for it, it fails

The doc tests contains short params like $a, but why it does not fail on unit test?
Are unit tests not run with strict?

Change 411587 had a related patch set uploaded (by Umherirrender; owner: Umherirrender):
[mediawiki/tools/codesniffer@master] Replace substr_compare with substr

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

Umherirrender triaged this task as Medium priority.

Change 411587 merged by jenkins-bot:
[mediawiki/tools/codesniffer@master] Replace substr_compare with substr

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

I ran into this in a few other places, so I released 16.0.1.