Download the PHP package stejac/code-thresholds without Composer

On this page you can find all versions of the php package stejac/code-thresholds. 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 code-thresholds

code-thresholds

A dependency-free size and complexity gate for PHP that checks only the files you changed: method count, parameters, returns, function length, nesting depth and two defect checks, in a pre-commit hook or a pull request.

CI Latest Stable Version codecov

Deutsche Version

Why this one?

Size and complexity limits are usually enforced late: a hosted analysis reports them after the push, and the fix turns into another round of review. This tool moves exactly the limits that can be counted from a single file to the moment before the commit.

Tool What it is good at Where code-thresholds differs
PHPStan Types and bugs It has no size or complexity limits; this tool does not look at types at all. Use both.
PHPMD Similar metrics (excessive method count, parameter list length, ...) PHPMD brings its own dependencies and rule-set XML. This tool is one composer require --dev with ext-tokenizer as its only requirement, and one small PHP config file.
PHP_CodeSniffer Code style, plus a few metrics sniffs Style is not the goal here, and there is no ruleset to compose.
SonarCloud Cognitive complexity, duplication, security hotspots, history It runs on the server after the push. This tool answers locally, in the pre-commit hook or the pull request job, before a finding exists.

What sets it apart is the combination: zero dependencies, only changed files (staged, or a diff against a base ref), so it stays fast enough for every commit, and one config file that is plain PHP.

What it deliberately leaves out

A check that reports something a project does not really enforce is worse than no check: it blocks commits and gets switched off. Three checks are therefore absent on purpose.

Everything is measured on token_get_all(), never with regular expressions. A regex over string literals matches the gap between two array keys as if it were a literal of its own.

Quickstart

Without a config file the defaults apply and src/ is the source directory. Output on success goes to stdout, the violation list to stderr:

Exit codes: 0 no violations, 1 violations found, 2 usage or configuration error.

Ready-made integrations:

Features

Check Config key Default Counts
Methods per class limits.methods_per_class 20 Methods of one class, interface, trait or enum. Closures are not methods.
Parameters limits.parameters 7 Parameters of a function or method. A trailing comma and commas inside default values or attributes are not counted.
Returns limits.returns 3 return statements in a function. Returns inside a nested closure belong to the closure.
Function length limits.function_length 100 Lines of the function body.
Nesting depth limits.nesting_depth 4 Nested if, for, foreach, while, switch, try and match blocks. Ten sequential if blocks are depth one.
Unused variable rules.unused_variable on A variable that appears exactly once in a function body, as an assignment. Deliberately conservative to avoid false alarms with destructuring, references and interpolation.
Loop counter reassigned rules.loop_counter_reassigned on A for counter that is assigned inside the loop body. Use while instead.

Configuration

Create code-thresholds.php in the directory you run the tool from (or pass --config=<file>). It returns an array; every key is optional. Without a file the defaults below apply. Unknown keys and wrong types stop the run with exit code 2.

Key Type Default Meaning
source_dirs list<string> ['src'] Directories scanned by --all. Missing directories are skipped; if none exists the run fails with exit code 2.
exclude list<string> [] fnmatch() globs of files that are never checked. * also matches /.
limits array<string, int\|null> see Features Keys methods_per_class, parameters, returns, function_length, nesting_depth. null disables a limit.
rules array<string, bool> all true Keys unused_variable, loop_counter_reassigned.
methods_per_class_exclude list<string> ['*/Entity/*', 'tests/*'] Globs of files exempt from the method count only. Entities track the width of a table, and a test class holds one method per scenario.
exempt_constructors bool true Constructors are not checked against the parameter limit: injecting eight collaborators is not the same defect as an eight-argument call.

The project root is the directory of the config file, or the working directory when there is none. Globs and source_dirs are relative to it. The match is anchored at the root on purpose: a checkout below a directory that happens to be called tests must not exempt all of src/.

Paths that do not exist, files that are not *.php and excluded files are ignored.

Security

The tool reads the PHP files it is pointed at and never executes them. The config file is the exception: it is a PHP file that is included, so treat it like composer.json scripts and only run the tool in projects you trust. Git is started without a shell and the --base ref is validated against a conservative pattern, so a ref cannot inject options or commands. To report a vulnerability, see SECURITY.md.

Requirements

PHP 8.3 or newer with ext-tokenizer. git for staged and --base mode. Developed and tested on Linux and macOS.

Contributing

Issues and pull requests are welcome, see CONTRIBUTING.md. The checks you need locally:

About

Built and maintained by Stefan Jacomeit.

License

MIT, see LICENSE.


All versions of code-thresholds with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
ext-tokenizer Version *
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 stejac/code-thresholds contains the following files

Loading the files please wait ...