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 |
||
21 | class Schema extends \yii\db\Schema |
||
22 | { |
||
23 | /** |
||
24 | * @var array mapping from physical column types (keys) to abstract column types (values) |
||
25 | * Please refer to [CUBRID manual](http://www.cubrid.org/manual/91/en/sql/datatype.html) for |
||
26 | * details on data types. |
||
27 | */ |
||
28 | public $typeMap = [ |
||
29 | // Numeric data types |
||
30 | 'short' => self::TYPE_SMALLINT, |
||
31 | 'smallint' => self::TYPE_SMALLINT, |
||
32 | 'int' => self::TYPE_INTEGER, |
||
33 | 'integer' => self::TYPE_INTEGER, |
||
34 | 'bigint' => self::TYPE_BIGINT, |
||
35 | 'numeric' => self::TYPE_DECIMAL, |
||
36 | 'decimal' => self::TYPE_DECIMAL, |
||
37 | 'float' => self::TYPE_FLOAT, |
||
38 | 'real' => self::TYPE_FLOAT, |
||
39 | 'double' => self::TYPE_DOUBLE, |
||
40 | 'double precision' => self::TYPE_DOUBLE, |
||
41 | 'monetary' => self::TYPE_MONEY, |
||
42 | // Date/Time data types |
||
43 | 'date' => self::TYPE_DATE, |
||
44 | 'time' => self::TYPE_TIME, |
||
45 | 'timestamp' => self::TYPE_TIMESTAMP, |
||
46 | 'datetime' => self::TYPE_DATETIME, |
||
47 | // String data types |
||
48 | 'char' => self::TYPE_CHAR, |
||
49 | 'varchar' => self::TYPE_STRING, |
||
50 | 'char varying' => self::TYPE_STRING, |
||
51 | 'nchar' => self::TYPE_CHAR, |
||
52 | 'nchar varying' => self::TYPE_STRING, |
||
53 | 'string' => self::TYPE_STRING, |
||
54 | // BLOB/CLOB data types |
||
55 | 'blob' => self::TYPE_BINARY, |
||
56 | 'clob' => self::TYPE_BINARY, |
||
57 | // Bit string data types |
||
58 | 'bit' => self::TYPE_INTEGER, |
||
59 | 'bit varying' => self::TYPE_INTEGER, |
||
60 | // Collection data types (considered strings for now) |
||
61 | 'set' => self::TYPE_STRING, |
||
62 | 'multiset' => self::TYPE_STRING, |
||
63 | 'list' => self::TYPE_STRING, |
||
64 | 'sequence' => self::TYPE_STRING, |
||
65 | 'enum' => self::TYPE_STRING, |
||
66 | ]; |
||
67 | /** |
||
68 | * @var array map of DB errors and corresponding exceptions |
||
69 | * If left part is found in DB error message exception class from the right part is used. |
||
70 | */ |
||
71 | public $exceptionMap = [ |
||
72 | 'Operation would have caused one or more unique constraint violations' => IntegrityException::class, |
||
73 | ]; |
||
74 | |||
75 | |||
76 | /** |
||
77 | * @inheritdoc |
||
78 | */ |
||
79 | public function releaseSavepoint($name) |
||
83 | |||
84 | /** |
||
85 | * Quotes a table name for use in a query. |
||
86 | * A simple table name has no schema prefix. |
||
87 | * @param string $name table name |
||
88 | * @return string the properly quoted table name |
||
89 | */ |
||
90 | public function quoteSimpleTableName($name) |
||
94 | |||
95 | /** |
||
96 | * Quotes a column name for use in a query. |
||
97 | * A simple column name has no prefix. |
||
98 | * @param string $name column name |
||
99 | * @return string the properly quoted column name |
||
100 | */ |
||
101 | public function quoteSimpleColumnName($name) |
||
105 | |||
106 | /** |
||
107 | * Creates a query builder for the CUBRID database. |
||
108 | * @return QueryBuilder query builder instance |
||
109 | */ |
||
110 | public function createQueryBuilder() |
||
114 | |||
115 | /** |
||
116 | * Loads the metadata for the specified table. |
||
117 | * @param string $name table name |
||
118 | * @return TableSchema driver dependent table metadata. Null if the table does not exist. |
||
119 | */ |
||
120 | protected function loadTableSchema($name) |
||
166 | |||
167 | /** |
||
168 | * Loads the column information into a [[ColumnSchema]] object. |
||
169 | * @param array $info column information |
||
170 | * @return ColumnSchema the column schema object |
||
171 | */ |
||
172 | protected function loadColumnSchema($info) |
||
237 | |||
238 | /** |
||
239 | * Returns all table names in the database. |
||
240 | * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
||
241 | * @return array all table names in the database. The names have NO schema name prefix. |
||
242 | */ |
||
243 | protected function findTableNames($schema = '') |
||
257 | |||
258 | /** |
||
259 | * Determines the PDO type for the given PHP data value. |
||
260 | * @param mixed $data the data whose PDO type is to be determined |
||
261 | * @return integer the PDO type |
||
262 | * @see http://www.php.net/manual/en/pdo.constants.php |
||
263 | */ |
||
264 | public function getPdoType($data) |
||
278 | |||
279 | /** |
||
280 | * @inheritdoc |
||
281 | * @see http://www.cubrid.org/manual/91/en/sql/transaction.html#database-concurrency |
||
282 | */ |
||
283 | public function setTransactionIsolationLevel($level) |
||
302 | |||
303 | /** |
||
304 | * @inheritdoc |
||
305 | */ |
||
306 | public function createColumnSchemaBuilder($type, $length = null) |
||
310 | } |
||
311 |