{"id":97,"date":"2021-12-20T21:41:20","date_gmt":"2021-12-20T21:41:20","guid":{"rendered":"https:\/\/mrzebra.co.uk\/code\/?p=97"},"modified":"2021-12-20T21:43:16","modified_gmt":"2021-12-20T21:43:16","slug":"php-codesniffer-expected-boolean-but-found-bool","status":"publish","type":"post","link":"https:\/\/zebra-north.com\/code\/2021\/12\/20\/php-codesniffer-expected-boolean-but-found-bool\/","title":{"rendered":"PHP Codesniffer: Expected &#8220;boolean&#8221; but found &#8220;bool&#8221;"},"content":{"rendered":"\n<p>If you use the types <code>bool<\/code> or <code>int<\/code> in a function or variable documentation comment block, PHP Codesniffer will give you an error:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>Expected &quot;boolean&quot; but found &quot;bool&quot;<\/code><\/li><li><code>Expected &quot;integer&quot; but found &quot;int&quot;<\/code><\/li><\/ul>\n\n\n\n<p>Here&#8217;s a workaround!<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>I&#8217;ve created a composer package <a href=\"https:\/\/packagist.org\/packages\/zebra-north\/phpcs-short-types\">zebra-north\/phpcs-short-types<\/a> to work around the problem, allowing &#8220;bool&#8221; and &#8220;int&#8221; into the list of allowed types.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installation<\/h2>\n\n\n\n<p>You can install it using:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-bash\">composer require --dev zebra-north\/phpcs-short-types<\/code><\/pre>\n\n\n\n<p>To tell PHP Codesniffer to load the modification, edit your <code>phpcs.xml<\/code> configuration file to add an &#8220;arg&#8221; option:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-markup\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;ruleset&gt;\n\n    &lt;arg name=&quot;bootstrap&quot; value=&quot;vendor\/zebra-north\/phpcs-short-types\/short-types.php&quot;\/&gt;\n\n    ...\n\n&lt;\/ruleset&gt;<\/code><\/pre>\n\n\n\n<p>That&#8217;s all there is to it!<\/p>\n\n\n\n<p>You can view the project&#8217;s <a href=\"https:\/\/github.com\/ZebraNorth\/phpcs-short-types\">readme on GitHub<\/a> for more details.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you use the types bool or int in a function or variable documentation comment block, PHP Codesniffer will give you an error: Expected &quot;boolean&quot; but found &quot;bool&quot; Expected &quot;integer&quot; but found &quot;int&quot; Here&#8217;s a workaround!<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-97","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/zebra-north.com\/code\/wp-json\/wp\/v2\/posts\/97","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zebra-north.com\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zebra-north.com\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zebra-north.com\/code\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zebra-north.com\/code\/wp-json\/wp\/v2\/comments?post=97"}],"version-history":[{"count":3,"href":"https:\/\/zebra-north.com\/code\/wp-json\/wp\/v2\/posts\/97\/revisions"}],"predecessor-version":[{"id":100,"href":"https:\/\/zebra-north.com\/code\/wp-json\/wp\/v2\/posts\/97\/revisions\/100"}],"wp:attachment":[{"href":"https:\/\/zebra-north.com\/code\/wp-json\/wp\/v2\/media?parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zebra-north.com\/code\/wp-json\/wp\/v2\/categories?post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zebra-north.com\/code\/wp-json\/wp\/v2\/tags?post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}