Complex classes like Schema 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 Schema, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
38 | class Schema extends AbstractAsset |
||
39 | { |
||
40 | /** |
||
41 | * The namespaces in this schema. |
||
42 | * |
||
43 | * @var string[] |
||
44 | */ |
||
45 | private $namespaces = []; |
||
46 | |||
47 | /** @var Table[] */ |
||
48 | protected $_tables = []; |
||
49 | |||
50 | /** @var Sequence[] */ |
||
51 | protected $_sequences = []; |
||
52 | |||
53 | /** @var SchemaConfig */ |
||
54 | protected $_schemaConfig = false; |
||
55 | |||
56 | /** |
||
57 | * @param Table[] $tables |
||
58 | * @param Sequence[] $sequences |
||
59 | * @param string[] $namespaces |
||
60 | */ |
||
61 | 1886 | public function __construct( |
|
85 | |||
86 | /** |
||
87 | * @return bool |
||
88 | */ |
||
89 | public function hasExplicitForeignKeyIndexes() |
||
93 | |||
94 | /** |
||
95 | * @return void |
||
96 | * |
||
97 | * @throws SchemaException |
||
98 | */ |
||
99 | 1856 | protected function _addTable(Table $table) |
|
117 | |||
118 | /** |
||
119 | * @return void |
||
120 | * |
||
121 | * @throws SchemaException |
||
122 | */ |
||
123 | 1403 | protected function _addSequence(Sequence $sequence) |
|
140 | |||
141 | /** |
||
142 | * Returns the namespaces of this schema. |
||
143 | * |
||
144 | * @return string[] A list of namespace names. |
||
145 | */ |
||
146 | 1638 | public function getNamespaces() |
|
150 | |||
151 | /** |
||
152 | * Gets all tables of this schema. |
||
153 | * |
||
154 | * @return Table[] |
||
155 | */ |
||
156 | 1644 | public function getTables() |
|
160 | |||
161 | /** |
||
162 | * @param string $tableName |
||
163 | * |
||
164 | * @return Table |
||
165 | * |
||
166 | * @throws SchemaException |
||
167 | */ |
||
168 | 1650 | public function getTable($tableName) |
|
177 | |||
178 | /** |
||
179 | * @param string $name |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | 1707 | private function getFullQualifiedAssetName($name) |
|
193 | |||
194 | /** |
||
195 | * Returns the unquoted representation of a given asset name. |
||
196 | * |
||
197 | * @param string $assetName Quoted or unquoted representation of an asset name. |
||
198 | * |
||
199 | * @return string |
||
200 | */ |
||
201 | 1717 | private function getUnquotedAssetName($assetName) |
|
209 | |||
210 | /** |
||
211 | * Does this schema have a namespace with the given name? |
||
212 | * |
||
213 | * @param string $namespaceName |
||
214 | * |
||
215 | * @return bool |
||
216 | */ |
||
217 | 1253 | public function hasNamespace($namespaceName) |
|
223 | |||
224 | /** |
||
225 | * Does this schema have a table with the given name? |
||
226 | * |
||
227 | * @param string $tableName |
||
228 | * |
||
229 | * @return bool |
||
230 | */ |
||
231 | 1679 | public function hasTable($tableName) |
|
237 | |||
238 | /** |
||
239 | * Gets all table names, prefixed with a schema name, even the default one if present. |
||
240 | * |
||
241 | * @return string[] |
||
242 | */ |
||
243 | public function getTableNames() |
||
247 | |||
248 | /** |
||
249 | * @param string $sequenceName |
||
250 | * |
||
251 | * @return bool |
||
252 | */ |
||
253 | 1276 | public function hasSequence($sequenceName) |
|
259 | |||
260 | /** |
||
261 | * @param string $sequenceName |
||
262 | * |
||
263 | * @return Sequence |
||
264 | * |
||
265 | * @throws SchemaException |
||
266 | */ |
||
267 | 1193 | public function getSequence($sequenceName) |
|
276 | |||
277 | /** |
||
278 | * @return Sequence[] |
||
279 | */ |
||
280 | 1642 | public function getSequences() |
|
284 | |||
285 | /** |
||
286 | * Creates a new namespace. |
||
287 | * |
||
288 | * @param string $namespaceName The name of the namespace to create. |
||
289 | * |
||
290 | * @return \Doctrine\DBAL\Schema\Schema This schema instance. |
||
291 | * |
||
292 | * @throws SchemaException |
||
293 | */ |
||
294 | 1293 | public function createNamespace($namespaceName) |
|
306 | |||
307 | /** |
||
308 | * Creates a new table. |
||
309 | * |
||
310 | * @param string $tableName |
||
311 | * |
||
312 | * @return Table |
||
313 | */ |
||
314 | 1819 | public function createTable($tableName) |
|
325 | |||
326 | /** |
||
327 | * Renames a table. |
||
328 | * |
||
329 | * @param string $oldTableName |
||
330 | * @param string $newTableName |
||
331 | * |
||
332 | * @return \Doctrine\DBAL\Schema\Schema |
||
333 | */ |
||
334 | 752 | public function renameTable($oldTableName, $newTableName) |
|
344 | |||
345 | /** |
||
346 | * Drops a table from the schema. |
||
347 | * |
||
348 | * @param string $tableName |
||
349 | * |
||
350 | * @return \Doctrine\DBAL\Schema\Schema |
||
351 | */ |
||
352 | 760 | public function dropTable($tableName) |
|
360 | |||
361 | /** |
||
362 | * Creates a new sequence. |
||
363 | * |
||
364 | * @param string $sequenceName |
||
365 | * @param int $allocationSize |
||
366 | * @param int $initialValue |
||
367 | * |
||
368 | * @return Sequence |
||
369 | */ |
||
370 | 1276 | public function createSequence($sequenceName, $allocationSize = 1, $initialValue = 1) |
|
377 | |||
378 | /** |
||
379 | * @param string $sequenceName |
||
380 | * |
||
381 | * @return \Doctrine\DBAL\Schema\Schema |
||
382 | */ |
||
383 | 577 | public function dropSequence($sequenceName) |
|
390 | |||
391 | /** |
||
392 | * Returns an array of necessary SQL queries to create the schema on the given platform. |
||
393 | * |
||
394 | * @return string[] |
||
395 | */ |
||
396 | 1773 | public function toSql(AbstractPlatform $platform) |
|
403 | |||
404 | /** |
||
405 | * Return an array of necessary SQL queries to drop the schema on the given platform. |
||
406 | * |
||
407 | * @return string[] |
||
408 | */ |
||
409 | 137 | public function toDropSql(AbstractPlatform $platform) |
|
416 | |||
417 | /** |
||
418 | * @return string[] |
||
419 | */ |
||
420 | 896 | public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) |
|
427 | |||
428 | /** |
||
429 | * @return string[] |
||
430 | */ |
||
431 | public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform) |
||
438 | |||
439 | /** |
||
440 | * @return void |
||
441 | */ |
||
442 | 1786 | public function visit(Visitor $visitor) |
|
460 | |||
461 | /** |
||
462 | * Cloning a Schema triggers a deep clone of all related assets. |
||
463 | * |
||
464 | * @return void |
||
465 | */ |
||
466 | 1434 | public function __clone() |
|
475 | } |
||
476 |
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.