Complex classes like MongoDbServiceProvider 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 MongoDbServiceProvider, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class MongoDbServiceProvider implements ServiceProviderInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var array Buffer. |
||
23 | */ |
||
24 | private $args = array(); |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | private $defaultArgs = array( |
||
30 | 'uri_options' => array(), |
||
31 | 'driver_options' => array(), |
||
32 | ); |
||
33 | |||
34 | /** |
||
35 | * @var int|string |
||
36 | */ |
||
37 | private $defaultConnection = 0; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | private $id = 'mongodb'; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | private $instances = 'mongodb.clients'; |
||
48 | |||
49 | /** |
||
50 | * @var bool |
||
51 | */ |
||
52 | private $isLoaded = false; |
||
53 | |||
54 | /** |
||
55 | * @var array |
||
56 | */ |
||
57 | private $parameters = array(); |
||
58 | |||
59 | /** |
||
60 | * @param string $id |
||
61 | * @param string $instances |
||
62 | */ |
||
63 | public function __construct($id = null, $instances = null) |
||
72 | |||
73 | /** |
||
74 | * @return string |
||
75 | */ |
||
76 | private function buildConnectionString(array $connection) |
||
98 | |||
99 | /** |
||
100 | * @param array|string $connection |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | private function buildUri($connection) |
||
108 | |||
109 | /** |
||
110 | * @param \Pimple\Container $app |
||
111 | * @param string $name |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | private function getArg(Container $app, $name) |
||
119 | |||
120 | private function getArgConnectionAuthority(array $connection) |
||
134 | |||
135 | /** |
||
136 | * @return string |
||
137 | */ |
||
138 | private function getArgConnectionHost(array $connection = array()) |
||
146 | |||
147 | private function getArgConnectionHosts(array $connection) |
||
157 | |||
158 | /** |
||
159 | * @return string |
||
160 | */ |
||
161 | private function getArgUri(Container $app) |
||
169 | |||
170 | /** |
||
171 | * @param \Pimple\Container $app |
||
172 | * @param string $name |
||
173 | * |
||
174 | * @return string|array |
||
175 | */ |
||
176 | private function getDefaultArg(Container $app, $name) |
||
184 | |||
185 | private function loadParameters(Container $app) |
||
200 | |||
201 | private function loadSingletonParameters(Container $app) |
||
218 | |||
219 | /** |
||
220 | * @param string $uri |
||
221 | * |
||
222 | * @return string |
||
223 | */ |
||
224 | private function sanitizeUri($uri) |
||
232 | |||
233 | /** |
||
234 | * @param \Pimple\Container $app |
||
235 | * @param string $name |
||
236 | */ |
||
237 | private function setDefaultArg(Container $app, $name) |
||
243 | |||
244 | public function register(Container $app) |
||
274 | } |
||
275 |