Coding-standard: Require DeclareStrictTypes on its own line after opening PHP tag is not possible

Created on 9 Apr 2021  路  10Comments  路  Source: slevomat/coding-standard

SlevomatCodingStandard.TypeHints.DeclareStrictTypes
declareOnFirstLine requires declare on the first line right after

I want to be able to require declare on the next line of the PHP opening tag, this seems not require-able in version 7.0.0?

When the opening <?php tag is on the first line of the file, it MUST be on its own line with no other statements unless it is a file containing markup outside of PHP opening and closing tags.
See: https://www.php-fig.org/psr/psr-12/

Bug

Most helpful comment

All 10 comments

Thanks for your reply; I read the README and already tried the configuration options, but without result.
When I put the option linesCountBeforeDeclare on 1, it will be enforced like this:

<?php

declare(strict_types=1);

However I try to enforce this:

<?php
declare(strict_types=1);

Set linesCountBeforeDeclare to 0.

When I set linesCountBeforeDeclare to 0, you're still able to put the declare on the same line as the opening PHP tag.

@tlsvda I'm sorry, I don't understand you.

Let me try to clarify it again, this is what I try to enforce:

<?php
declare(strict_types=1);

I can't achieve this with the current configuration options.
This is my configuration:

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
        <properties>
            <property name="declareOnFirstLine" value="0"/>
            <property name="linesCountBeforeDeclare" value="0"/>
            <property name="linesCountAfterDeclare" value="1"/>
            <property name="spacesCountAroundEqualsSign" value="0"/>
        </properties>
    </rule>

But with these settings I'm also able to put it like this:

<?php declare(strict_types=1);

When changing this
<property name="linesCountBeforeDeclare" value="0"/>
to
<property name="linesCountBeforeDeclare" value="1"/>

I'm forced to put an extra line between opening tag and declare line, like this:

<?php

declare(strict_types=1);

declareOnFirstLine is boolean so it should be false. Or you can just remove the line because false is default.

Okay I removed declareOnFirstLine now, but it's still possible to put the declare(strict_types=1) on the same line as the PHP opening tag.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lptn picture lptn  路  4Comments

carusogabriel picture carusogabriel  路  4Comments

donatj picture donatj  路  3Comments

Stadly picture Stadly  路  6Comments

carusogabriel picture carusogabriel  路  5Comments