symfony / recipes-contrib

Symfony Contrib Recipes Repositories

Home Page:https://github.com/symfony/recipes-contrib/blob/flex/main/RECIPES.md

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The php_codesniffer recipe report errors with the default Symfony installation

gremo opened this issue · comments

I did a fresh Symfony 6.3 installation, basically running:

curl -O https://raw.githubusercontent.com/symfony/skeleton/6.3/composer.json
composer install
composer require webapp
composer require squizlabs/php_codesniffer

I accepted the recipes and the following file phpcs.xml.dist was created (coming from the recipe):

<?xml version="1.0" encoding="UTF-8"?>

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

    <arg name="basepath" value="."/>
    <arg name="cache" value=".phpcs-cache"/>
    <arg name="colors"/>
    <arg name="extensions" value="php"/>

    <rule ref="PSR12"/>

    <file>bin/</file>
    <file>config/</file>
    <file>public/</file>
    <file>src/</file>
    <file>tests/</file>

</ruleset>

Running the tool it's clear that Symfony codebase doesn't follow PSR12. Reported errors are relative to spaces before/after a period (see below code).

So either the relevant Symfony files should be PSR12 (i.e. index.php) or, at least, this recipe must be updated to exclude the offending rules:

<rule ref="PSR12">
    <exclude name="PSR12.Operators.OperatorSpacing.NoSpaceBefore" />
    <exclude name="PSR12.Operators.OperatorSpacing.NoSpaceAfter" />
</rule>
root@967b5351a8f9:/var/www/html# vendor/bin/phpcs

FILE: config/preload.php
----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 3 | ERROR | [x] Expected at least 1 space before "."; 0 found
 3 | ERROR | [x] Expected at least 1 space after "."; 0 found
 4 | ERROR | [x] Expected at least 1 space before "."; 0 found
 4 | ERROR | [x] Expected at least 1 space after "."; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: public/index.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------
 5 | ERROR | [x] Expected at least 1 space before "."; 0 found
 5 | ERROR | [x] Expected at least 1 space after "."; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
root@967b5351a8f9:/var/www/html# vendor/bin/phpcs

FILE: config/preload.php
----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 3 | ERROR | [x] Expected at least 1 space before "."; 0 found
 3 | ERROR | [x] Expected at least 1 space after "."; 0 found
 4 | ERROR | [x] Expected at least 1 space before "."; 0 found
 4 | ERROR | [x] Expected at least 1 space after "."; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: public/index.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------
 5 | ERROR | [x] Expected at least 1 space before "."; 0 found
 5 | ERROR | [x] Expected at least 1 space after "."; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: tests/bootstrap.php
----------------------------------------------------------------------
FOUND 8 ERRORS AFFECTING 4 LINES
----------------------------------------------------------------------
  5 | ERROR | [x] Expected at least 1 space before "."; 0 found
  5 | ERROR | [x] Expected at least 1 space after "."; 0 found
  7 | ERROR | [x] Expected at least 1 space before "."; 0 found
  7 | ERROR | [x] Expected at least 1 space after "."; 0 found
  8 | ERROR | [x] Expected at least 1 space before "."; 0 found
  8 | ERROR | [x] Expected at least 1 space after "."; 0 found
 10 | ERROR | [x] Expected at least 1 space before "."; 0 found
 10 | ERROR | [x] Expected at least 1 space after "."; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 8 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Closing as explained in the related PR.