I have a factory that implements FactoryInterface, like:
class SomeFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
// the code to create SomeClass instance
}
}
Now, all the code is inside the createService method (multiple ifs, some queries, etc.) which makes the method long and difficult to follow. I'd like to refactor the code by extracting the some pieces of code into separate methods. Problem is for my case, I end up passing the instance of $serviceLocator->getServiceLocator() in each of these methods, which is no problem really, but feels ugly.
I was wondering if there's an elegant way of maybe assigning the attribute of SomeFactory $serviceLocator->getServiceLocator() than just passing it in every extracted method.