PHP script with algorithm. Design Pattern