Вопрос

I want to know is there any way to find the cyclomatic complexity of the project created in Xcode.

Thanks

Это было полезно?

Решение

You can use a external tool like http://oclint.org/

OCLint is a static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code and looking for potential problems like:

  • Possible bugs - empty if/else/try/catch/finally statements
  • Unused code - unused local variables and parameters
  • Complicated code - high cyclomatic complexity, NPath complexity and high NCSS
  • Redundant code - redundant if statement and useless parentheses
  • Code smells - long method and long parameter list
  • Bad practices - inverted logic and parameter reassignment

Two non free options: Xclarify (99$ or 400$) and SonarQube (5,000€).

Другие советы

CLang Static Analyzer

You can use Static Analyzer for CLang, it can be integrated with Xcode and it'll perform some basic analysis to produce quality indices (such as cyclomatic compexity) and more advanced static analysis (to detect possible bugs, defects, hard to maintain code).

See this tutorial for instruction about integration.

From website:

The Clang Static Analyzer is a source code analysis tool that finds bugs in C, C++, and Objective-C programs.

HFCCA

If you don't really need a full static analysis tool you may consider to use a more simple program to just calculate cyclomatic complexity. HFCCA is a simple Phyton script that can be used from command line and produces some very basic indices (lines of code without comments, cyclomatic complexity, token count of functions and parameter count of functions).

It's a command line tool but it can be integrated in XCode (take a start from CLang analyzer to see how).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top