Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Allow to use cognitive instead of cyclomatic complexity #354

Open
haraldreingruber opened this issue Mar 30, 2022 · 2 comments
Open

Comments

@haraldreingruber
Copy link

Cognitive complexity seems to have some advantages over cyclomatic complexity, for the understandability of code.

For example, a long but simple switch/case block has a very high cyclomatic complexity but a low cognitive complexity.
Here is a good description of the differences: https://docs.codeclimate.com/docs/cognitive-complexity

Maybe the analyzer from https://github.com/Rarst/phpcs-cognitive-complexity can be used to add this alternative metric?

@eduard-sukharev
Copy link

eduard-sukharev commented Apr 2, 2024

Although this tool seem to be quite extendable, I failed miserably to switch it over to cognitive complexity algorithm. Twice. I don't know how to adopt 3rd party libraries and code to be used in this tool - it's probably due to the way it's made to run in parallel to speed up analysis - but it simply misses any custom-provided classes.
I would really appreciate if @villfa @bmitch would try himself and made it available.

@villfa
Copy link
Collaborator

villfa commented Apr 9, 2024

Hi @eduard-sukharev,
This is not currently possible to extend Churn in order to replace the algorithm that calculates the complexity.
The available hooks allow users to process the results as they wish (to save them in a database for instance).

I like the idea that Churn can calculate cognitive complexity, whether by default or as an extension.

That said, I don't have much free time to work on that, so I can't promise anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants