Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like BannersI18nTableMap 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 BannersI18nTableMap, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
29 | class BannersI18nTableMap extends TableMap |
||
30 | { |
||
31 | use InstancePoolTrait; |
||
32 | use TableMapTrait; |
||
33 | |||
34 | /** |
||
35 | * The (dot-path) name of this class |
||
36 | */ |
||
37 | const CLASS_NAME = 'xbanners.models.Map.BannersI18nTableMap'; |
||
38 | |||
39 | /** |
||
40 | * The default database name for this class |
||
41 | */ |
||
42 | const DATABASE_NAME = 'Shop'; |
||
43 | |||
44 | /** |
||
45 | * The table name for this class |
||
46 | */ |
||
47 | const TABLE_NAME = 'banners_i18n'; |
||
48 | |||
49 | /** |
||
50 | * The related Propel class for this table |
||
51 | */ |
||
52 | const OM_CLASS = '\\xbanners\\models\\BannersI18n'; |
||
53 | |||
54 | /** |
||
55 | * A class that can be returned by this tableMap |
||
56 | */ |
||
57 | const CLASS_DEFAULT = 'xbanners.models.BannersI18n'; |
||
58 | |||
59 | /** |
||
60 | * The total number of columns |
||
61 | */ |
||
62 | const NUM_COLUMNS = 3; |
||
63 | |||
64 | /** |
||
65 | * The number of lazy-loaded columns |
||
66 | */ |
||
67 | const NUM_LAZY_LOAD_COLUMNS = 0; |
||
68 | |||
69 | /** |
||
70 | * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) |
||
71 | */ |
||
72 | const NUM_HYDRATE_COLUMNS = 3; |
||
73 | |||
74 | /** |
||
75 | * the column name for the id field |
||
76 | */ |
||
77 | const COL_ID = 'banners_i18n.id'; |
||
78 | |||
79 | /** |
||
80 | * the column name for the locale field |
||
81 | */ |
||
82 | const COL_LOCALE = 'banners_i18n.locale'; |
||
83 | |||
84 | /** |
||
85 | * the column name for the name field |
||
86 | */ |
||
87 | const COL_NAME = 'banners_i18n.name'; |
||
88 | |||
89 | /** |
||
90 | * The default string format for model objects of the related table |
||
91 | */ |
||
92 | const DEFAULT_STRING_FORMAT = 'YAML'; |
||
93 | |||
94 | /** |
||
95 | * holds an array of fieldnames |
||
96 | * |
||
97 | * first dimension keys are the type constants |
||
98 | * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' |
||
99 | */ |
||
100 | protected static $fieldNames = array ( |
||
101 | self::TYPE_PHPNAME => array('Id', 'Locale', 'Name', ), |
||
102 | self::TYPE_CAMELNAME => array('id', 'locale', 'name', ), |
||
103 | self::TYPE_COLNAME => array(BannersI18nTableMap::COL_ID, BannersI18nTableMap::COL_LOCALE, BannersI18nTableMap::COL_NAME, ), |
||
104 | self::TYPE_FIELDNAME => array('id', 'locale', 'name', ), |
||
105 | self::TYPE_NUM => array(0, 1, 2, ) |
||
106 | ); |
||
107 | |||
108 | /** |
||
109 | * holds an array of keys for quick access to the fieldnames array |
||
110 | * |
||
111 | * first dimension keys are the type constants |
||
112 | * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 |
||
113 | */ |
||
114 | protected static $fieldKeys = array ( |
||
115 | self::TYPE_PHPNAME => array('Id' => 0, 'Locale' => 1, 'Name' => 2, ), |
||
116 | self::TYPE_CAMELNAME => array('id' => 0, 'locale' => 1, 'name' => 2, ), |
||
117 | self::TYPE_COLNAME => array(BannersI18nTableMap::COL_ID => 0, BannersI18nTableMap::COL_LOCALE => 1, BannersI18nTableMap::COL_NAME => 2, ), |
||
118 | self::TYPE_FIELDNAME => array('id' => 0, 'locale' => 1, 'name' => 2, ), |
||
119 | self::TYPE_NUM => array(0, 1, 2, ) |
||
120 | ); |
||
121 | |||
122 | /** |
||
123 | * Initialize the table attributes and columns |
||
124 | * Relations are not initialized by this method since they are lazy loaded |
||
125 | * |
||
126 | * @return void |
||
127 | * @throws PropelException |
||
128 | */ |
||
129 | public function initialize() |
||
143 | |||
144 | /** |
||
145 | * Build the RelationMap objects for this table relationships |
||
146 | */ |
||
147 | View Code Duplication | public function buildRelations() |
|
157 | |||
158 | /** |
||
159 | * Adds an object to the instance pool. |
||
160 | * |
||
161 | * Propel keeps cached copies of objects in an instance pool when they are retrieved |
||
162 | * from the database. In some cases you may need to explicitly add objects |
||
163 | * to the cache in order to ensure that the same objects are always returned by find*() |
||
164 | * and findPk*() calls. |
||
165 | * |
||
166 | * @param \xbanners\models\BannersI18n $obj A \xbanners\models\BannersI18n object. |
||
167 | * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). |
||
168 | */ |
||
169 | View Code Duplication | public static function addInstanceToPool($obj, $key = null) |
|
178 | |||
179 | /** |
||
180 | * Removes an object from the instance pool. |
||
181 | * |
||
182 | * Propel keeps cached copies of objects in an instance pool when they are retrieved |
||
183 | * from the database. In some cases -- especially when you override doDelete |
||
184 | * methods in your stub classes -- you may need to explicitly remove objects |
||
185 | * from the cache in order to prevent returning objects that no longer exist. |
||
186 | * |
||
187 | * @param mixed $value A \xbanners\models\BannersI18n object or a primary key value. |
||
188 | */ |
||
189 | View Code Duplication | public static function removeInstanceFromPool($value) |
|
210 | |||
211 | /** |
||
212 | * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. |
||
213 | * |
||
214 | * For tables with a single-column primary key, that simple pkey value will be returned. For tables with |
||
215 | * a multi-column primary key, a serialize()d version of the primary key will be returned. |
||
216 | * |
||
217 | * @param array $row resultset row. |
||
218 | * @param int $offset The 0-based offset for reading from the resultset row. |
||
219 | * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
220 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM |
||
221 | * |
||
222 | * @return string The primary key hash of the row |
||
223 | */ |
||
224 | View Code Duplication | public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) |
|
233 | |||
234 | /** |
||
235 | * Retrieves the primary key from the DB resultset row |
||
236 | * For tables with a single-column primary key, that simple pkey value will be returned. For tables with |
||
237 | * a multi-column primary key, an array of the primary key columns will be returned. |
||
238 | * |
||
239 | * @param array $row resultset row. |
||
240 | * @param int $offset The 0-based offset for reading from the resultset row. |
||
241 | * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
242 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM |
||
243 | * |
||
244 | * @return mixed The primary key of the row |
||
245 | */ |
||
246 | View Code Duplication | public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) |
|
263 | |||
264 | /** |
||
265 | * The class that the tableMap will make instances of. |
||
266 | * |
||
267 | * If $withPrefix is true, the returned path |
||
268 | * uses a dot-path notation which is translated into a path |
||
269 | * relative to a location on the PHP include_path. |
||
270 | * (e.g. path.to.MyClass -> 'path/to/MyClass.php') |
||
271 | * |
||
272 | * @param boolean $withPrefix Whether or not to return the path with the class name |
||
273 | * @return string path.to.ClassName |
||
274 | */ |
||
275 | public static function getOMClass($withPrefix = true) |
||
279 | |||
280 | /** |
||
281 | * Populates an object of the default type or an object that inherit from the default. |
||
282 | * |
||
283 | * @param array $row row returned by DataFetcher->fetch(). |
||
284 | * @param int $offset The 0-based offset for reading from the resultset row. |
||
285 | * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). |
||
286 | One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
287 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
288 | * |
||
289 | * @throws PropelException Any exceptions caught during processing will be |
||
290 | * rethrown wrapped into a PropelException. |
||
291 | * @return array (BannersI18n object, last column rank) |
||
292 | */ |
||
293 | View Code Duplication | public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) |
|
311 | |||
312 | /** |
||
313 | * The returned array will contain objects of the default type or |
||
314 | * objects that inherit from the default. |
||
315 | * |
||
316 | * @param DataFetcherInterface $dataFetcher |
||
317 | * @return array |
||
318 | * @throws PropelException Any exceptions caught during processing will be |
||
319 | * rethrown wrapped into a PropelException. |
||
320 | */ |
||
321 | View Code Duplication | public static function populateObjects(DataFetcherInterface $dataFetcher) |
|
346 | /** |
||
347 | * Add all the columns needed to create a new object. |
||
348 | * |
||
349 | * Note: any columns that were marked with lazyLoad="true" in the |
||
350 | * XML schema will not be added to the select list and only loaded |
||
351 | * on demand. |
||
352 | * |
||
353 | * @param Criteria $criteria object containing the columns to add. |
||
354 | * @param string $alias optional table alias |
||
355 | * @throws PropelException Any exceptions caught during processing will be |
||
356 | * rethrown wrapped into a PropelException. |
||
357 | */ |
||
358 | public static function addSelectColumns(Criteria $criteria, $alias = null) |
||
370 | |||
371 | /** |
||
372 | * Returns the TableMap related to this object. |
||
373 | * This method is not needed for general use but a specific application could have a need. |
||
374 | * @return TableMap |
||
375 | * @throws PropelException Any exceptions caught during processing will be |
||
376 | * rethrown wrapped into a PropelException. |
||
377 | */ |
||
378 | public static function getTableMap() |
||
382 | |||
383 | /** |
||
384 | * Add a TableMap instance to the database for this tableMap class. |
||
385 | */ |
||
386 | View Code Duplication | public static function buildTableMap() |
|
393 | |||
394 | /** |
||
395 | * Performs a DELETE on the database, given a BannersI18n or Criteria object OR a primary key value. |
||
396 | * |
||
397 | * @param mixed $values Criteria or BannersI18n object or primary key or array of primary keys |
||
398 | * which is used to create the DELETE statement |
||
399 | * @param ConnectionInterface $con the connection to use |
||
400 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
401 | * if supported by native driver or if emulated using Propel. |
||
402 | * @throws PropelException Any exceptions caught during processing will be |
||
403 | * rethrown wrapped into a PropelException. |
||
404 | */ |
||
405 | View Code Duplication | public static function doDelete($values, ConnectionInterface $con = null) |
|
444 | |||
445 | /** |
||
446 | * Deletes all rows from the banners_i18n table. |
||
447 | * |
||
448 | * @param ConnectionInterface $con the connection to use |
||
449 | * @return int The number of affected rows (if supported by underlying database driver). |
||
450 | */ |
||
451 | public static function doDeleteAll(ConnectionInterface $con = null) |
||
455 | |||
456 | /** |
||
457 | * Performs an INSERT on the database, given a BannersI18n or Criteria object. |
||
458 | * |
||
459 | * @param mixed $criteria Criteria or BannersI18n object containing data that is used to create the INSERT statement. |
||
460 | * @param ConnectionInterface $con the ConnectionInterface connection to use |
||
461 | * @return mixed The new primary key. |
||
462 | * @throws PropelException Any exceptions caught during processing will be |
||
463 | * rethrown wrapped into a PropelException. |
||
464 | */ |
||
465 | View Code Duplication | public static function doInsert($criteria, ConnectionInterface $con = null) |
|
487 | |||
488 | } // BannersI18nTableMap |
||
489 | // This is the static code needed to register the TableMap for this table with the main Propel class. |
||
492 |