I am using Netbeans 8.2
for my PHP
project. It was an already build one. When code, I saw so many areas where using if-else
conditions without braces like below.
if(1<2)
echo 'yes';
else
echo 'no';
I don't like this syntax and want to change them to
if(1<2){
echo 'yes';
} else {
echo 'no';
}
Is there any inbuilt option or custom plugin to do the same?
I fixed this issue. Added php-cs-fixer
to Netbeans
. And it fixed the issue. php-cs-fixer
will fix coding standard issues. So the above mentioned is a coding standard issue and php-cs-fixer
fixed it.
I don't think it is possible to automatically correct all if-else statements missing a brace in a single pass, but the functionality to automatically add missing braces on an individual basis for PHP source is built in to NetBeans:
First ensure that if-else
statements without braces are reported:
Then build your project containing if-else
statements without braces:
if-else
braces as errors, so errors were reported on the line following if
and also on the line following else
for the PHP code in the screen shot below:if
statement, but the associated error is now gone.else
statement.This approach is not ideal, but it is reliable, and you only need to got through the exercise once.