coding-standard icon indicating copy to clipboard operation
coding-standard copied to clipboard

Coding standard does not specify negation formatting

Open mhujer opened this issue 7 years ago • 3 comments

Currently the negation formatting is not explicitly specified in the standard.

It can be written either:

  • with no spaces if (!is_array($foo))
  • with space after if (! is_array($foo))
  • with spaces around if ( ! is_array($foo))

In the Scalar types chapter there is a code example which includes negation formatted without spaces around:

<?php

if (!is_int($foo)) {
	return (int) $foo;
}

So it would be nice to have it explicitly stated in the coding standard. Maybe eventually also checked automatically (but PHP_CodeSniffer currently offers only SpaceAfterNotSniff).

mhujer avatar Aug 22 '18 07:08 mhujer

Thanks for the suggestion, I will add it in next major version (to not break versioning) in the format stated in the code example.

VasekPurchart avatar Aug 27 '18 11:08 VasekPurchart

It is now possible to check this with PHPCS>=3.4 https://github.com/squizlabs/PHP_CodeSniffer/pull/2233

mhujer avatar Dec 21 '18 08:12 mhujer

Yes, I noticed, already have it in my notes :)

VasekPurchart avatar Dec 21 '18 08:12 VasekPurchart