Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure HeaderCommentFixer in PHP-CS-Fixer

Tags:

php

I'd like to use HeaderCommentFixer provided by PHP-CS-Fixer but I don't understand how to.

I tried to do something like this:

$headerCommentFixer = new HeaderCommentFixer();
$headerCommentFixer->setHeader('test this');

return Symfony\CS\Config\Config::create()
    ->level(Symfony\CS\FixerInterface::NONE_LEVEL)
    ->setUsingCache(false)
    ->fixers([
        ...
        $headerCommentFixer,
        ...
    ])
    ->finder($finder);

But I get this error:

[ErrorException] strpos() expects parameter 1 to be string, object given

So, how can I configure it? I also checked the test, but this unfortunately didn't helped me.

like image 415
Aerendir Avatar asked Oct 19 '22 16:10

Aerendir


1 Answers

For version 1.x:

// Configure the fixer
$header = 'test this';
Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header)

return Symfony\CS\Config\Config::create()
    ->fixers(array(
        'header_comment' // Enable the fixer as rule
    ));

For newer (2.x or dev-master):

$header = 'test this';

return Symfony\CS\Config\Config::create()
    ->setRules(array(
        'header_comment' => array('header' => $header)
    ));
like image 110
chalasr Avatar answered Oct 26 '22 22:10

chalasr