FAQ
Edit report at https://pear.php.net/bugs/bug.php?id=19798&edit=1

ID: 19798
Updated by: mplx+pear@donotreply.at
Reported By: mplx+pear at donotreply dot at
Summary: PSR-2: default value assignment in method arguments
Status: Open
Type: Bug
Package: PHP_CodeSniffer
Operating System: Cygwin
Package Version: 1.4.3
PHP Version: 5.3.20
Roadmap Versions:
New Comment:

Testcode:

<?php
public function foo ($arg = 'default')
{
}


Previous Comments:
------------------------------------------------------------------------

[2013-01-23 16:39:05] mplx

Description:
------------
Assignment operations are omitted intentionally from the PSR-2
ruleset (see PSR-2 chapter 7).

Current phpcs PSR-2 ruleset however enforces blanks for
assignment of default values in method arguments.

See also https://github.com/php-fig/fig-standards/issues/82

Test script:
---------------
public foo ($arg='default')
{
}

Expected result:
----------------
phpcs considers this valid PSR-2 coding style

Actual result:
--------------
Incorrect spacing between argument "$arg" and equals sign;
expected 1 but found 0

Incorrect spacing between default value and equals sign for
argument "$arg"; expected 1 but found 0

------------------------------------------------------------------------

Search Discussions

  • Mplx+pear at Jan 23, 2013 at 4:50 pm
    Edit report at https://pear.php.net/bugs/bug.php?id=19798&edit=1

    ID: 19798
    Updated by: mplx+pear@donotreply.at
    Reported By: mplx+pear at donotreply dot at
    Summary: PSR-2: default value assignment in method arguments
    Status: Open
    Type: Bug
    Package: PHP_CodeSniffer
    Operating System: Cygwin
    Package Version: 1.4.3
    PHP Version: 5.3.20
    Roadmap Versions:
    New Comment:

    <?php
    public function foo ($arg='default')
    {
    }


    Previous Comments:
    ------------------------------------------------------------------------

    [2013-01-23 16:49:19] mplx

    Testcode:

    <?php
    public function foo ($arg = 'default')
    {
    }

    ------------------------------------------------------------------------

    [2013-01-23 16:39:05] mplx

    Description:
    ------------
    Assignment operations are omitted intentionally from the PSR-2
    ruleset (see PSR-2 chapter 7).

    Current phpcs PSR-2 ruleset however enforces blanks for
    assignment of default values in method arguments.

    See also https://github.com/php-fig/fig-standards/issues/82

    Test script:
    ---------------
    public foo ($arg='default')
    {
    }

    Expected result:
    ----------------
    phpcs considers this valid PSR-2 coding style

    Actual result:
    --------------
    Incorrect spacing between argument "$arg" and equals sign;
    expected 1 but found 0

    Incorrect spacing between default value and equals sign for
    argument "$arg"; expected 1 but found 0

    ------------------------------------------------------------------------
  • Gsherwood at Jan 23, 2013 at 11:32 pm
    Edit report at https://pear.php.net/bugs/bug.php?id=19798&edit=1

    ID: 19798
    Updated by: gsherwood@squiz.net
    Reported By: mplx+pear at donotreply dot at
    Summary: PSR-2: default value assignment in method arguments
    -Status: Open
    +Status: Feedback
    Type: Bug
    Package: PHP_CodeSniffer
    Operating System: Cygwin
    Package Version: 1.4.3
    PHP Version: 5.3.20
    -Assigned To:
    +Assigned To: squiz
    Roadmap Versions:
    New Comment:

    -Status: Open
    +Status: Feedback
    -Assigned To:
    +Assigned To: squiz
    Section 4.3:
    https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-
    coding-style-guide.md#43-methods

    says: "A method declaration looks like the following. Note the placement
    of
    parentheses, commas, spaces, and braces:"

    And is then followed by an example that shows a single space before and
    after the
    equals sign for default values. So when I wrote the standard, I ensured
    that it
    checked for the correct spacing, comma and bracket placement as defined
    in that
    example.

    This is common in many coding standards because a bit of sample code is
    always
    easier to write than a complete list of every rule. Although I still
    need to code in every
    rule when I do a standard.

    Note that section 7 talks about assignments being excluded, which I
    believe means
    variable assignments and not assignment of default values, as these are
    explicitly
    referred to in the section 4.3 example.

    If you disagree with me (I am not a PHP FIG voting member) then the best
    place to
    ask about the standard is on the google groups page:
    https://groups.google.com/forum/?fromgroups=#!forum/php-fig-cs

    Note this is a new group they started to remove the CS discussions from
    the main
    group, so it is currently empty. But someone has to be the first to post
    :)


    Previous Comments:
    ------------------------------------------------------------------------

    [2013-01-23 16:50:23] mplx

    <?php
    public function foo ($arg='default')
    {
    }

    ------------------------------------------------------------------------

    [2013-01-23 16:49:19] mplx

    Testcode:

    <?php
    public function foo ($arg = 'default')
    {
    }

    ------------------------------------------------------------------------

    [2013-01-23 16:39:05] mplx

    Description:
    ------------
    Assignment operations are omitted intentionally from the PSR-2
    ruleset (see PSR-2 chapter 7).

    Current phpcs PSR-2 ruleset however enforces blanks for
    assignment of default values in method arguments.

    See also https://github.com/php-fig/fig-standards/issues/82

    Test script:
    ---------------
    public foo ($arg='default')
    {
    }

    Expected result:
    ----------------
    phpcs considers this valid PSR-2 coding style

    Actual result:
    --------------
    Incorrect spacing between argument "$arg" and equals sign;
    expected 1 but found 0

    Incorrect spacing between default value and equals sign for
    argument "$arg"; expected 1 but found 0

    ------------------------------------------------------------------------
  • Mplx+pear at Jan 24, 2013 at 11:29 pm
    Edit report at https://pear.php.net/bugs/bug.php?id=19798&edit=1

    ID: 19798
    Updated by: mplx+pear@donotreply.at
    Reported By: mplx+pear at donotreply dot at
    Summary: PSR-2: default value assignment in method arguments
    Status: Feedback
    Type: Bug
    Package: PHP_CodeSniffer
    Operating System: Cygwin
    Package Version: 1.4.3
    PHP Version: 5.3.20
    Assigned To: squiz
    Roadmap Versions:
    New Comment:

    Greg, thanks for your comment on this issue. I agree with you that it's
    best
    practice to include spaces and I would prefer it to have it included in
    PSR2 for both
    - default values and variable assignment - to have a consistent
    styling.

    As a lot of other issues related to spacing have their own rules I doubt
    it's valid to
    construct a rule for this specific issue just through some sample code.
    If the styling
    in the sample is part of the guidelines there has to be a rule about
    it.

    In the end I just like to have some clarification about how to refactor
    legacy code
    to valid PSR2 so I'm happy with any solution. Following your advise I'll
    post to the
    Google group.

    Best regards, mplx :)


    Previous Comments:
    ------------------------------------------------------------------------

    [2013-01-23 23:32:19] squiz

    -Status: Open
    +Status: Feedback
    -Assigned To:
    +Assigned To: squiz
    Section 4.3:
    https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-
    coding-style-guide.md#43-methods

    says: "A method declaration looks like the following. Note the placement
    of
    parentheses, commas, spaces, and braces:"

    And is then followed by an example that shows a single space before and
    after the
    equals sign for default values. So when I wrote the standard, I ensured
    that it
    checked for the correct spacing, comma and bracket placement as defined
    in that
    example.

    This is common in many coding standards because a bit of sample code is
    always
    easier to write than a complete list of every rule. Although I still
    need to code in every
    rule when I do a standard.

    Note that section 7 talks about assignments being excluded, which I
    believe means
    variable assignments and not assignment of default values, as these are
    explicitly
    referred to in the section 4.3 example.

    If you disagree with me (I am not a PHP FIG voting member) then the best
    place to
    ask about the standard is on the google groups page:
    https://groups.google.com/forum/?fromgroups=#!forum/php-fig-cs

    Note this is a new group they started to remove the CS discussions from
    the main
    group, so it is currently empty. But someone has to be the first to post
    :)

    ------------------------------------------------------------------------

    [2013-01-23 16:50:23] mplx

    <?php
    public function foo ($arg='default')
    {
    }

    ------------------------------------------------------------------------

    [2013-01-23 16:49:19] mplx

    Testcode:

    <?php
    public function foo ($arg = 'default')
    {
    }

    ------------------------------------------------------------------------

    [2013-01-23 16:39:05] mplx

    Description:
    ------------
    Assignment operations are omitted intentionally from the PSR-2
    ruleset (see PSR-2 chapter 7).

    Current phpcs PSR-2 ruleset however enforces blanks for
    assignment of default values in method arguments.

    See also https://github.com/php-fig/fig-standards/issues/82

    Test script:
    ---------------
    public foo ($arg='default')
    {
    }

    Expected result:
    ----------------
    phpcs considers this valid PSR-2 coding style

    Actual result:
    --------------
    Incorrect spacing between argument "$arg" and equals sign;
    expected 1 but found 0

    Incorrect spacing between default value and equals sign for
    argument "$arg"; expected 1 but found 0

    ------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedJan 23, '13 at 4:49p
activeJan 24, '13 at 11:29p
posts4
users2
websitepear.php.net

2 users in discussion

Mplx+pear: 3 posts Gsherwood: 1 post

People

Translate

site design / logo © 2022 Grokbase