DEV Community

loading...

Discussion on: Writing Clean Code

Collapse
rafaacioly profile image
Rafael Acioly

Hi Jason, great article congratulations.
By the way, i did not see anything commenting about this so there it go, you can clean even more replacing the 3 ifs with a single switch using multiple case validation like this;

switch ($scope) {
    case 'public':
    case 'private' && Auth::user()->id === $owner_id:
    case Auth::user()->hasRole('admin'):
        return true;
    default:
        return false;
}


`

let me know what you think.

Collapse
gonedark profile image
Jason McCreary Author

The original code (from Part 1) was a switch statement. Personally, I don't find switch statements very readable. Especially with conditions in the case.

Collapse
rafaacioly profile image
Rafael Acioly

Cool!
I prefer "switch" because i like to write return true only one time. 😁