Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple catch blocks not checked in Squiz.ControlStructures.ControlSignature sniff #551

Closed
fbourigault opened this issue Apr 15, 2015 · 4 comments

Comments

@fbourigault
Copy link

In PSR2, multiple catches block must be like this:

<?php
try {
    // try body
} catch (FirstExceptionType $e) {
    // catch body
} catch (OtherExceptionType $e) {
    // catch body
}

but phpcs --standard-PSR2 is ok with the following code:

<?php
try {
    // try body
} catch (FirstExceptionType $e) {
    // catch body
}
catch (OtherExceptionType $e) {
    // catch body
}

Bug is present in 2.3.0 and master

@aik099
Copy link
Contributor

aik099 commented Apr 15, 2015

Appears like catch statement formatting isn't checked at all. Can you please post a link in the PSR-2 specification where it describes how catch should be formatted?

@fbourigault
Copy link
Author

When you run phpcs --standard=PSR2 against the following code, it throw this error: Expected 1 space after closing brace; newline found

<?php
try {
    // try body
}
catch (FirstExceptionType $e) {
    // catch body
}

PSR2 about try, catch : https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md#56-try-catch

@aik099
Copy link
Contributor

aik099 commented Apr 15, 2015

I see. The subsequential catch statements are ignored then.

@gsherwood gsherwood changed the title PSR2 multiple catch Multiple catch blocks not checked in Squiz.ControlStructures.ControlSignature sniff Apr 15, 2015
gsherwood added a commit that referenced this issue Apr 15, 2015
@gsherwood
Copy link
Member

Thanks for reporting this. It has been fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants