Scenario
I need to check if my variable is $type_id
one 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:
...
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,
...
])) {
}
Question
At this point, PHPMD stops complaining, but is it still cyclical complexity hidden only by the function in_array()
?
source
share