聲納給了我下面的圈複雜度數:22聲納如何計算圈複雜度?
對於下面的程序:
private static SomeDto checkSomething(AnotherDto anotherDto, String reference)
{
SomeDto someDto = new SomeDto();
// condition 1
if (!someDto.getA())
return new SomeDto("bla1", "blabla");
// condition 2
if (someDto.getName2() == null || checkSurName(anotherDto.getName()))
return new SomeDto("bla2", "blabla");
// condition 3
if (someDto.getName3() == null || checkSurName(anotherDto.getName()))
return new SomeDto("bla3", "blabla");
// condition 4
if (someDto.getName4() == null && checkSurName(anotherDto.getName()))
return new SomeDto("bla4", "blabla");
// condition 5
if (someDto.getName5() == null || checkSurName(anotherDto.getName()))
return new SomeDto("bla5", "blabla");
// condition 6
if (someDto.getName6() == null && checkSurName(anotherDto.getName()))
return new SomeDto("bla6", "blabla");
// condition 7
if (someDto.getName7() == null && checkSurName(anotherDto.getName()))
return new SomeDto("bla7", "blabla");
// condition 8
if (someDto.getName8() == null && checkSurName(anotherDto.getName()))
return new SomeDto("bla8", "blabla");
// condition 9
if (someDto.getName9() == null && checkSurName(anotherDto.getName()))
return new SomeDto("bla9", "blabla");
// condition 10
if (someDto.getName10() == null && checkSurName(anotherDto.getName()))
return new SomeDto("bla10", "blabla");
// condition 11
if (someDto.getName11() == null && checkSurName(anotherDto.getName()))
return new SomeDto("bla11", "blabla");
return someDto;
}
問題我得到的是以下幾點:
「這種方法的圈複雜度」 checkSomething「是22,它大於12授權」
我的問題是: 考慮Mac Ca (公式)v(g)= e - n + 2,Sonar如何達到22的數量?
其中:
E =邊緣
數N =節點
在這個方法中有多少邊和節點的有多少? 這種方法的控制流程是什麼?
我們在SonarQube版本6.3(建立19869)。
請[編輯]你的問題,包括問題 –
分析儀的名稱和版本,你可以發佈一個具體的'if(condition *)'? –
是的。 'if(anotherDto.getName()== null ||!checkSurName(anotherDto.getName())) return new SomeDto(「bla10」,「blabla」);' –