Janus PHP
Janus is a library to provide the config for our CI / code style tools.
We use the following tools:
The philosophy of this library is like this:
- put reusable config into the library
- place all config files in the root of the project, but reference the reusable config files from the library
This has the following advantages: every developer and tool detects that we use these tools, but we have a reusable config that can be automatically update with a composer update
.
All tools are installed and used with the Composer bin plugin, so that the dependencies don't interfere with your application.
If you want to use PHPUnit, please make sure the read the note about it.
Installation
Install the library with:
composer req --dev 21torr/janus
If you can't install Janus directly into your project due to conflicting dependencies, then use a custom vendor-bin
installation. You'll need to adapt all paths from below to point to your vendor-bin
directory.
E.g. composer bin janus require --dev 21torr/janus
Integration
To place the import files into the project, the library provides a helper that just copies the files to the repository and updates the composer.json
. So make sure that your Git is clean before running this command. After updating, you can diff and integrate the changes with git.
./vendor/bin/janus init
You need to rerun this task every time anything in janus changed (i.e. the janus version changed).
Usage
Janus also adds scripts
to your composer.json
that you then run with composer:
# Fixes lint issues
composer fix-lint
# Runs linting, use in your CI
composer lint
# Runs tests, use in your CI
composer test
If you have no conflict, you can use the short version composer lint
, otherwise you need to use the longer form composer run-script lint
.
Integration in CI
Your CI should just use the composer scripts:
"Build App":
script:
- "composer install --optimize-autoloader --classmap-authoritative --no-interaction"
- "composer run-script lint"
- "composer run-script test"
BC Promise
This package has by definition no BC promise. So with every update it is possible, that your CI will fail.
However, that is intended: the whole purpose of this package is to force the application to have clean, error-free and clearly structured code. So forcing the dev to be always up-to-date is a good thing.
PHP CS Fixer
We use our own PHP-CS-Fixer package, as it adds custom configuration for our usage.
PHPStan
Janus uses a pretty strict PHPStan config. One of the most prominent issues is that "unspecified iterable" error, you can deactivate it with this config:
parameters:
ignoreErrors:
- identifier: missingType.iterableValue
You should work on typing your iterables however, to have a clean project and be able to remove this ignore rule in the future.