Complex classes like MonologServiceFactory often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MonologServiceFactory, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class MonologServiceFactory implements FactoryInterface |
||
|
|||
20 | { |
||
21 | |||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | * @throws \Interop\Container\Exception\ContainerException |
||
25 | * @throws \RuntimeException |
||
26 | * @throws \Interop\Container\Exception\NotFoundException |
||
27 | */ |
||
28 | 2 | public function createService(ServiceLocatorInterface $serviceLocator) |
|
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | * @throws \Interop\Container\Exception\NotFoundException |
||
38 | * @throws \RuntimeException |
||
39 | */ |
||
40 | public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
||
46 | |||
47 | /** |
||
48 | * @param ServiceLocatorInterface|ContainerInterface $container |
||
49 | * @param MonologOptions $options |
||
50 | * @return Logger |
||
51 | * @throws \Interop\Container\Exception\NotFoundException |
||
52 | * @throws \RuntimeException |
||
53 | * @throws \Interop\Container\Exception\ContainerException |
||
54 | */ |
||
55 | 3 | public function createLogger($container, MonologOptions $options) |
|
70 | |||
71 | /** |
||
72 | * @param ServiceLocatorInterface|ContainerInterface $container |
||
73 | * @param MonologOptions $options |
||
74 | * @param string|array $handler |
||
75 | * @throws \RuntimeException |
||
76 | * @return HandlerInterface |
||
77 | * @throws \Interop\Container\Exception\NotFoundException |
||
78 | * @throws \Interop\Container\Exception\ContainerException |
||
79 | * |
||
80 | */ |
||
81 | 12 | public function createHandler($container, MonologOptions $options, $handler) |
|
130 | |||
131 | /** |
||
132 | * @param ServiceLocatorInterface|ContainerInterface $container |
||
133 | * @param string|array $formatter |
||
134 | * @return FormatterInterface |
||
135 | * @throws \Interop\Container\Exception\NotFoundException |
||
136 | * @throws \Interop\Container\Exception\ContainerException |
||
137 | * @throws RuntimeException |
||
138 | */ |
||
139 | 8 | public function createFormatter($container, $formatter) |
|
173 | |||
174 | /** |
||
175 | * @param ServiceLocatorInterface|ContainerInterface $container |
||
176 | * @param $processor |
||
177 | * @return Closure |
||
178 | * @throws \Interop\Container\Exception\NotFoundException |
||
179 | * @throws \Interop\Container\Exception\ContainerException |
||
180 | * @throws RuntimeException |
||
181 | */ |
||
182 | 5 | public function createProcessor($container, $processor) |
|
208 | |||
209 | /** |
||
210 | * Handles the constructor arguments and if they're named, just sort them to fit constructor ordering. |
||
211 | * |
||
212 | * @param string $className |
||
213 | * @param array $arguments |
||
214 | * |
||
215 | * @return object |
||
216 | * @throws \InvalidArgumentException If given arguments are not valid for provided className constructor. |
||
217 | */ |
||
218 | 11 | private function createInstanceFromArguments($className, array $arguments) |
|
275 | } |
||
276 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.