Over-engineered calculation in PHP!