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 |
||
26 | class Schema extends \yii\db\Schema |
||
27 | { |
||
28 | use ConstraintFinderTrait; |
||
29 | |||
30 | /** |
||
31 | * @var array mapping from physical column types (keys) to abstract column types (values) |
||
32 | * Please refer to [CUBRID manual](http://www.cubrid.org/manual/91/en/sql/datatype.html) for |
||
33 | * details on data types. |
||
34 | */ |
||
35 | public $typeMap = [ |
||
36 | // Numeric data types |
||
37 | 'short' => self::TYPE_SMALLINT, |
||
38 | 'smallint' => self::TYPE_SMALLINT, |
||
39 | 'int' => self::TYPE_INTEGER, |
||
40 | 'integer' => self::TYPE_INTEGER, |
||
41 | 'bigint' => self::TYPE_BIGINT, |
||
42 | 'numeric' => self::TYPE_DECIMAL, |
||
43 | 'decimal' => self::TYPE_DECIMAL, |
||
44 | 'float' => self::TYPE_FLOAT, |
||
45 | 'real' => self::TYPE_FLOAT, |
||
46 | 'double' => self::TYPE_DOUBLE, |
||
47 | 'double precision' => self::TYPE_DOUBLE, |
||
48 | 'monetary' => self::TYPE_MONEY, |
||
49 | // Date/Time data types |
||
50 | 'date' => self::TYPE_DATE, |
||
51 | 'time' => self::TYPE_TIME, |
||
52 | 'timestamp' => self::TYPE_TIMESTAMP, |
||
53 | 'datetime' => self::TYPE_DATETIME, |
||
54 | // String data types |
||
55 | 'char' => self::TYPE_CHAR, |
||
56 | 'varchar' => self::TYPE_STRING, |
||
57 | 'char varying' => self::TYPE_STRING, |
||
58 | 'nchar' => self::TYPE_CHAR, |
||
59 | 'nchar varying' => self::TYPE_STRING, |
||
60 | 'string' => self::TYPE_STRING, |
||
61 | // BLOB/CLOB data types |
||
62 | 'blob' => self::TYPE_BINARY, |
||
63 | 'clob' => self::TYPE_BINARY, |
||
64 | // Bit string data types |
||
65 | 'bit' => self::TYPE_INTEGER, |
||
66 | 'bit varying' => self::TYPE_INTEGER, |
||
67 | // Collection data types (considered strings for now) |
||
68 | 'set' => self::TYPE_STRING, |
||
69 | 'multiset' => self::TYPE_STRING, |
||
70 | 'list' => self::TYPE_STRING, |
||
71 | 'sequence' => self::TYPE_STRING, |
||
72 | 'enum' => self::TYPE_STRING, |
||
73 | ]; |
||
74 | /** |
||
75 | * @var array map of DB errors and corresponding exceptions |
||
76 | * If left part is found in DB error message exception class from the right part is used. |
||
77 | */ |
||
78 | public $exceptionMap = [ |
||
79 | 'Operation would have caused one or more unique constraint violations' => 'yii\db\IntegrityException', |
||
80 | ]; |
||
81 | |||
82 | |||
83 | /** |
||
84 | * @inheritDoc |
||
85 | */ |
||
86 | protected function findTableNames($schema = '') |
||
100 | |||
101 | /** |
||
102 | * @inheritDoc |
||
103 | */ |
||
104 | protected function loadTableSchema($name) |
||
149 | |||
150 | /** |
||
151 | * @inheritDoc |
||
152 | */ |
||
153 | protected function loadTablePrimaryKey($tableName) |
||
166 | |||
167 | /** |
||
168 | * @inheritDoc |
||
169 | */ |
||
170 | protected function loadTableForeignKeys($tableName) |
||
195 | |||
196 | /** |
||
197 | * @inheritDoc |
||
198 | */ |
||
199 | protected function loadTableIndexes($tableName) |
||
203 | |||
204 | /** |
||
205 | * @inheritDoc |
||
206 | */ |
||
207 | protected function loadTableUniques($tableName) |
||
211 | |||
212 | /** |
||
213 | * @inheritDoc |
||
214 | * @throws NotSupportedException if this method is called. |
||
215 | */ |
||
216 | protected function loadTableChecks($tableName) |
||
220 | |||
221 | /** |
||
222 | * @inheritDoc |
||
223 | * @throws NotSupportedException if this method is called. |
||
224 | */ |
||
225 | protected function loadTableDefaultValues($tableName) |
||
229 | |||
230 | /** |
||
231 | * @inheritdoc |
||
232 | */ |
||
233 | public function releaseSavepoint($name) |
||
237 | |||
238 | /** |
||
239 | * Quotes a table name for use in a query. |
||
240 | * A simple table name has no schema prefix. |
||
241 | * @param string $name table name |
||
242 | * @return string the properly quoted table name |
||
243 | */ |
||
244 | public function quoteSimpleTableName($name) |
||
248 | |||
249 | /** |
||
250 | * Quotes a column name for use in a query. |
||
251 | * A simple column name has no prefix. |
||
252 | * @param string $name column name |
||
253 | * @return string the properly quoted column name |
||
254 | */ |
||
255 | public function quoteSimpleColumnName($name) |
||
259 | |||
260 | /** |
||
261 | * Creates a query builder for the CUBRID database. |
||
262 | * @return QueryBuilder query builder instance |
||
263 | */ |
||
264 | public function createQueryBuilder() |
||
268 | |||
269 | /** |
||
270 | * Loads the column information into a [[ColumnSchema]] object. |
||
271 | * @param array $info column information |
||
272 | * @return \yii\db\ColumnSchema the column schema object |
||
273 | */ |
||
274 | protected function loadColumnSchema($info) |
||
339 | |||
340 | /** |
||
341 | * Determines the PDO type for the given PHP data value. |
||
342 | * @param mixed $data the data whose PDO type is to be determined |
||
343 | * @return int the PDO type |
||
344 | * @see http://www.php.net/manual/en/pdo.constants.php |
||
345 | */ |
||
346 | public function getPdoType($data) |
||
360 | |||
361 | /** |
||
362 | * @inheritdoc |
||
363 | * @see http://www.cubrid.org/manual/91/en/sql/transaction.html#database-concurrency |
||
364 | */ |
||
365 | public function setTransactionIsolationLevel($level) |
||
384 | |||
385 | /** |
||
386 | * @inheritdoc |
||
387 | */ |
||
388 | public function createColumnSchemaBuilder($type, $length = null) |
||
392 | |||
393 | /** |
||
394 | * Loads multiple types of constraints and returns the specified ones. |
||
395 | * @param string $tableName table name. |
||
396 | * @param string $returnType return type: |
||
397 | * - indexes |
||
398 | * - uniques |
||
399 | * @return mixed constraints. |
||
400 | */ |
||
401 | private function loadTableConstraints($tableName, $returnType) |
||
432 | } |
||
433 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.