[CCA Standards] Was missfällt an PSR-1 und PSR-2 :: brace placement

Tristan Lins tristan.lins at bit3.de
Fr Mai 2 10:26:29 CEST 2014


[PSR-2] 1. Overview #2

> Opening braces for control structures MUST go on the same line, ...

Bzgl. der öffnenden Klammer stimme ich dem zu, aber die schließende
Klammer sollte imo eine eigene Zeile bekommen.

Also

> if (...) {
>     ...
> }
> else {
>     ...
> }

anstatt

> if (...) {
>     ...
> } else {
>     ...
> }

Begründung: Wenn man die "Einrückungslinie" entlang geht, kann man so
besser lesen, wo das if anfängt und wo der nächste elseif/else Block
anfängt, als wenn vor dem elseif/else erst noch eine "störende" } steht.

-----

Duplicate: [PSR-2] 5.1. if, elseif, else

> Note the placement of parentheses, spaces, and braces; and that else
> and elseif are on the same line as the closing brace from the earlier
> body.

-----

[PSR-2] 5.3. while, do while

> ... Note the placement of parentheses, spaces, and braces.

Auch hier gehört das while imo in eine eigene Zeile.

Also

> do {
>     // structure body;
> }
> while ($expr);

anstatt

> do {
>     // structure body;
> } while ($expr);

Begründung: s.o.

-----

[PSR-2] 5.6. try, catch

> ... Note the placement of parentheses, spaces, and braces.

Auch hier gehören die catch'es in eine eigene Zeile.

Also

> try {
>     // try body
> }
> catch (FirstExceptionType $e) {
>     // catch body
> }
> catch (OtherExceptionType $e) {
>     // catch body
> }

anstatt

> try {
>     // try body
> } catch (FirstExceptionType $e) {
>     // catch body
> } catch (OtherExceptionType $e) {
>     // catch body
> }

Begründung: s.o.

-- 
Tristan Lins - Inhaber, Softwareentwickler
bit3 UG (haftungsbeschränkt)
Im Coenen Palais · Hofstr. 272 · 56077 Koblenz
info at bit3.de · http://bit3.de · 0261-45093253
Amtsgericht Koblenz, HRB 23386


More information about the Standards mailing list