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 |
||
27 | class Schema extends \yii\db\Schema implements ConstraintFinderInterface |
||
28 | { |
||
29 | use ConstraintFinderTrait; |
||
30 | |||
31 | /** |
||
32 | * @var array mapping from physical column types (keys) to abstract column types (values) |
||
33 | * Please refer to [CUBRID manual](http://www.cubrid.org/manual/91/en/sql/datatype.html) for |
||
34 | * details on data types. |
||
35 | */ |
||
36 | public $typeMap = [ |
||
37 | // Numeric data types |
||
38 | 'short' => self::TYPE_SMALLINT, |
||
39 | 'smallint' => self::TYPE_SMALLINT, |
||
40 | 'int' => self::TYPE_INTEGER, |
||
41 | 'integer' => self::TYPE_INTEGER, |
||
42 | 'bigint' => self::TYPE_BIGINT, |
||
43 | 'numeric' => self::TYPE_DECIMAL, |
||
44 | 'decimal' => self::TYPE_DECIMAL, |
||
45 | 'float' => self::TYPE_FLOAT, |
||
46 | 'real' => self::TYPE_FLOAT, |
||
47 | 'double' => self::TYPE_DOUBLE, |
||
48 | 'double precision' => self::TYPE_DOUBLE, |
||
49 | 'monetary' => self::TYPE_MONEY, |
||
50 | // Date/Time data types |
||
51 | 'date' => self::TYPE_DATE, |
||
52 | 'time' => self::TYPE_TIME, |
||
53 | 'timestamp' => self::TYPE_TIMESTAMP, |
||
54 | 'datetime' => self::TYPE_DATETIME, |
||
55 | // String data types |
||
56 | 'char' => self::TYPE_CHAR, |
||
57 | 'varchar' => self::TYPE_STRING, |
||
58 | 'char varying' => self::TYPE_STRING, |
||
59 | 'nchar' => self::TYPE_CHAR, |
||
60 | 'nchar varying' => self::TYPE_STRING, |
||
61 | 'string' => self::TYPE_STRING, |
||
62 | // BLOB/CLOB data types |
||
63 | 'blob' => self::TYPE_BINARY, |
||
64 | 'clob' => self::TYPE_BINARY, |
||
65 | // Bit string data types |
||
66 | 'bit' => self::TYPE_INTEGER, |
||
67 | 'bit varying' => self::TYPE_INTEGER, |
||
68 | // Collection data types (considered strings for now) |
||
69 | 'set' => self::TYPE_STRING, |
||
70 | 'multiset' => self::TYPE_STRING, |
||
71 | 'list' => self::TYPE_STRING, |
||
72 | 'sequence' => self::TYPE_STRING, |
||
73 | 'enum' => self::TYPE_STRING, |
||
74 | ]; |
||
75 | /** |
||
76 | * @var array map of DB errors and corresponding exceptions |
||
77 | * If left part is found in DB error message exception class from the right part is used. |
||
78 | */ |
||
79 | public $exceptionMap = [ |
||
80 | 'Operation would have caused one or more unique constraint violations' => 'yii\db\IntegrityException', |
||
81 | ]; |
||
82 | |||
83 | /** |
||
84 | * @inheritDoc |
||
85 | */ |
||
86 | protected $tableQuoteCharacter = '"'; |
||
87 | |||
88 | /** |
||
89 | * @inheritDoc |
||
90 | */ |
||
91 | protected function findTableNames($schema = '') |
||
105 | |||
106 | /** |
||
107 | * @inheritDoc |
||
108 | */ |
||
109 | protected function loadTableSchema($name) |
||
154 | |||
155 | /** |
||
156 | * @inheritDoc |
||
157 | */ |
||
158 | protected function loadTablePrimaryKey($tableName) |
||
171 | |||
172 | /** |
||
173 | * @inheritDoc |
||
174 | */ |
||
175 | protected function loadTableForeignKeys($tableName) |
||
201 | |||
202 | /** |
||
203 | * @inheritDoc |
||
204 | */ |
||
205 | protected function loadTableIndexes($tableName) |
||
209 | |||
210 | /** |
||
211 | * @inheritDoc |
||
212 | */ |
||
213 | protected function loadTableUniques($tableName) |
||
217 | |||
218 | /** |
||
219 | * @inheritDoc |
||
220 | * @throws NotSupportedException if this method is called. |
||
221 | */ |
||
222 | protected function loadTableChecks($tableName) |
||
226 | |||
227 | /** |
||
228 | * @inheritDoc |
||
229 | * @throws NotSupportedException if this method is called. |
||
230 | */ |
||
231 | protected function loadTableDefaultValues($tableName) |
||
235 | |||
236 | /** |
||
237 | * {@inheritdoc} |
||
238 | */ |
||
239 | public function releaseSavepoint($name) |
||
243 | |||
244 | /** |
||
245 | * Creates a query builder for the CUBRID database. |
||
246 | * @return QueryBuilder query builder instance |
||
247 | */ |
||
248 | public function createQueryBuilder() |
||
252 | |||
253 | /** |
||
254 | * Loads the column information into a [[ColumnSchema]] object. |
||
255 | * @param array $info column information |
||
256 | * @return \yii\db\ColumnSchema the column schema object |
||
257 | */ |
||
258 | protected function loadColumnSchema($info) |
||
323 | |||
324 | /** |
||
325 | * Determines the PDO type for the given PHP data value. |
||
326 | * @param mixed $data the data whose PDO type is to be determined |
||
327 | * @return int the PDO type |
||
328 | * @see http://www.php.net/manual/en/pdo.constants.php |
||
329 | */ |
||
330 | public function getPdoType($data) |
||
344 | |||
345 | /** |
||
346 | * {@inheritdoc} |
||
347 | * @see http://www.cubrid.org/manual/91/en/sql/transaction.html#database-concurrency |
||
348 | */ |
||
349 | public function setTransactionIsolationLevel($level) |
||
368 | |||
369 | /** |
||
370 | * {@inheritdoc} |
||
371 | */ |
||
372 | public function createColumnSchemaBuilder($type, $length = null) |
||
376 | |||
377 | /** |
||
378 | * Loads multiple types of constraints and returns the specified ones. |
||
379 | * @param string $tableName table name. |
||
380 | * @param string $returnType return type: |
||
381 | * - indexes |
||
382 | * - uniques |
||
383 | * @return mixed constraints. |
||
384 | */ |
||
385 | private function loadTableConstraints($tableName, $returnType) |
||
417 | } |
||
418 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.