php /folder/phpcs.phar --config-set installed_paths /folder/PHPCompatibility-x.y.z/PHPCompatibility
php /folder/phpcs.phar --standard=PHPCompatibility /folder/with/php/files
ou php /folder/phpcs.phar --standard=PSR12 /folder/with/php/files
Pour définir l'ensemble de nos règles directement :
/folder/myRuleset.xml
:
<?xml version="1.0"?>
<ruleset name="myRuleset">
<description>Toutes mes règles PHPCS.</description>
<!-- Inclure PSR-12 -->
<rule ref="PSR12" />
<!-- Inclure PHPCompatibility -->
<rule ref="PHPCompatibility"/>
</ruleset>
php /folder/phpcs.phar --standard=/folder/myRuleset.xml /folder/with/php/files
Certaines règles peuvent ne pas convenir au projet, il est possible de les ignorer :
php /folder/phpcs.phar -s --standard=/folder/myRuleset.xml /folder/with/php/files
.
Le nom de la règle causant l'avertissement est désormais affichée (exemple : (Generic.Files.LineEndings.InvalidEOLChar)
)...
<!-- Inclure PSR-12 -->
<rule ref="PSR12">
<!-- Exclure les CRLF gérés par git => core.autocrlf=true ) -->
<exclude name="Generic.Files.LineEndings.InvalidEOLChar" />
</rule>
...
Ces vérifications peuvent être effectuées automatiquement lors de l'envoi de code sur GitHub.
/.github/workflows/main.yml
> # This is a basic workflow to help you get started with Actions
>
> name: CI
>
> # Controls when the action will run.
> on:
> # Triggers the workflow on push or pull request events but only for the main branch
> push:
> branches: [ main ]
> pull_request:
> branches: [ main ]
>
> # Allows you to run this workflow manually from the Actions tab
> workflow_dispatch:
>
> # A workflow run is made up of one or more jobs that can run sequentially or in parallel
> jobs:
> # This workflow contains a single job called "build"
> build:
> # The type of runner that the job will run on
> runs-on: ubuntu-latest
>
> # Steps represent a sequence of tasks that will be executed as part of the job
> steps:
> # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
> - uses: actions/checkout@v2
>
> - name: Setup PHP
> uses: shivammathur/setup-php@v2
> with:
> php-version: '7.4'
> tools: cs2pr, phpcs
>
> - name: Run phpcs
> run: phpcs -q --standard=myRuleset.xml --report=checkstyle $GITHUB_WORKSPACE | cs2pr