Skip to content

BracesFixer#472

Closed
keradus wants to merge 113 commits intoPHP-CS-Fixer:masterfrom
keradus:structure_braces
Closed

BracesFixer#472
keradus wants to merge 113 commits intoPHP-CS-Fixer:masterfrom
keradus:structure_braces

Conversation

@keradus
Copy link
Copy Markdown
Member

@keradus keradus commented Aug 23, 2014

Braces for structure blocks, fix #98

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong indentation

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@stof
Copy link
Copy Markdown
Contributor

stof commented Aug 27, 2014

It looks like applying the new fixer on the project codebase changes lots of files, which looks wrong as I think the codebase already uses brances everywhere. It looks like there is a bug in your fixer

@stof
Copy link
Copy Markdown
Contributor

stof commented Aug 27, 2014

Also, I think it will break for codebases using the following syntax:

if (2 > 1):
    echo 'This is always reached':
    echo 'More code';
endif;

the fixer should take such code into account to avoid breaking it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't you check for $index < count($this) to be safe against exceptions too ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see a case when this will break on valid php code. Could you provide one?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you pass a $startBraceIndex which is not the opening brace, I think it might create weird issues

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually whole project do not validate input parameters, so you can use almost any method in the way to blow up in your face.
It will be added, no harm

@keradus
Copy link
Copy Markdown
Member Author

keradus commented Aug 27, 2014

@stof

  1. applying fixer on codebase - yes, it change a lot. it is not a bug, it just a fixer that is not finish yet. take a look at todo list - probably missing of correct multi-level intend change your code in bad way.
  2. endif etc - argh, ugly syntax. actually consider between learning this fixer or ignore it (without codebreak) and creating new fixer to replace with {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this loop is the same than $tokens->findBracesBlockEnd but using parenthesis instead of braces. I suggest making findBracesBlockEnd able to handle both cases instead

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. thanks ae5d0be

@keradus
Copy link
Copy Markdown
Member Author

keradus commented Aug 28, 2014

fix T_FOR token syntax

@keradus
Copy link
Copy Markdown
Member Author

keradus commented Aug 28, 2014

(just rebase on master)

@keradus
Copy link
Copy Markdown
Member Author

keradus commented Aug 29, 2014

Next to task done:

  • correct multi-level intend
  • make Travis pass

@keradus
Copy link
Copy Markdown
Member Author

keradus commented Aug 29, 2014

@stof
Running fixer on project itself do not change anything now. I think you may run it on your codebase again

Be aware that

if (2 > 1):
    echo 'This is always reached':
    echo 'More code';
endif;

syntax is not touched yet

@stof
Copy link
Copy Markdown
Contributor

stof commented Aug 29, 2014

@keradus I don't have such codebase (the case where it is common to use such syntax is in templates, and I use Twig for that)

@keradus
Copy link
Copy Markdown
Member Author

keradus commented Aug 29, 2014

@stof OK. I think I will ignore this syntax, at least for now. Maybe some day.

The intresting thing is that the fixer do not only add missing braces, but also correct indent inside it ;)

@stof
Copy link
Copy Markdown
Contributor

stof commented Aug 29, 2014

@keradus IMO, changing the if/endif syntax to the brace syntax is a job for a different fixer, as you might now want it globally

@keradus
Copy link
Copy Markdown
Member Author

keradus commented Aug 29, 2014

@stof Then agreed, this fixer should ignore that syntax.
Do you have time to create if ... endif -> if {} fixer ?

@stof
Copy link
Copy Markdown
Contributor

stof commented Sep 8, 2014

👍

@keradus
Copy link
Copy Markdown
Member Author

keradus commented Sep 8, 2014

You are great @Nyholm ! Thanks !

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is not executed on HHVM (3.0.1). T_FINALLY is not defined. I don't know why. Sorry...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally was added in hhvm 3.2.0 btw.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Nyholm !
Then I will just skip test if T_FINALLY is not defined.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T_FINALLY is defined on newer hhvm versions? If not, this is a bug, and should be reported to the hhvm team.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And travis uses hhvm 3.2.0, so how can this be happening?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to HipHop VM 3.2.0 (rel) . Same error there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a genuine bug in hhvm then.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll report it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Nyholm !

@keradus
Copy link
Copy Markdown
Member Author

keradus commented Sep 8, 2014

Wow, I see some ghost comments here ! :D

@keradus
Copy link
Copy Markdown
Member Author

keradus commented Sep 9, 2014

link facebook/hhvm#3703

@keradus
Copy link
Copy Markdown
Member Author

keradus commented Sep 9, 2014

merged

@keradus keradus closed this in 32a4806 Sep 9, 2014
@keradus keradus deleted the structure_braces branch September 9, 2014 18:43
@keradus keradus removed their assignment Nov 6, 2014
@keradus keradus mentioned this pull request Apr 2, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants