Php-cs-fixer: Adding script_types right after <?php

Created on 3 Feb 2017  Â·  5Comments  Â·  Source: FriendsOfPHP/PHP-CS-Fixer

If I run the fixer on files without declare(strict_types=1);, it will add it, but right after the opening <?php tag which itself thinks is wrong, if I re-run it, it will fix it again to be as expected. This means all fixes must be run twice.

The PHP version you are using:
PHP 7.1.1

PHP CS Fixer version you are using:
PHP CS Fixer 2.0.0 by Fabien Potencier and Dariusz Ruminski

The command you use to run the fixer
vendor/bin/php-cs-fixer fix --diff -v --using-cache false

and the configuration file you are using if any

<?php
declare(strict_types = 1);
$finder = PhpCsFixer\Finder::create()
    ->exclude('vendor')
    ->exclude('var')
    ->notPath('bin/symfony_requirement')
    ->in(__DIR__);

return PhpCsFixer\Config::create()
    ->setRiskyAllowed(true)
    ->setRules(
        [
            '@Symfony' => true,
            'array_syntax' => ['syntax' => 'short'],
            'declare_strict_types' => true,
            'php_unit_strict' => true,
            'phpdoc_add_missing_param_annotation' => true,
            'phpdoc_order' => true,
            'psr4' => true,
            'strict_comparison' => true,
            'strict_param' => true,
        ]
    )
    ->setFinder($finder);

The fixed version of that code after you run the fixer

<?php declare(strict_types=1);
class Foo
{
}

and the version you expected.

<?php

declare(strict_types=1);
class Foo
{
}

All 5 comments

Thank you for your detail report!

This is indeed an issue that is not resolved.
For background and discussion on this please see also:

If you've time please help out by reviewing the proposed PR to fix the first part of the issue and/or create a PR for this issue. It will be must welcome as more people would like this fixed :)

@SpacePossum sorry, should have searched issues more thoroughly, closing. :(

no worries, thanks reporting it helps prioritizing :)

My PR #2481 resolves exactly this issue :)

@juliendufresne looking forward to getting this merged! :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bilge picture Bilge  Â·  3Comments

fisharebest picture fisharebest  Â·  3Comments

kcloze picture kcloze  Â·  3Comments

OskarStark picture OskarStark  Â·  3Comments

grachevko picture grachevko  Â·  3Comments