payload: {"action":"created","issue":{"url":"https://api.github.com/repos/phpmd/phpmd/issues/282","repository_url":"https://api.github.com/repos/phpmd/phpmd","labels_url":"https://api.github.com/repos/phpmd/phpmd/issues/282/labels{/name}","comments_url":"https://api.github.com/repos/phpmd/phpmd/issues/282/comments","events_url":"https://api.github.com/repos/phpmd/phpmd/issues/282/events","html_url":"https://github.com/phpmd/phpmd/issues/282","id":76961867,"node_id":"MDU6SXNzdWU3Njk2MTg2Nw==","number":282,"title":"NPath complexity are increased after \"else\" branch was removed and \"return\" statement was added","user":{"login":"EvgenyUnvsoft","id":6170386,"node_id":"MDQ6VXNlcjYxNzAzODY=","avatar_url":"https://avatars3.githubusercontent.com/u/6170386?v=4","gravatar_id":"","url":"https://api.github.com/users/EvgenyUnvsoft","html_url":"https://github.com/EvgenyUnvsoft","followers_url":"https://api.github.com/users/EvgenyUnvsoft/followers","following_url":"https://api.github.com/users/EvgenyUnvsoft/following{/other_user}","gists_url":"https://api.github.com/users/EvgenyUnvsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/EvgenyUnvsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EvgenyUnvsoft/subscriptions","organizations_url":"https://api.github.com/users/EvgenyUnvsoft/orgs","repos_url":"https://api.github.com/users/EvgenyUnvsoft/repos","events_url":"https://api.github.com/users/EvgenyUnvsoft/events{/privacy}","received_events_url":"https://api.github.com/users/EvgenyUnvsoft/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/phpmd/phpmd/milestones/22","html_url":"https://github.com/phpmd/phpmd/milestone/22","labels_url":"https://api.github.com/repos/phpmd/phpmd/milestones/22/labels","id":1852530,"node_id":"MDk6TWlsZXN0b25lMTg1MjUzMA==","number":22,"title":"2.6.0","description":"","creator":{"login":"ravage84","id":625761,"node_id":"MDQ6VXNlcjYyNTc2MQ==","avatar_url":"https://avatars1.githubusercontent.com/u/625761?v=4","gravatar_id":"","url":"https://api.github.com/users/ravage84","html_url":"https://github.com/ravage84","followers_url":"https://api.github.com/users/ravage84/followers","following_url":"https://api.github.com/users/ravage84/following{/other_user}","gists_url":"https://api.github.com/users/ravage84/gists{/gist_id}","starred_url":"https://api.github.com/users/ravage84/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ravage84/subscriptions","organizations_url":"https://api.github.com/users/ravage84/orgs","repos_url":"https://api.github.com/users/ravage84/repos","events_url":"https://api.github.com/users/ravage84/events{/privacy}","received_events_url":"https://api.github.com/users/ravage84/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":36,"state":"closed","created_at":"2016-06-28T11:36:24Z","updated_at":"2017-01-30T16:12:12Z","due_on":null,"closed_at":"2017-01-30T16:12:12Z"},"comments":4,"created_at":"2015-05-16T06:34:04Z","updated_at":"2020-01-10T16:19:08Z","closed_at":"2016-06-15T05:58:19Z","author_association":"NONE","body":"First example\n\n```\nfunction Test($a, $b)\n{\n    if ($a > $b) {\n        $result = $a;\n    } else {\n        if ($a > 5) {\n            $result = 6;\n        } else {\n            $result = 4\n        }\n    }\n\n    return $result;\n}\n```\n\nFor this function PHPMD return NPath complexity 3.\n\nMake some changes - remove \"else\" branches and add return statement to the if branches.\n\n```\nfunction Test($a, $b)\n{\n    if ($a > $b) {\n        $result = $a;\n\n        return $result;\n    }\n\n    if ($a > 5) {\n        $result = 6;\n\n        return $result;\n    }\n\n    $result = 4\n\n    return $result;\n}\n```\n\nFor this function PHPMD return NPath complexity 4.\n\nWhy NPath complexity increased?\n"},"comment":{"url":"https://api.github.com/repos/phpmd/phpmd/issues/comments/573102152","html_url":"https://github.com/phpmd/phpmd/issues/282#issuecomment-573102152","issue_url":"https://api.github.com/repos/phpmd/phpmd/issues/282","id":573102152,"node_id":"MDEyOklzc3VlQ29tbWVudDU3MzEwMjE1Mg==","user":{"login":"offsides","id":5611731,"node_id":"MDQ6VXNlcjU2MTE3MzE=","avatar_url":"https://avatars3.githubusercontent.com/u/5611731?v=4","gravatar_id":"","url":"https://api.github.com/users/offsides","html_url":"https://github.com/offsides","followers_url":"https://api.github.com/users/offsides/followers","following_url":"https://api.github.com/users/offsides/following{/other_user}","gists_url":"https://api.github.com/users/offsides/gists{/gist_id}","starred_url":"https://api.github.com/users/offsides/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/offsides/subscriptions","organizations_url":"https://api.github.com/users/offsides/orgs","repos_url":"https://api.github.com/users/offsides/repos","events_url":"https://api.github.com/users/offsides/events{/privacy}","received_events_url":"https://api.github.com/users/offsides/received_events","type":"User","site_admin":false},"created_at":"2020-01-10T16:19:07Z","updated_at":"2020-01-10T16:19:07Z","author_association":"NONE","body":"The original NPath specification comes from an article in the Communications of the ACM, which is now available online here: https://www.thefreelibrary.com/NPATH%3A+a+measure+of+execution+path+complexity+and+its+applications.-a06242192\r\n\r\nYou are incorrect that the NPath of both examples above is 3.  In the first one, it is 3 - 1 for if the first if is true, and then if it's false (second path) that has 2 possible paths for the nested if giving a total NPath of 3.  The second has 4 paths - 2 for the first if (one if true, one if false even though there's no else) and 2 for the second if (same reasoning).  The reason for this is that NPath is limited in that it's NOT about how many paths through the code you might actually take based on input data, but how many POSSIBLE paths there are through the code regardless of input data.  A return statement doesn't change the fact that there are 2 possible paths even if it guarantees that later paths can never be taken once it's executed.\r\n\r\nThat's why I said it's an issue with the NPath spec - it doesn't take into account the fact that some cases just can't happen, partially because that's more of a subjective interpretation rather than an objective one (return is pretty straightforward, but goto makes a mess of everything and there's no telling what may or may not happen within a function call that might prevent later branches from being executed, etc.).  Then again, something like this can also help you tighten up your code a little, which is probably the whole point of the NPath metric in the first place."}}
other: {"actor":{"display_login":"offsides"}}