phpcs-cognitive-complexity icon indicating copy to clipboard operation
phpcs-cognitive-complexity copied to clipboard

do while calculation

Open bkdotcom opened this issue 3 years ago • 2 comments

sniff calculates this to be 7 codeclimate.com calculates it to be 5 (I think) I think it should be 6 ??

public function doWhile()
{
    if (true) {         // 1
        $val = true    // 2
            ? 'foo'
            : 'bar';
    }
    do {                   //  nesting inc
        if (true) {        // 2
            break;
        }
    } while (false);    // 1
}

do {} while(); should have the same complexity as a while() {}

If we agree the value should be 6, I can add and new test to my PR

bkdotcom avatar Oct 27 '21 04:10 bkdotcom

Yes, while and do while should behave same according to spec.

More granular with PRs, please. I'd rather deal with small focused ones, since this is not a code I am actively working with day to day. :)

Rarst avatar Oct 27 '21 08:10 Rarst

👍 simply need to remove T_DO from the increments const T_WHILE has it covered

bkdotcom avatar Oct 27 '21 12:10 bkdotcom