converted php logic to Object Oriented