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

Cognitive Complexity #368

Open
Isinlor opened this issue Feb 3, 2019 · 1 comment
Open

Cognitive Complexity #368

Isinlor opened this issue Feb 3, 2019 · 1 comment

Comments

@Isinlor
Copy link

Isinlor commented Feb 3, 2019

Hello,

Recently I have read about an interesting upgrade of Cyclomatic Complexity called Cognitive Complexity.

Cyclomatic Complexity was initially formulated as a measurement of the “testability and
maintainability” of the control flow of a module. While it excels at measuring the former, its
underlying mathematical model is unsatisfactory at producing a value that measures the
latter. This white paper describes a new metric that breaks from the use of mathematical
models to evaluate code in order to remedy Cyclomatic Complexity’s shortcomings and
produce a measurement that more accurately reflects the relative difficulty of understanding,
and therefore of maintaining methods, classes, and applications.

Here is the paper: https://www.sonarsource.com/docs/CognitiveComplexity.pdf

I have also seen two implementations for PHP:

https://github.com/Symplify/Symplify/blob/2a449a660d48658088e35be8bd565111c230fa78/packages/TokenRunner/src/Analyzer/SnifferAnalyzer/CognitiveComplexityAnalyzer.php

https://github.com/NielsdeBlaauw/php-doc-check/blob/master/src/Metrics/CognitiveComplexity.php

I guess it could be an interesting addition to PHP Metrics.

( Side note: I have submitted similar issue to PHP Mess Detector: phpmd/phpmd#594 )

@niconoe-
Copy link
Contributor

Issue #409 is giving link of another example of implementation.

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

2 participants