Download the PHP package christianjbrown/code-quality-scripts without Composer

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

PHP Code Quality Scripts

CI Coverage Packagist License PHP

This project

:heavy_check_mark: Prerequisites

:bulb: If you're on MacOS and have Homebrew, PHP and Composer will install with brew install composer.

:bulb: Xdebug is only needed if you want to work on this repository itself (it generates the test coverage report). Consumers of the package don't need it. See Development below.

* These scripts have only been tested on MacOS, but will likely work in any Bash/Z-Shell environment.

:building_construction: Installation

As part of your composer-enabled project

In the project you wish to use the phpcs standard and phpcsfixer rules in your project, require this library

:bulb: This package pulls in dealerdirect/phpcodesniffer-composer-installer, which registers the bundled slevomat sniffs with PHP_CodeSniffer automatically. Composer will ask to trust that plugin the first time; allow it (or add it to config.allow-plugins in your composer.json):

Adding composer scripts

Consider using the rules and standards through composer scripts

Alternatively, you can use the original PHP Code Sniffer phpcs and PHP CS Fixer php-cs-fixer commands with the rules and standards provided:

In either case, you can run composer check-style or composer fix-style directly within your project.

Standalone installation

If you want to use these tools in a standalone way, not specific to a project:

Setting up global commands

If you want to use the shell scripts anywhere

:computer: Usage

:bulb: If you don't add these commands to your PATH, you'll need to run them from the ./src directory in this repository, or if including this in a composer-enabled PHP project, the configured bin-dir (defaults to ./vendor/bin).

Using php-cs

where

Using php-cs-diff

where

Using php-cs-fix

where

:warning: This will default to the risky rule set. See Setting up global commands on how to override this.

Using php-cs-fix-diff

where

:warning: This will currently default to the risky rule set for new files, and safe rule set for existing files. See Setting up global commands on how to override this.

Using php-changelog-check

Run it on pull requests, from the repository root, against the branch being merged into:

It fails (exit 1) when the pull request changes anything under src/ without also changing CHANGELOG.md, or when CHANGELOG.md no longer has a ## [Unreleased] heading. A repository with no CHANGELOG.md is skipped (exit 0). Exit 2 means no base ref was given or git could not diff against it. The changelog is expected to follow Keep a Changelog: each change adds a line under ## [Unreleased], and a release renames that section to the version.

In GitHub Actions:

Using php-coverage-check

where

It compares the covered and total counts rather than the rounded percentage, so 1999 of 2000 lines fails a 100% floor even though PHPUnit prints it as 100.00%. It exits 0 when every metric passes, 1 when one is under the floor, and 2 when the report is missing or has no summary. Paths and branches only appear in the summary when PHPUnit runs with pathCoverage="true".

PHP CodeSniffer Standard

The PHPCS standards can be found in ./config directory.

The only standard in there right now is ./config/standard.xml (name ChristianBrown), a set of rules for PHP_CodeSniffer 4 based on various PSR, PEAR, Squiz, Zend and Generic standards plus slevomat/coding-standard sniffs, with a few more sprinkled in for extra goodness. (Earlier versions built on escapestudios/symfony2-coding-standard, which is PHP_CodeSniffer 3 only; its formatting rules are now handled by the PHP CS Fixer @Symfony/@PhpCsFixer rule sets and its lint rules by slevomat.)

config/ChristianBrown/ruleset.xml is a thin shim that re-exports standard.xml under a named directory, so once config/ is on phpcs installed_paths the standard is discoverable as --standard=ChristianBrown.

The php-cs-fix / php-cs-fix-diff wrappers run PHP CS Fixer and then phpcbf (with this standard), because some slevomat violations (e.g. useless phpdoc @param/@return annotations) are auto-fixable only by phpcbf, not PHP CS Fixer.

PHP CS Fixer Rule sets

The rule sets can be found in the ./config directory.

They can be generated by a handy user interface provided at https://mlocati.github.io/php-cs-fixer-configurator/

:warning: Risky

Rule set: Risky.php

A set of risky non-backward compatible rules based on various PSR, Symfony, PEAR and Generic standards, with a few more sprinkled in for extra goodness. If you use this, you will want to have very good test coverage, but at the end you will have some very neat code.

:construction_worker: Safe

Rule set: Safe.php

A set of safer backward-compatible rules based on various PSR, Symfony, PEAR and Generic standards, with a few more sprinkled in for extra goodness. This is better for running on existing legacy codebases which you may to be too risky to make too many changes to in one go.

PHPStan

The package also ships a shared PHPStan config at config/phpstan.neon, so the analysis policy (the level, and a custom rule) lives here once instead of being duplicated in every project.

It sets:

Consuming it

phpstan/phpstan is a dev dependency of your project (add it if you don't already have it):

Then include the shared config from your project's phpstan.neon.dist and add only your project's paths:

Add a stan composer script to run it (uses the bin-dir from Adding composer scripts above):

:bulb: Why paths (and tmpDir) stay in your project and not here: PHPStan resolves relative paths against the directory of the file that declares them. paths written in this package's config/phpstan.neon would resolve against vendor/christianjbrown/code-quality-scripts/config/, not your project root — so they must live in your own phpstan.neon.dist. The level and rules, being path-independent, are shared. Change the level or add a rule here once and every consumer picks it up on composer update.

:bulb: Array parameters (e.g. ignoreErrors) set in both files are merged/appended by default; to override the shared value instead, prefix the key in your own file with ! (e.g. ignoreErrors!:).

:hammer_and_wrench: Development

This section is for working on the package itself, not for consuming it.

The repository dogfoods its own standard — composer check-style runs the ChristianBrown standard over config and tests, and CI fails on any violation, so any PHP added here must already conform.

Requires PHP 8.5 and Xdebug (Xdebug is only needed to generate the test coverage report). Both bin/ and vendor/ are gitignored and Composer-installed, so run composer install first — its post-install-cmd runs setup-standards, which registers the phpcs standard so ./src/php-cs works.

Task Command
Run tests + coverage (opens HTML report) composer test
Static analysis (PHPStan level max) composer stan
Check code style composer check-style
Auto-fix code style composer fix-style
Check / fix style on git diff only composer check-style-diff / composer fix-style-diff

Recommended order before finishing a change: composer fix-style → composer check-style → composer stan → composer test. CI (.github/workflows/ci.yml) runs the same gates on push/PR to main.

:page_facing_up: License

Released under the MIT License.


All versions of code-quality-scripts with dependencies

PHP Build Version
Package Version
Requires php Version ^8.5
ext-mbstring Version *
ext-xdebug Version *
friendsofphp/php-cs-fixer Version ^3.74
squizlabs/php_codesniffer Version ^4.0.2
slevomat/coding-standard Version ^8.30
dealerdirect/phpcodesniffer-composer-installer Version ^1.2.1
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 christianjbrown/code-quality-scripts contains the following files

Loading the files please wait ...