如何在PHP-CS-Fixer中配置HeaderCommentFixer

时间:2016-02-01 01:35:59

标签: php

我想使用HeaderCommentFixer提供的PHP-CS-Fixer,但我不明白该怎么做。

我试着这样做:

$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);

但是我收到了这个错误:

  

[ErrorException] strpos()期望参数1为str​​ing,object   给定

那么,我该如何配置呢? 我还检查了the test,但遗憾的是这对我没有帮助。

1 个答案:

答案 0 :(得分:3)

对于版本// 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 ));

2.x

对于较新的(dev-master$header = 'test this'; return Symfony\CS\Config\Config::create() ->setRules(array( 'header_comment' => array('header' => $header) )); ):

import datetime
import time
mytime= datetime.datetime.now()
currenttime= str(datetime.datetime.time(mytime))
currenttime = currenttime.split(':')
data = list(currenttime)
data[0] = str(int(data[0])+1) # [0] is the first part of 00:00:00, and +1 is the sum for the hour part
print data
print currenttime
while True:
    mytime= datetime.datetime.now()
    currenttime= str(datetime.datetime.time(mytime))
    currenttime = currenttime.split(':')
    # Note: if want test code, delete the while and time.sleep()
    time.sleep(5)
    if data==currenttime:
        exit(0)