Download the PHP package code050/codestyle without Composer

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

banner

Code050 Codestyle

The official Code050 codestyle package.

Guidelines

A description of the guidelines can be found in the Code050 Codestyle Guidelines document.

Installation

You can install the package via composer:

Usage

The primary usage of the package is to provide a consistent code style for all Code050 projects. We achieve this by using a combination of various tools. Currently, these tools include:

The package contains stub configurations for these tools which can be used in your project.

Initializing the package

To initialize the package, you can run the following command:

This will copy the stub configuration files to your project, but will not overwrite any existing files. If you want to overwrite existing files, you can use the -- --overwrite flag. Note the double -- before the --overwrite flag.

When initializing the package in an existing project, chances are that you will get loads of errors from the PHP_CodeSniffer and PHPStan checks. This is because the stub configuration files are very strict and will enforce a lot of rules. For PHPStan you can generate a baseline file to ignore all the errors.

If you do not want to use the Php-cs baseline for your project, you can use --loose flag to initialize the package with a looser configuration. This will report a lot of common errors as warnings instead of errors, so you can fix them at your own pace. In the background the --loose flag will copy the phpcs.loose.xml file instead of the phpcs.xml file. You can even extend this file with more custom rule mitigations, to get to the 0 error state.

Running the checks

To ensure your code follows the Code050 codestyle, you need to run the PHP_CodeSniffer and PHPStan checks. You can run the PHP_CodeSniffer checks by running the following command:

PHP_CodeSniffer

This command will check your code against the Code050 codestyle rules and provide feedback on any issues found.

To automatically fix any issues found by PHP_CodeSniffer, you can run the following command:

PHPstan

You can run the PHPStan checks by running the following command:

This command will check your code against the Code050 PHPStan rules and provide feedback on any issues found.

Configuration

PHP_CodeSniffer

After initializing the package, you can configure the PHP_CodeSniffer rules by editing the phpcs.xml file in the root of your project. You can find more information about the rules that can be configured in the PHP_CodeSniffer documentation.

Basically, when you want to ignore certain rules, you can add the following to the phpcs.xml file:

Example: configuring cognitive complexity

When you want to ignore a rule only in a certain path, you can add the following to the phpcs.xml file:

PHPStan

You can change the PHPStan configuration by editing the phpstan.neon file in the root of your project. You can find more information about the rules that can be configured in the PHPStan documentation.

Generating baseline

When you want to generate a baseline file, you can run the following command:

This will generate a phpstan-baseline.neon file in the root of your project. It will also register this baseline in your phpstan.neon file, so it will be used when running the PHPStan checks.

General notes

If you encounter any issues with the package, please create an issue on the GitHub repository.

Workflow for legacy projects

Unfortunately, we can't just run the init and fixer commands on legacy projects. This will probably break some things, but more often than not, after generation of a phpstan baseline, the project will still have PHPStan errors.

These errors usually indicate serious problems in the code, that would probably throw exceptions when hit in production. So, we need to fix these errors manually.

For PHP_CodeSniffer, we can use the --loose flag to generate a looser configuration. This will report a lot of common errors as warnings instead of errors, so you can fix them at your own pace. You can find a detailed explanation of the --loose flag in the Initialization section.

So firstly we need to run the init command with the --loose flag:

After this, we can run the PHP_CodeSniffer fixer command:

Then we run PHPStan to generate a baseline file:

The errors that remain after this, are the ones that need to be fixed manually. For PHP_CodeSniffer, you can report these errors as warnings as described in the Initialization section. For PHPStan, you should fix the error manually.


All versions of codestyle with dependencies

PHP Build Version
Package Version
Requires squizlabs/php_codesniffer Version ^3.7
slevomat/coding-standard Version ~8.0
phpstan/phpstan Version ^1.9
melchiorkokernoot/composer-pkg-scripts Version ^1.0.0
php Version >7.4
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 code050/codestyle contains the following files

Loading the files please wait ....