3 ms·
This illustrates exactly why PHP projects often become such an unmaintainable mess and security hole. This looks like an example collection of PHP worst practic
by rickmb 14y ago
This illustrates exactly why PHP projects often become such an unmaintainable mess and security hole. This looks like an example collection of PHP worst practices.
I mean, what could possibly go wrong with untestable code and unfiltered input...?
- jasonmoo 14y agoNot sure how adding some input filtering and tests would make this an unmaintainable mess..? The code is actually pretty tight and is optimized for empowering a developer rather than inflating the bumpers of your bowling lane.
- andypants 14y agoUntestable code? How is it untestable? Unfiltered input? You realise that this is a router, right? The only 'input' is the URL path. I really wish you could be more specific about these 'worst practices' that make this 91-line library an 'unmaintainable mess and security hole'.
- skrebbel 14y agoThat's not the problem this solves. This is 91 lines of code that solve one problem, routing, and that problem only. You filter input right afterwards. And how is this untestable, exactly? It's really easy to fake http requests in php-cli from a unit test, for instance. And is there any other way you'd want to test a router than by faking php requests? I somewhat wonder whether the fact that this happens to be PHP biased your judgment.
- jakejake 14y agoIf anything I find that a router makes your code easier to test. If you're 100% consistent about using the router to obtain user input, then your code is easy to unit test with a mock router. Routers themselves can be easy to test as well. It's a clean separation of concerns - the router is the only thing that knows about the URL implementation. The rest of the code relies on the router to do that. That's a good practice to me. What would you would consider "best practice" in place of a router?