Giter Site home page Giter Site logo

Comments (16)

keradus avatar keradus commented on May 3, 2024

@breerly could you provide a PSR rule for that ?

from php-cs-fixer.

HelloGrayson avatar HelloGrayson commented on May 3, 2024

Probably not, haven't been using PHP lately.

from php-cs-fixer.

GrahamCampbell avatar GrahamCampbell commented on May 3, 2024

This would still be a good contrib fixer, or even symfony level?

from php-cs-fixer.

keradus avatar keradus commented on May 3, 2024

Yes.
I would even changed it into ++$i

Nevertheless it is a nice info is this should be at PSR level or not.

from php-cs-fixer.

GrahamCampbell avatar GrahamCampbell commented on May 3, 2024

++$i is technically different though.

from php-cs-fixer.

keradus avatar keradus commented on May 3, 2024

Yes. You can change blindly $a ++ into $a++.

And you can also change knowingly $a++ into ++$a - eg already provided by @breerly ;)

from php-cs-fixer.

vbence avatar vbence commented on May 3, 2024

It does not say, just gives an example, which is quite insufficient knowing the various uses of the C-style for loop.

What I get away from this:

  • Operators with two operands (= < > etc.) should be surrounded by spaces (I wonder if this is not covered elsewhere).
  • There should be no space between the variable and the ++.

Excerpt from PSR-2:

5.4. for

A for statement looks like the following. Note the placement of parentheses,
spaces, and braces.

<?php
for ($i = 0; $i < 10; $i++) {
    // for body
}

from php-cs-fixer.

keradus avatar keradus commented on May 3, 2024

Operators like < aren't relevant here.
Example didn't say that one should use post- or pre- incrementation.

from php-cs-fixer.

vbence avatar vbence commented on May 3, 2024

I think the whole spacing issue in a for loop deserves to be looked at. Whether or not pre-incrementation is allowed I think the following examples are all wrong:

// too many spaces
for ($i = 0; $i < 10; $i ++) {

// too many spaces
for ($i = 0; $i < 10; ++ $i) {

// too few spaces
for ($i=0; $i<10; $i++) {

// incredibly few spaces
for ($i=0;$i<10;$i++) {

from php-cs-fixer.

stof avatar stof commented on May 3, 2024

@vbence most of the cases in your comment are already fixed by the fixer enforcing spaces around binary operators

from php-cs-fixer.

vbence avatar vbence commented on May 3, 2024

@stof I think operators_spaces [symfony] is the one, but it is outside PSR-2 level.

from php-cs-fixer.

stof avatar stof commented on May 3, 2024

@vbence indeed, because PSR-2 does not define any rules about using spaces or no around operators.

from php-cs-fixer.

vbence avatar vbence commented on May 3, 2024

@stof I guess it's up for interpretation. I quoted the doc in my first comment.

Are you saying the following is valid PSR2?

   for ($i=0;$i<10;$i ++) {

from php-cs-fixer.

stof avatar stof commented on May 3, 2024

@vbence read what the section 5 is defining in the spec. Your snippet is technically valid, because it has the parentheses, braces and spaces in the places defined in the spec. The section 5 is not about spaces around operators or between statements (Symfony on the other hand defines such a rule, making your snippet invalid for the Symfony coding standards)

from php-cs-fixer.

gharlan avatar gharlan commented on May 3, 2024

This issue is fixed by #1064 and can be closed.

from php-cs-fixer.

keradus avatar keradus commented on May 3, 2024

Thank you. Closing

from php-cs-fixer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.