I have a project on production for years which I want to modernize and wanted to ask for veteran opinion about what the best practice would be.
There is an admin panel which is used to manage products of a company. This panel is integrated into 10 different services which are mostly REST APIs; and some are SOAP.
Right now, I am using PHP’s overloading mechanism to avoid code repeating. Each service has its own PHP class in an individual file which then has a RequestConstruction
and RequestParameters
classes.
Each integration class has available methods in RequestParameters
class, to define their own endpoint and parameters. So when an integration class of a service is called, for example to update a product’s name in that service, (for example (new Service)->UpdateProduct(['name' => 'Something'))
, since this method is not defined, __call()
method is called. It maps the UpdateProduct
method’s endpoint and parameters from the RequestParameters
class and then builds the payload using RequestConstruction
. I chose this approach years ago because many methods of these services are very similar. For the sake of DRY principle, I didn’t want to repeat tens of lines of code for all the methods and all the services.
Now I’d like a modern approach respecting SOLID principles. What would be the best code structure? For example I will be writing an Interface (or maybe an abstract class) for the services to implement. And I would probably better ditch the overloading method. But how to avoid code-repeating and ensure code quality in that case?