Differences in cyclic complexity between switch / cases and in_array

Scenario

I need to check if my variable is $type_idone of a specific set of identifiers.

For some reason, besides readability, I went with

switch($type_id) {
    case Type::SOME_TYPE:
    case Type::SOME_OTHER_TYPE:
    ...
        //do stuff

where most of them cascade to the general case.

But this increases the cyclic complexity to the point where PHPMD starts to whine.

So, I decided that just use in_array()instead.

if (in_array($type_id, [
    Type::SOME_TYPE,
    TYPE::SOME_OTHER_TYPE,
    ...
    ])) {
    //do stuff
}

Question

At this point, PHPMD stops complaining, but is it still cyclical complexity hidden only by the function in_array()?

+4
source share
1 answer

. PHPMD CC /. CC call-. , PHPMD CC, .

: .

+3

Source: https://habr.com/ru/post/1687777/


All Articles