Comments (16)
@breerly could you provide a PSR rule for that ?
from php-cs-fixer.
Probably not, haven't been using PHP lately.
from php-cs-fixer.
This would still be a good contrib fixer, or even symfony level?
from php-cs-fixer.
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.
++$i
is technically different though.
from php-cs-fixer.
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.
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.
Operators like <
aren't relevant here.
Example didn't say that one should use post- or pre- incrementation.
from php-cs-fixer.
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.
@vbence most of the cases in your comment are already fixed by the fixer enforcing spaces around binary operators
from php-cs-fixer.
@stof I think operators_spaces [symfony] is the one, but it is outside PSR-2 level.
from php-cs-fixer.
@vbence indeed, because PSR-2 does not define any rules about using spaces or no around operators.
from php-cs-fixer.
@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.
@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.
This issue is fixed by #1064 and can be closed.
from php-cs-fixer.
Thank you. Closing
from php-cs-fixer.
Related Issues (20)
- no_trailing_whitespace_in_string new parameter to allow single white space if it exists HOT 6
- [InvalidArgumentException] Token at index xx is not the start of an alternative syntax block. HOT 1
- multiline_whitespace_before_semicolons behaves inconsistently with multline conditions
- Option's deprecation warning is misplaced in docs HOT 5
- `statement_indentation`: indents on multiline class properties HOT 3
- `switch` should be followed by a space HOT 5
- no_unused_imports does not remove some unused imports HOT 2
- Separat sorting for enum cases HOT 1
- "no-return" phpdoc not removed because superflous HOT 9
- Remove or add redundant `readonly` property modifier HOT 4
- ClassAttributesSeparationFixer - ['property' => 'none'] Add unwanted blank line when comment present
- Allow custom assertion methods in php_unit_test_case_static_method_calls
- Init command HOT 1
- Enum ordering support
- Bug in PHP-CS-Fixer with Laravel Pint 1.13.7 and php_unit_method_casing HOT 3
- `FullyQualifiedStrictTypesFixer` adds imports before PHP opening tag HOT 2
- Install now: 404 HOT 2
- `PhpUnitAttributesFixer` - ability to keep annotations HOT 1
- Please improve the documentation HOT 2
- PhpUnitDedicateAssertFixer is replacing functions with deprecated/removed method names of PHPUnit v9.1+
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-cs-fixer.