0

I have to find the CFG and complexity for this code, but I'm kind of confused by conflicting results. Would appreciate some opinions and help if possible. Here's the code snippet:

public function checkCredentials() { // 0

if (username.length < 5 || username.length > 15) { // 1
    return; // 2
}

if (password.length < 5 || password.length > 12) { // 3
    return; // 4
}

foreach(users as user) { // 5
    if (user.username === username) { // 6
        return; // 7
    }
}

if (phonenumber.length < 7) { // 8
    return; // 9
}

And here's the Control Flow Graph I have come up with..

enter image description here

Is the Control Flow Graph accurate? If so - what's the Cyclomatic Complexity? Sometimes I think it's 4. But when I count the edges - nodes + 2 - it's a separate story.

Would really appreciate some clearance here. Thank you.

VenoM
  • 453
  • 3
  • 9
  • 17

0 Answers0