If an indexed array contains only primitive types it can be declared as e.g. int[], string[], etc. The sniff that checks for non-matching type hints triggers erroneously for such types.

Comments

klausi’s picture

Status: Active » Postponed (maintainer needs more info)

Could you provide a test snippet to reproduce this?

psynaptic’s picture

Certainly! Here you go:

$ cat test.php
<?php

/**
 * @file
 * Something something.
 */

/**
 * Does foo blah.
 *
 * @param string[] $names
 *   An indexed array of names.
 */
function foo($names) {
}
$ phpcs --standard=/Users/psynaptic/src/drupal/coder/coder_sniffer/Drupal --extensions=php,inc,test,engine,install,module,profile,theme -- ./test.php

FILE: /Users/psynaptic/src/drupal/coder/test.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 14 | ERROR | Type hint "string[]" missing for $names
--------------------------------------------------------------------------------

Time: 47ms; Memory: 4.5Mb

Apologies for not providing one with the initial report.

psynaptic’s picture

Uploaded the file since the code snippet is missing newlines.

psynaptic’s picture

Forgot to include the correct type hint example too:

$ cat test.php
<?php

/**
 * @file
 * Something something.
 */

/**
 * Does foo blah.
 *
 * @param string[] $names
 *   An indexed array of names.
 */
function foo(array $names) {
}
$ phpcs --standard=/Users/psynaptic/src/drupal/coder/coder_sniffer/Drupal --extensions=php,inc,test,engine,install,module,profile,theme -- ./2279123-phpcs-compound-primitive-data-type-hints.php.txt

FILE: ...c/drupal/coder/2279123-phpcs-compound-primitive-data-type-hints.php.txt
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 14 | ERROR | Expected type hint "string[]"; found "array" for $names
--------------------------------------------------------------------------------

Time: 47ms; Memory: 4.5Mb
psynaptic’s picture

Status: Postponed (maintainer needs more info) » Active

  • klausi committed db8321e on
    Issue #2279123 by klausi, psynaptic: Fixed array bracket notation...
klausi’s picture

Status: Active » Fixed

Fixed, thanks for reporting!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.