Download the PHP package ncac/php-cognitive-complexity without Composer

On this page you can find all versions of the php package ncac/php-cognitive-complexity. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-cognitive-complexity

PHP Cognitive Complexity

CI codecov Packagist Version PHP Version

A modern PHP CLI tool for measuring cognitive complexity of PHP code — ISO SonarQube (G. Ann Campbell's specification).

Two commands under one binary: check for CI/hooks (strict gate, exit 1 on violation), analyse for interactive exploration (coloured output, severity levels, always exit 0).


Why cognitive complexity?

Cyclomatic complexity counts paths. Cognitive complexity measures how hard code is to read. It penalises deep nesting and rewards early returns — much closer to human perception of code quality.

This tool implements the SonarSource specification for PHP.


Installation


Usage

check — CI gate

Strict mode: exits 1 on any violation. Designed for pre-commit hooks and CI pipelines.

analyse — interactive exploration

Developer-experience mode: coloured output grouped by file, severity labels, always exits 0.

Example output:

Severity levels (multiples of threshold, default 15):

Level Score range
minor threshold+1 → 2×threshold
moderate 2×threshold+1 → 3×threshold
high 3×threshold+1 → 50
critical > 50

Generate a baseline (ignore pre-existing violations)


Configuration file

Create a cognitive.yaml at the root of your project:


Console output example

This is the output of check. For richer output, use analyse.


Integration in your project

Add convenience scripts to your composer.json for fixed targets:

For ad-hoc analysis on a specific path, call cc — the short wrapper installed alongside the main binary:

To ignore pre-existing violations during onboarding, generate a baseline first:



GitLab CI/CD integration


Algorithm

Based on G. Ann Campbell's Cognitive Complexity specification:

Structure Increment
if, else if, else +1
for, foreach, while, do-while +1
switch +1
catch +1
Ternary ?: +1
&&, \|\| (logical sequence changes) +1
Each nested level +level bonus

Development


License

MIT © Nicolas Catrice-Auzon Cape


All versions of php-cognitive-complexity with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
nikic/php-parser Version ^5.0
revolt/event-loop Version >=1.0.0 <1.0.7
symfony/console Version ^6.0 || ^7.0
symfony/finder Version ^6.0 || ^7.0
symfony/yaml Version ^6.0 || ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ncac/php-cognitive-complexity contains the following files

Loading the files please wait ...