I'd put the result in a `$flags` variable, and compact the code with less new lines. Same thing for what's inside the `else` block.