Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR12 / There must be 1 space after the property type #3729

Open
Phillip85 opened this issue Dec 12, 2022 · 4 comments · May be fixed by #3756
Open

PSR12 / There must be 1 space after the property type #3729

Phillip85 opened this issue Dec 12, 2022 · 4 comments · May be fixed by #3756

Comments

@Phillip85
Copy link

Describe the bug

Code sample

class test 
{
    public FlightHeader  $flight_header;
    public Carbon        $flight_date;
    public BookingNumber $booking_number;
}

Custom ruleset

<?xml version="1.0"?>
<ruleset name="schauinsland" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
    <rule ref="PSR12"/>
    <rule ref="Squiz.NamingConventions.ValidVariableName.NotCamelCaps"/>
    <rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps"/>
    <rule ref="Squiz.NamingConventions.ValidVariableName.StringNotCamelCaps"/>
    <rule ref="Generic.Arrays.DisallowLongArraySyntax">
        <type>warning</type>
    </rule>
    <rule ref="Generic.PHP.ForbiddenFunctions">
        <properties>
            <property name="forbiddenFunctions" type="array">
                <element key="sizeof" value="count"/>
                <element key="delete" value="unset"/>
                <element key="print" value="echo"/>
                <element key="create_function" value="null"/>
            </property>
        </properties>
    </rule>

    <exclude-pattern>/vendor/</exclude-pattern>
</ruleset>

To reproduce

 11 | ERROR | [x] There must be 1 space after the property type
    |       |     declaration; 2 found
 12 | ERROR | [x] There must be 1 space after the property type
    |       |     declaration; 8 found

Expected behavior
no error

Reason
The PSR12 does not disalow multiple spaces after the declaration:

There MUST be a space between type declaration and property name.

it just says there must be a space, not one space

@Tithugues
Copy link

I'd like to clarify something please… What would be the point to say that there MUST be a space (so from one to many) between type and name, whereas it's not possible to have 0 space, as it would be syntactically invalid?

Do we expect PSR to explicitly redefine the PHP rules?

If not, my feeling would be that the intention was to require one single space after the property type.

@Phillip85
Copy link
Author

syntactically this is still correct/working... (PHP is impressive inconsistent in this case)

class test
{
    public FlightHeader$flight_header;
    public Carbon$flight_date;
    public BookingNumber$booking_number;
    public ?string$booking_class;
}

thats why i see a difference between "must be a space" and "must be one space"

@Phillip85
Copy link
Author

and PSR makes a difference between 'one space' and 'a space'

4.5 Method and Function Arguments
In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma.

in this example is explicit one space defined

@Tithugues
Copy link

syntactically this is still correct/working... (PHP is impressive inconsistent in this case)

class test
{
    public FlightHeader$flight_header;
    public Carbon$flight_date;
    public BookingNumber$booking_number;
    public ?string$booking_class;
}

thats why i see a difference between "must be a space" and "must be one space"

WOW! 😱 Sorry for this, I should have tested it before answering…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants