$ php -v):PHP 7.2.11-2+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Oct 15 2018 11:40:04) ( NTS )
$ php-cs-fixer -V):2.12 / 2.13
$ php-cs-fixer fix tmp/test2.php --dry-run -vvv --diff
<?php
$header = <<<'EOF'
/**
* Foo
*/
EOF;
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
;
return PhpCsFixer\Config::create()
->setRules([
'header_comment' => [
'header' => $header,
'location' => 'after_open',
'separate' => 'bottom'
],
])
->setFinder($finder)
;
<?php
$ php-cs-fixer fix tmp/test2.php --dry-run -vvv --diff
Loaded config default from "/home/possum/work/PHP-CS-Fixer/.php_cs.dist".
Using cache file ".php_cs.cache".
Paths from configuration file have been overridden by paths provided as command arguments.
E
Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error
Checked all files in 0.006 seconds, 10.000 MB memory used
Files that were not fixed due to errors reported during linting after fixing:
1) /home/possum/work/PHP-CS-Fixer/tmp/test2.php
[PhpCsFixer\Linter\LintingException]
PHP Parse error: syntax error, unexpected '*', expecting end of file on line 6.
Applied fixers: header_comment
---------- begin diff ----------
--- Original
+++ New
@@ @@
<?php
+/*
+ * /**
+ * * Foo
+ * */
+ */
+
<?php
/**
* Foo
*/
--- Update ---
Clearly this is an user error for providing the header as PHPDoc already.
However we could detect this case during configuration of the rule and throw a nice exception message and not crash during fixing.
Should we throw exception if it contains */, as that is the sequence that breaks it. Or should it be escaped somehow?
I prefer to see the fixer throw an InvalidFixerConfigurationException when */ is in the configured header
Most helpful comment
I prefer to see the fixer throw an
InvalidFixerConfigurationExceptionwhen*/is in the configured header