Yet the code in the question isn't simple. It's 180 lines of code that mostly duplicates 2 built-in php functions. To wrap the functionality in a class, simple would be (example and almost pseudo-code):
Also from the question, the class:
relies a lot on that functionality (eg the Router class and some HTML helpers)
Yet the code in the question has no dependencies at all. That kind of implies that the class may not actually fit the purpose it has been written for.
In this way the embedded logic in the build method is separated and more obvious - and the repetative in_array
!empty
logic is avoided. It also becomes possible to run the _prepare
function whenever the data changes rather than each time a call is made to return output.