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 BannerImageI18nTableMap 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 BannerImageI18nTableMap, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class BannerImageI18nTableMap 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.BannerImageI18nTableMap'; |
||
| 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 = 'banner_image_i18n'; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The related Propel class for this table |
||
| 51 | */ |
||
| 52 | const OM_CLASS = '\\xbanners\\models\\BannerImageI18n'; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * A class that can be returned by this tableMap |
||
| 56 | */ |
||
| 57 | const CLASS_DEFAULT = 'xbanners.models.BannerImageI18n'; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * The total number of columns |
||
| 61 | */ |
||
| 62 | const NUM_COLUMNS = 6; |
||
| 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 = 6; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * the column name for the id field |
||
| 76 | */ |
||
| 77 | const COL_ID = 'banner_image_i18n.id'; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * the column name for the locale field |
||
| 81 | */ |
||
| 82 | const COL_LOCALE = 'banner_image_i18n.locale'; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * the column name for the src field |
||
| 86 | */ |
||
| 87 | const COL_SRC = 'banner_image_i18n.src'; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * the column name for the name field |
||
| 91 | */ |
||
| 92 | const COL_NAME = 'banner_image_i18n.name'; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * the column name for the clicks field |
||
| 96 | */ |
||
| 97 | const COL_CLICKS = 'banner_image_i18n.clicks'; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * the column name for the description field |
||
| 101 | */ |
||
| 102 | const COL_DESCRIPTION = 'banner_image_i18n.description'; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * The default string format for model objects of the related table |
||
| 106 | */ |
||
| 107 | const DEFAULT_STRING_FORMAT = 'YAML'; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * holds an array of fieldnames |
||
| 111 | * |
||
| 112 | * first dimension keys are the type constants |
||
| 113 | * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' |
||
| 114 | */ |
||
| 115 | protected static $fieldNames = array ( |
||
| 116 | self::TYPE_PHPNAME => array('Id', 'Locale', 'Src', 'Name', 'Clicks', 'Description', ), |
||
| 117 | self::TYPE_CAMELNAME => array('id', 'locale', 'src', 'name', 'clicks', 'description', ), |
||
| 118 | self::TYPE_COLNAME => array(BannerImageI18nTableMap::COL_ID, BannerImageI18nTableMap::COL_LOCALE, BannerImageI18nTableMap::COL_SRC, BannerImageI18nTableMap::COL_NAME, BannerImageI18nTableMap::COL_CLICKS, BannerImageI18nTableMap::COL_DESCRIPTION, ), |
||
| 119 | self::TYPE_FIELDNAME => array('id', 'locale', 'src', 'name', 'clicks', 'description', ), |
||
| 120 | self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) |
||
| 121 | ); |
||
| 122 | |||
| 123 | /** |
||
| 124 | * holds an array of keys for quick access to the fieldnames array |
||
| 125 | * |
||
| 126 | * first dimension keys are the type constants |
||
| 127 | * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 |
||
| 128 | */ |
||
| 129 | protected static $fieldKeys = array ( |
||
| 130 | self::TYPE_PHPNAME => array('Id' => 0, 'Locale' => 1, 'Src' => 2, 'Name' => 3, 'Clicks' => 4, 'Description' => 5, ), |
||
| 131 | self::TYPE_CAMELNAME => array('id' => 0, 'locale' => 1, 'src' => 2, 'name' => 3, 'clicks' => 4, 'description' => 5, ), |
||
| 132 | self::TYPE_COLNAME => array(BannerImageI18nTableMap::COL_ID => 0, BannerImageI18nTableMap::COL_LOCALE => 1, BannerImageI18nTableMap::COL_SRC => 2, BannerImageI18nTableMap::COL_NAME => 3, BannerImageI18nTableMap::COL_CLICKS => 4, BannerImageI18nTableMap::COL_DESCRIPTION => 5, ), |
||
| 133 | self::TYPE_FIELDNAME => array('id' => 0, 'locale' => 1, 'src' => 2, 'name' => 3, 'clicks' => 4, 'description' => 5, ), |
||
| 134 | self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, ) |
||
| 135 | ); |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Initialize the table attributes and columns |
||
| 139 | * Relations are not initialized by this method since they are lazy loaded |
||
| 140 | * |
||
| 141 | * @return void |
||
| 142 | * @throws PropelException |
||
| 143 | */ |
||
| 144 | public function initialize() |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Build the RelationMap objects for this table relationships |
||
| 164 | */ |
||
| 165 | View Code Duplication | public function buildRelations() |
|
| 175 | |||
| 176 | /** |
||
| 177 | * Adds an object to the instance pool. |
||
| 178 | * |
||
| 179 | * Propel keeps cached copies of objects in an instance pool when they are retrieved |
||
| 180 | * from the database. In some cases you may need to explicitly add objects |
||
| 181 | * to the cache in order to ensure that the same objects are always returned by find*() |
||
| 182 | * and findPk*() calls. |
||
| 183 | * |
||
| 184 | * @param \xbanners\models\BannerImageI18n $obj A \xbanners\models\BannerImageI18n object. |
||
| 185 | * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). |
||
| 186 | */ |
||
| 187 | View Code Duplication | public static function addInstanceToPool($obj, $key = null) |
|
| 196 | |||
| 197 | /** |
||
| 198 | * Removes an object from the instance pool. |
||
| 199 | * |
||
| 200 | * Propel keeps cached copies of objects in an instance pool when they are retrieved |
||
| 201 | * from the database. In some cases -- especially when you override doDelete |
||
| 202 | * methods in your stub classes -- you may need to explicitly remove objects |
||
| 203 | * from the cache in order to prevent returning objects that no longer exist. |
||
| 204 | * |
||
| 205 | * @param mixed $value A \xbanners\models\BannerImageI18n object or a primary key value. |
||
| 206 | */ |
||
| 207 | View Code Duplication | public static function removeInstanceFromPool($value) |
|
| 228 | |||
| 229 | /** |
||
| 230 | * 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. |
||
| 231 | * |
||
| 232 | * For tables with a single-column primary key, that simple pkey value will be returned. For tables with |
||
| 233 | * a multi-column primary key, a serialize()d version of the primary key will be returned. |
||
| 234 | * |
||
| 235 | * @param array $row resultset row. |
||
| 236 | * @param int $offset The 0-based offset for reading from the resultset row. |
||
| 237 | * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 238 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM |
||
| 239 | * |
||
| 240 | * @return string The primary key hash of the row |
||
| 241 | */ |
||
| 242 | View Code Duplication | public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) |
|
| 251 | |||
| 252 | /** |
||
| 253 | * Retrieves the primary key from the DB resultset row |
||
| 254 | * For tables with a single-column primary key, that simple pkey value will be returned. For tables with |
||
| 255 | * a multi-column primary key, an array of the primary key columns will be returned. |
||
| 256 | * |
||
| 257 | * @param array $row resultset row. |
||
| 258 | * @param int $offset The 0-based offset for reading from the resultset row. |
||
| 259 | * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 260 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM |
||
| 261 | * |
||
| 262 | * @return mixed The primary key of the row |
||
| 263 | */ |
||
| 264 | View Code Duplication | public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) |
|
| 281 | |||
| 282 | /** |
||
| 283 | * The class that the tableMap will make instances of. |
||
| 284 | * |
||
| 285 | * If $withPrefix is true, the returned path |
||
| 286 | * uses a dot-path notation which is translated into a path |
||
| 287 | * relative to a location on the PHP include_path. |
||
| 288 | * (e.g. path.to.MyClass -> 'path/to/MyClass.php') |
||
| 289 | * |
||
| 290 | * @param boolean $withPrefix Whether or not to return the path with the class name |
||
| 291 | * @return string path.to.ClassName |
||
| 292 | */ |
||
| 293 | public static function getOMClass($withPrefix = true) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Populates an object of the default type or an object that inherit from the default. |
||
| 300 | * |
||
| 301 | * @param array $row row returned by DataFetcher->fetch(). |
||
| 302 | * @param int $offset The 0-based offset for reading from the resultset row. |
||
| 303 | * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). |
||
| 304 | One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 305 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 306 | * |
||
| 307 | * @throws PropelException Any exceptions caught during processing will be |
||
| 308 | * rethrown wrapped into a PropelException. |
||
| 309 | * @return array (BannerImageI18n object, last column rank) |
||
| 310 | */ |
||
| 311 | View Code Duplication | public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) |
|
| 329 | |||
| 330 | /** |
||
| 331 | * The returned array will contain objects of the default type or |
||
| 332 | * objects that inherit from the default. |
||
| 333 | * |
||
| 334 | * @param DataFetcherInterface $dataFetcher |
||
| 335 | * @return array |
||
| 336 | * @throws PropelException Any exceptions caught during processing will be |
||
| 337 | * rethrown wrapped into a PropelException. |
||
| 338 | */ |
||
| 339 | View Code Duplication | public static function populateObjects(DataFetcherInterface $dataFetcher) |
|
| 364 | /** |
||
| 365 | * Add all the columns needed to create a new object. |
||
| 366 | * |
||
| 367 | * Note: any columns that were marked with lazyLoad="true" in the |
||
| 368 | * XML schema will not be added to the select list and only loaded |
||
| 369 | * on demand. |
||
| 370 | * |
||
| 371 | * @param Criteria $criteria object containing the columns to add. |
||
| 372 | * @param string $alias optional table alias |
||
| 373 | * @throws PropelException Any exceptions caught during processing will be |
||
| 374 | * rethrown wrapped into a PropelException. |
||
| 375 | */ |
||
| 376 | public static function addSelectColumns(Criteria $criteria, $alias = null) |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Returns the TableMap related to this object. |
||
| 397 | * This method is not needed for general use but a specific application could have a need. |
||
| 398 | * @return TableMap |
||
| 399 | * @throws PropelException Any exceptions caught during processing will be |
||
| 400 | * rethrown wrapped into a PropelException. |
||
| 401 | */ |
||
| 402 | public static function getTableMap() |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Add a TableMap instance to the database for this tableMap class. |
||
| 409 | */ |
||
| 410 | View Code Duplication | public static function buildTableMap() |
|
| 417 | |||
| 418 | /** |
||
| 419 | * Performs a DELETE on the database, given a BannerImageI18n or Criteria object OR a primary key value. |
||
| 420 | * |
||
| 421 | * @param mixed $values Criteria or BannerImageI18n object or primary key or array of primary keys |
||
| 422 | * which is used to create the DELETE statement |
||
| 423 | * @param ConnectionInterface $con the connection to use |
||
| 424 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
| 425 | * if supported by native driver or if emulated using Propel. |
||
| 426 | * @throws PropelException Any exceptions caught during processing will be |
||
| 427 | * rethrown wrapped into a PropelException. |
||
| 428 | */ |
||
| 429 | View Code Duplication | public static function doDelete($values, ConnectionInterface $con = null) |
|
| 468 | |||
| 469 | /** |
||
| 470 | * Deletes all rows from the banner_image_i18n table. |
||
| 471 | * |
||
| 472 | * @param ConnectionInterface $con the connection to use |
||
| 473 | * @return int The number of affected rows (if supported by underlying database driver). |
||
| 474 | */ |
||
| 475 | public static function doDeleteAll(ConnectionInterface $con = null) |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Performs an INSERT on the database, given a BannerImageI18n or Criteria object. |
||
| 482 | * |
||
| 483 | * @param mixed $criteria Criteria or BannerImageI18n object containing data that is used to create the INSERT statement. |
||
| 484 | * @param ConnectionInterface $con the ConnectionInterface connection to use |
||
| 485 | * @return mixed The new primary key. |
||
| 486 | * @throws PropelException Any exceptions caught during processing will be |
||
| 487 | * rethrown wrapped into a PropelException. |
||
| 488 | */ |
||
| 489 | View Code Duplication | public static function doInsert($criteria, ConnectionInterface $con = null) |
|
| 511 | |||
| 512 | } // BannerImageI18nTableMap |
||
| 513 | // This is the static code needed to register the TableMap for this table with the main Propel class. |
||
| 516 |