mayflower / mo4-coding-standard

MO4 Coding Standard Rules for Codesniffer based on Symfony Coding Standards.
MIT License
17 stars 10 forks source link

Create ConstSpacingSniff #182

Closed mmoll closed 3 years ago

mmoll commented 3 years ago

Type of issue

Description

Given this real world exmaple:

    public const NO_FAILURE                            = 'ok';
    public const FAILURE_REASON_CUSTOMER_NOT_FOUND     = 'customer_not_found';
    public const  FAILURE_REASON_NO_AUTH               = 'no_auth';
    public const FAILURE_REASON_MAIL_MISSING           = 'mail_missing';
    public const  FAILURE_REASON_PASSWORD_MISSING      = 'password_missing';
    public const  FAILURE_REASON_MAIL_PASSWORD_MISSING = 'mail_password_missing';
    public const  FAILURE_REASON_CUSTOMER_DELETED      = 'customer_deleted';
    public const  FAILURE_REASON_COMMUNICATION         = 'communication';
    public const FAILURE_REASON_UNKNOWN                = 'unknown';

it's clear that this is not acceptable. consts should be spaced like this:

protected const C1 = 'c1';
public const    C2 = 'c2';
const           C3 = 'c3';

If there are empty lines, the alignment should be resetted, just like Generic.Formatting.MultipleStatementAlignment does for =.

xalopp commented 3 years ago

@mmoll I think that after const there should exact one space. So the second example would look like this:

protected const C1 = 'c1';
public const C2    = 'c2';
const C3           = 'c3';

and the first

    public const NO_FAILURE                           = 'ok';
    public const FAILURE_REASON_CUSTOMER_NOT_FOUND    = 'customer_not_found';
    public const FAILURE_REASON_NO_AUTH               = 'no_auth';
    public const FAILURE_REASON_MAIL_MISSING          = 'mail_missing';
    public const FAILURE_REASON_PASSWORD_MISSING      = 'password_missing';
    public const FAILURE_REASON_MAIL_PASSWORD_MISSING = 'mail_password_missing';
    public const FAILURE_REASON_CUSTOMER_DELETED      = 'customer_deleted';
    public const FAILURE_REASON_COMMUNICATION         = 'communication';
    public const FAILURE_REASON_UNKNOWN               = 'unknown';

Could we agree on that?

mmoll commented 3 years ago

Could we agree on that?

Yes. ☑️