Closed (works as designed)
Project:
Coder
Version:
8.x-2.x-dev
Component:
Coder Sniffer
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
21 Aug 2016 at 10:47 UTC
Updated:
18 Sep 2016 at 20:11 UTC
Jump to comment: Most recent
Comments
Comment #2
alexpottLooking at part of the problem I think core is the issue - we shouldn't break PSR-0/4 in runtime code and tests are just doing it wrong. See #2572801-41: Fix 'Drupal.WhiteSpace.ScopeIndent' coding standard, #2787577: When tests use multiple namespaces they should do so in a coding standards compliant way and #2787567: Refactor \Drupal\Component\Assertion\Handle to not break PSR-0/4 one class per file
Comment #3
alexpottI think for part two we might need to get Drupal.WhiteSpace.ScopeClosingBrace.BreakIndent working on core.
Comment #4
klausiThe problem with the break statements in this case is that they are unreachable code and should be removed. They can never be executed after the return statement has happened.
I understand why they are there for readability purposes, so yes we should somehow fix this.
Namespaces: we should not use braces for them at all. In PHP any new namespace declaration just switches the namespace, so no braces necessary.
Comment #5
klausiOK, for the global namespace you probably need the braces, but otherwise we can do this:
Comment #6
alexpott@klausi great minds :) #2787577: When tests use multiple namespaces they should do so in a coding standards compliant way
Comment #7
alexpottI'm coming round to thinking that we should remove the breaks if they are unreachable code. It just adds noise.
Comment #8
alexpottThere is nothing in https://www.drupal.org/coding-standards#controlstruct mandating the use of a break - but the example hints that it might have to be there.
Comment #9
eric_a commentedThe break keyword is nice when scanning for code paths. Getting rid of the early returns could be the solution that makes everybody happy - set one variable for each case and return once.
Comment #10
klausiSo we removed the unreachable break statements in core as solution, nothing we need to do in Coder.