friends-of-presta / fop_console

Prestashop Module providing a set of shell/terminal commands for developers (PrestaShop 1.7.5+)
Academic Free License v3.0
84 stars 35 forks source link

add a php-cs-fixer rule that adds a banner to php files. #191

Closed SebSept closed 2 years ago

SebSept commented 2 years ago

There is a rule to add a banner. It works well. but the .php_cs.dist file need some changes to support it.

I can do it later, or someone before, no matter.

ghost commented 2 years ago

I never succeeded with the $config = new PrestaShop\CodingStandards\CsFixer\Config();

With some things like that works well.

<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__)
    ->exclude('vendor')
    ->notPath('resources')
;

$config = new PhpCsFixer\Config();
$config->setRiskyAllowed(true);
return $config
    ->setRules([
        '@Symfony' => true,
        'header_comment' => [
            'comment_type' => 'PHPDoc',
            'header' => file_get_contents(__DIR__.'/licence/licence_header.txt'),
            'location' => 'after_open',
            'separate' => 'bottom'
        ],
        'concat_space' => [
            'spacing' => 'one',
        ],
        'cast_spaces' => [
            'space' => 'single',
        ],
        'error_suppression' => [
            'mute_deprecation_error' => false,
            'noise_remaining_usages' => false,
            'noise_remaining_usages_exclude' => [],
        ],
        'function_to_constant' => false,
        'no_alias_functions' => false,
        'non_printable_character' => false,
        'phpdoc_summary' => false,
        'phpdoc_align' => [
            'align' => 'left',
        ],
        'protected_to_private' => false,
        'psr4' => false,
        'self_accessor' => false,
        'yoda_style' => null,
        'non_printable_character' => true,
        'no_superfluous_phpdoc_tags' => false,
        ])
    ->setFinder($finder)
;
ghost commented 2 years ago

https://github.com/friends-of-presta/fop_console/compare/dev...okom3pom:header-stamp?expand=1

.php-cs-fixer.dist.php is for my own test with csfixer 3 i can remove it

SebSept commented 2 years ago

We can inherit PrestaShop\CodingStandards\CsFixer\Config and add rules with an anonymous class. I'm pushing a PR ...