Zebra Codes

PHP Codesniffer: Expected “boolean” but found “bool”

20th of December, 2021
PHP

If you use the types bool or int in a function or variable documentation comment block, PHP Codesniffer will give you an error:

  • Expected "boolean" but found "bool"
  • Expected "integer" but found "int"

Here’s a workaround!

I’ve created a composer package zebra-north/phpcs-short-types to work around the problem, allowing “bool” and “int” into the list of allowed types.

Installation

You can install it using:

composer require --dev zebra-north/phpcs-short-types

To tell PHP Codesniffer to load the modification, edit your phpcs.xml configuration file to add an “arg” option:

<?xml version="1.0"?>
<ruleset>

    <arg name="bootstrap" value="vendor/zebra-north/phpcs-short-types/short-types.php"/>

    ...

</ruleset>

That’s all there is to it!

You can view the project’s readme on GitHub for more details.