Scenario
I need to check if my $type_id
variable is one of a certain set of IDs.
For no reason other than readability, I went with
switch($type_id) {
case Type::SOME_TYPE:
case Type::SOME_OTHER_TYPE:
...
//do stuff
where most of them cascade down to a common case.
But this increases the cyclomatic complexity to the point where PHPMD starts whining.
So I figured, let's 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 isn't the cyclomatic complexity still there, just hidden behind the in_array()
function?