Re: Re: About PHPCodeSniffer 1.3.0RC2 and IF multi-lines check
| From: | Greg Sherwood | Date: | Mon, 07 Feb 2011 05:36:22 +0000 |
| Subject: | Re: Re: About PHPCodeSniffer 1.3.0RC2 and IF multi-lines check | ||
| References: | 1 2 3 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-54070@lists.php.net to get a copy of this message | ||
I'm sure you can find nice ways of writing these examples to make them a little easier to read
:) Otherwise, live with slightly longer lines I guess.
I'm just enforcing the standard, which may need some flexibility at times. But it's also
fairly easy to change the way you write code to keep it short and tidy. I'm not a massive fan
of multi-line IF statements myself, but I (of course) use them when things get complicated and
I've decided to adopt the PEAR standard of having boolean ops out front in my other projects. I
think it looks clean and is easy to follow because each decision is on a single line. If the
decision doesn't fit on a single line, then maybe it's just too complex.
By the way, the standard is here [1] and does actually touch on the point of what happens if the
condition itself is too long. It suggests assigning them to variables, as you did in your preg_match
example. So I think my own personal preference, and the work-around you came up with, seem to align
with the documented standard.
[1] http://pear.php.net/manual/en/standards.control.php
Greg
On 05/02/2011, at 8:11 PM, Laurent Laville wrote:
> In the same category
>
> > ERROR | Each line in a multi-line IF statement must begin with a
> > | boolean operator
>
> We have :
>
> <code>
> if ($fileinfo->getMTime() <=
> (time() - $this->options['gc_maxlifetime'])
> ) {
> unlink($fileinfo->getPathname());
> }
> </code>
>
>
> Le 05/02/2011 09:42, Laurent Laville a écrit :
>> Check of IF multi-lines detect also the same error
>>
>> ERROR | Each line in a multi-line IF statement must begin with a
>> | boolean operator
>>
>> for
>>
>> <code>
>>
>> if (!$reference
>> instanceof PHP_CompatInfo_Reference_PluginsAbstract
>> ) {
>> // ....
>> }
>> </code>
>>
>> Laurent
>>
>> Le 04/02/2011 20:42, Laurent Laville a écrit :
>>> Hello Greg,
>>>
>>> I don't know if you've already noticed this issue, and as I didn't find
>>> it on the PEAR bug tracker, I ask it here.
>>>
>>> While I giving a clean-up to my PHP_CompatInfo v2 code, I got this case
>>>
>>> Look at Lines 691 - 696 of
>>>
>>> https://github.com/llaville/php-compat-info/blob/master/PHP/CompatInfo.php
>>>
>>>
>>>
>>> A preg_match on a multi-line to respect the 85 characters limit.
>>>
>>> I got these error as it was a IF with boolean conditions
>>>
>>> ERROR | Each line in a multi-line IF statement must begin with a
>>> | boolean operator
>>>
>>> Is it possible to FIX it ?
>>>
>>> I used 1.3.0RC2 version of Code Sniffer
>>>
>>> BTW, I think you can close my request [1] since it's now part of 1.3.0RC2
>>>
>>> Thanks
>>> Laurent
>>>
>>> [1] http://pear.php.net/bugs/bug.php?id=18094
>>
>
>
> --
> PEAR Development Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Greg Sherwood
Product Development Manager
E gsherwood@squiz.com.au
Squiz Australia Pty. Ltd. A 92 Jarrett Street, Leichhardt NSW 2040
P +61 2 8507 9900 F +61 2 8507 9988 SUPPORT 13000 SQUIZ W www.squiz.com.au
AUSTRALIA UNITED KINGDOM NEW ZEALAND EUROPE UNITED STATES
SYDNEY MELBOURNE CANBERRA HOBART BRISBANE
SUPPORTED OPEN SOURCE SOLUTIONS