{"id":19360266,"url":"https://github.com/kts-o7/cyclomatic-complexity-clang-plugin","last_synced_at":"2025-02-24T12:18:38.304Z","repository":{"id":250932547,"uuid":"834780657","full_name":"KTS-o7/cyclomatic-complexity-clang-plugin","owner":"KTS-o7","description":"This repository is a small plugin for clang which can be built and ran to anaylse the cyclomatric complexity of the code","archived":false,"fork":false,"pushed_at":"2024-07-30T18:40:58.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-06T19:18:10.191Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KTS-o7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-28T10:43:43.000Z","updated_at":"2024-09-27T16:28:06.000Z","dependencies_parsed_at":"2024-07-30T23:13:17.040Z","dependency_job_id":null,"html_url":"https://github.com/KTS-o7/cyclomatic-complexity-clang-plugin","commit_stats":null,"previous_names":["kts-o7/cyclomatic-complexity-clang-plugin"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTS-o7%2Fcyclomatic-complexity-clang-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTS-o7%2Fcyclomatic-complexity-clang-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTS-o7%2Fcyclomatic-complexity-clang-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTS-o7%2Fcyclomatic-complexity-clang-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KTS-o7","download_url":"https://codeload.github.com/KTS-o7/cyclomatic-complexity-clang-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240475238,"owners_count":19807292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T07:17:34.958Z","updated_at":"2025-02-24T12:18:38.283Z","avatar_url":"https://github.com/KTS-o7.png","language":"C++","readme":"# cyclomatic-complexity-clang-plugin\n\nThis repository is a small plugin for clang which can be built and ran to anaylse the cyclomatric complexity of the code\n\nCyclomatic complexity is a software metric that measures the complexity of a program by counting the number of independent paths through its source code. It provides insights into the potential number of test cases required to achieve full code coverage.\n\nTo analyze the cyclomatic complexity of your code using the clang plugin, follow these steps:\n\n1. Build the plugin:\n\n```bash\nmkdir build\ncd build\ncmake ..\nmake\n```\n\n2. Run the plugin on your code:\n   The plugin takes a C++ source file as input and generates a report with the cyclomatic complexity values for each function in the code.\n\nThis command is run relative to the root of the repository.\n\n- You can change the path to the source file you want to analyze.\n- The plugin requires the `-lstdc++` flag to link the C++ standard library.\n- The plugin generates a report with the cyclomatic complexity values for each function in the code.\n- Stores as `results.cy`.\n\n```bash\nclang -lstdc++ -fplugin=./build/libCyclomaticComplexity.so ./test/sample.cpp\n```\n\nThe plugin will generate a report that includes the cyclomatic complexity values for each function in your code.\n\nTo run the plugin on a different source file, simply replace `./test/sample.cpp` with the path to your desired source file.\n\nLet's take a detailed example to understand how cyclomatic complexity works. Consider the following code snippet:\n\n```cpp\nint calculateSum(int a, int b) {\n    if (a \u003e b) {\n        return a + b;\n    } else if (a \u003c b) {\n        return a - b;\n    } else {\n        return a * b;\n    }\n}\n```\n\nIn this example, we have a function `calculateSum` that takes two integers as input and returns their sum, difference, or product based on certain conditions.\n\nTo calculate the cyclomatic complexity of this function, we count the number of decision points, which include conditional statements (`if`, `else if`, `else`) and loop statements (`for`, `while`, `do-while`). In this case, we have three decision points: the `if` statement, the `else if` statement, and the `else` statement.\n\nThe cyclomatic complexity is then calculated using the formula: `M = E - N + 2P`, where:\n\n- `E` is the number of edges in the control flow graph (number of decision points + 1)\n- `N` is the number of nodes in the control flow graph (number of statements + 1)\n- `P` is the number of connected components (1 for a single function)\n\nFor our example, `E = 4`, `N = 5`, and `P = 1`. Therefore, the cyclomatic complexity `M` is `4 - 5 + 2*1 = 1`.\n\nTo visualize the control flow graph and understand the paths through the code, you can use markdown graphs. Here's an example of how you can represent the control flow graph for our `calculateSum` function:\n\n```mermaid\ngraph TD\n    A[Start] --\u003e B{a \u003e b}\n    B -- Yes --\u003e C[Return a + b]\n    B -- No --\u003e D{a \u003c b}\n    D -- Yes --\u003e E[Return a - b]\n    D -- No --\u003e F[Return a * b]\n```\n\nThis graph shows the different paths that can be taken based on the conditions. By analyzing the cyclomatic complexity and the control flow graph, you can identify potential areas of code that may require additional testing or refactoring to improve code quality.\n\n---\n\n## Authors\n\n\u003e [Krishnatejaswi S](https://www.github.com/KTS-o7)\n\n## Citation\n\n```bibtex\n@misc{cyclomatic-complexity-clang-plugin,\n  author = {Krishnatejaswi S},\n  title = {Cyclomatic Complexity Clang Plugin},\n  year = {2024},\n  publisher = {GitHub},\n  journal = {GitHub repository},\n  howpublished = {\\url{https://www.github.com/KTS-o7/cyclomatic-complexity-clang-plugin}}\n}\n```\n\nChicago Style Citation\n\n```bibtex\nKrishnatejaswi S. \"Cyclomatic Complexity Clang Plugin.\" GitHub, 2024. https://www.github.com/KTS-o7/cyclomatic-complexity-clang-plugin.\n```\n\n---\n\n## Star Gazers Over Time\n\n[![Star History Chart](https://api.star-history.com/svg?repos=KTS-o7/cyclomatic-complexity-clang-plugin\u0026type=Date)](https://star-history.com/#KTS-o7/cyclomatic-complexity-clang-pluginr\u0026Date)\n\n---\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkts-o7%2Fcyclomatic-complexity-clang-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkts-o7%2Fcyclomatic-complexity-clang-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkts-o7%2Fcyclomatic-complexity-clang-plugin/lists"}