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:
| 1 | <?php |
||
| 179 | class classConfig extends classPersistent { |
||
| 180 | protected $defaults = array( |
||
| 181 | // SEO meta |
||
| 182 | 'adv_conversion_code_payment' => '', |
||
| 183 | 'adv_conversion_code_register' => '', |
||
| 184 | 'adv_seo_meta_description' => '', |
||
| 185 | 'adv_seo_meta_keywords' => '', |
||
| 186 | 'adv_seo_javascript' => '', |
||
| 187 | |||
| 188 | // Advert banner |
||
| 189 | 'advGoogleLeftMenuIsOn' => 0, |
||
| 190 | 'advGoogleLeftMenuCode' => '(Place here code for banner)', |
||
| 191 | |||
| 192 | // Alliance bonus calculations |
||
| 193 | 'ali_bonus_algorithm' => 0, // Bonus calculation algorithm |
||
| 194 | 'ali_bonus_brackets' => 10, // Brackets count for ALI_BONUS_BY_RANK |
||
| 195 | 'ali_bonus_brackets_divisor' => 10,// Bonus divisor for ALI_BONUS_BY_RANK |
||
| 196 | 'ali_bonus_divisor' => 10000000, // Rank divisor for ALI_BONUS_BY_POINTS |
||
| 197 | 'ali_bonus_members' => 10, // Minumum alliace size to start using bonus |
||
| 198 | |||
| 199 | 'allow_buffing' => 0, // Disable buffing check for TRANSPORT missions |
||
| 200 | 'ally_help_weak' => 0, // Allow strong players to HOLD on weak co-ally planets |
||
| 201 | |||
| 202 | // User avatar and alliance logo |
||
| 203 | 'avatar_max_height' => 128, // Maximum height |
||
| 204 | 'avatar_max_width' => 128, // Maximum width |
||
| 205 | |||
| 206 | 'BuildLabWhileRun' => 0, |
||
| 207 | |||
| 208 | // Chat settings |
||
| 209 | // Nick highliting |
||
| 210 | 'chat_highlight_developer' => '<span class=\"nick_developer\">$1</span>', // Developer nick |
||
| 211 | 'chat_highlight_admin' => '<span class=\"nick_admin\">$1</span>', // Admin nick |
||
| 212 | 'chat_highlight_moderator' => '<span class=\"nick_moderator\">$1</span>', // Moderator nick |
||
| 213 | 'chat_highlight_operator' => '<span class=\"nick_operator\">$1</span>', // Operator nick |
||
| 214 | 'chat_highlight_premium' => '<span class=\"nick_premium\">$1</span>', // Premium nick |
||
| 215 | // Other chat settings |
||
| 216 | 'chat_refresh_rate' => 5, // in seconds. Chat AJAX refresh rate |
||
| 217 | 'chat_timeout' => 900, // in seconds. Default = 15 min |
||
| 218 | |||
| 219 | 'COOKIE_NAME' => 'SuperNova', |
||
| 220 | 'crystal_basic_income' => 20, |
||
| 221 | 'debug' => 0, |
||
| 222 | 'Defs_Cdr' => 30, |
||
| 223 | 'deuterium_basic_income' => 0, |
||
| 224 | 'eco_scale_storage' => 1, |
||
| 225 | 'eco_stockman_fleet' => '', // Black Market - Starting amount of s/h ship merchant to sell |
||
| 226 | 'eco_stockman_fleet_populate' => 1, // Populate empty Stockman fleet with ships or not |
||
| 227 | 'empire_mercenary_base_period' => PERIOD_MONTH, // Base |
||
| 228 | 'empire_mercenary_temporary' => 0, // Temporary empire-wide mercenaries |
||
| 229 | 'energy_basic_income' => 0, |
||
| 230 | |||
| 231 | // Bashing protection settings |
||
| 232 | 'fleet_bashing_attacks' => 3, // Max amount of attack per wave - 3 by default |
||
| 233 | 'fleet_bashing_interval' => 1800, // Maximum interval between attacks when they still count as one wave - 30m by default |
||
| 234 | 'fleet_bashing_scope' => 86400, // Interval on which bashing waves counts - 24h by default |
||
| 235 | 'fleet_bashing_war_delay' => 43200, // Delay before start bashing after declaring war to alliance - 12h by default |
||
| 236 | 'fleet_bashing_waves' => 3, // Max amount of waves per day - 3 by default |
||
| 237 | |||
| 238 | 'Fleet_Cdr' => 30, |
||
| 239 | 'fleet_speed' => 1, |
||
| 240 | |||
| 241 | 'fleet_update_interval' => 4, |
||
| 242 | |||
| 243 | 'game_adminEmail' => 'root@localhost', // Admin's email to show to users |
||
| 244 | 'game_counter' => 0, // Does built-in page hit counter is on? |
||
| 245 | // Defaults |
||
| 246 | 'game_default_language' => 'ru', |
||
| 247 | 'game_default_skin' => 'skins/EpicBlue/', |
||
| 248 | 'game_default_template' => 'OpenGame', |
||
| 249 | |||
| 250 | 'game_disable' => GAME_DISABLE_INSTALL, |
||
| 251 | 'game_disable_reason' => 'SuperNova is in maintenance mode! Please return later!', |
||
| 252 | 'game_email_pm' => 0, // Is allowed forwarding messages from PM to e-mail? |
||
| 253 | // Universe size |
||
| 254 | 'game_maxGalaxy' => 5, |
||
| 255 | 'game_maxSystem' => 199, |
||
| 256 | 'game_maxPlanet' => 15, |
||
| 257 | // Game global settings |
||
| 258 | 'game_mode' => 0, // 0 - SuperNova, 1 - oGame |
||
| 259 | 'game_name' => 'SuperNova', // Server name (would be on banners and on top of left menu) |
||
| 260 | |||
| 261 | 'game_news_actual' => 259200, // How long announcement would be marked as "New". In seconds. Default - 3 days |
||
| 262 | 'game_news_overview' => 3, // How much last news to show in Overview page |
||
| 263 | // Noob protection |
||
| 264 | 'game_noob_factor' => 5, // Multiplier to divide "stronger" and "weaker" users |
||
| 265 | 'game_noob_points' => 5000, // Below this point user threated as noob. 0 to disable |
||
| 266 | |||
| 267 | 'game_multiaccount_enabled' => 0, // 1 - allow interactions for players with same IP (multiaccounts) |
||
| 268 | |||
| 269 | 'game_speed' => 1, // Game speed |
||
| 270 | 'game_speed_expedition' => 1, // Expedition speed. 1 means "normal" |
||
| 271 | 'game_user_changename' => 2, // Is user allowed to change name after registration? |
||
| 272 | 'game_user_changename_cost' => 100000, // Change name cost for paid changename |
||
| 273 | |||
| 274 | 'initial_fields' => 163, |
||
| 275 | |||
| 276 | // Interface - UserBanner |
||
| 277 | 'int_banner_background' => 'design/images/banner.png', |
||
| 278 | 'int_banner_fontInfo' => 'terminator.ttf', |
||
| 279 | 'int_banner_fontRaids' => 'klmnfp2005.ttf', |
||
| 280 | 'int_banner_fontUniverse' => 'cristal.ttf', |
||
| 281 | 'int_banner_showInOverview' => 1, |
||
| 282 | 'int_banner_URL' => '/banner.php?type=banner', |
||
| 283 | |||
| 284 | 'int_format_date' => 'd.m.Y', // Date default format |
||
| 285 | 'int_format_time' => 'H:i:s', // Time default format |
||
| 286 | |||
| 287 | // Interface - UserBar |
||
| 288 | 'int_userbar_background' => 'design/images/userbar.png', |
||
| 289 | 'int_userbar_font' => 'arialbd.ttf', |
||
| 290 | 'int_userbar_showInOverview' => 1, |
||
| 291 | 'int_userbar_URL' => '/banner.php?type=userbar', |
||
| 292 | |||
| 293 | 'LastSettedGalaxyPos' => 1, |
||
| 294 | 'LastSettedPlanetPos' => 1, |
||
| 295 | 'LastSettedSystemPos' => 1, |
||
| 296 | |||
| 297 | 'locale_cache_disable' => 0, // Disable locale caching |
||
| 298 | |||
| 299 | 'metal_basic_income' => 40, |
||
| 300 | |||
| 301 | 'payment_currency_default' => 'USD', |
||
| 302 | 'payment_currency_exchange_dm_' => METAMATTER_DEFAULT_LOT_SIZE, |
||
| 303 | 'payment_currency_exchange_mm_' => METAMATTER_DEFAULT_LOT_SIZE, |
||
| 304 | 'payment_currency_exchange_eur' => 0.90, |
||
| 305 | 'payment_currency_exchange_rub' => 60, |
||
| 306 | 'payment_currency_exchange_uah' => 30, |
||
| 307 | 'payment_currency_exchange_usd' => 1, |
||
| 308 | 'payment_currency_exchange_wmb' => 18000, |
||
| 309 | 'payment_currency_exchange_wme' => 0.9, |
||
| 310 | 'payment_currency_exchange_wmr' => 60, |
||
| 311 | 'payment_currency_exchange_wmu' => 30, |
||
| 312 | 'payment_currency_exchange_wmz' => 1, |
||
| 313 | |||
| 314 | 'payment_lot_price' => 1, // Lot price in default currency |
||
| 315 | 'payment_lot_size' => 2500, // Lot size. Also service as minimum amount of DM that could be bought with one transaction |
||
| 316 | |||
| 317 | 'planet_teleport_cost' => 50000, // |
||
| 318 | 'planet_teleport_timeout' => 86400, // |
||
| 319 | |||
| 320 | 'player_delete_time' => 3888000, // |
||
| 321 | 'player_max_colonies' => -1, // Max player planet count (NOT including main planet) |
||
| 322 | 'player_vacation_time' => PERIOD_WEEK, // |
||
| 323 | 'player_vacation_timeout' => PERIOD_WEEK, // |
||
| 324 | |||
| 325 | 'player_metamatter_immortal' => 100000, |
||
| 326 | |||
| 327 | // Quests |
||
| 328 | 'quest_total' => 0, // Total number of quests |
||
| 329 | |||
| 330 | 'resource_multiplier' => 1, |
||
| 331 | |||
| 332 | //Roleplay system |
||
| 333 | 'rpg_bonus_divisor' => 10, // Amount of DM referral shoud get for partner have 1 DM bonus |
||
| 334 | 'rpg_bonus_minimum' => 10000, // Minimum DM ammount for starting paying bonuses to affiliate |
||
| 335 | |||
| 336 | // Black Market - General |
||
| 337 | 'rpg_cost_banker' => 1000, // Banker can hold some resources |
||
| 338 | 'rpg_cost_exchange' => 1000, // Exchange allows resource trade between players |
||
| 339 | 'rpg_cost_info' => 10000, // Infotrader sells valuable information about users, alliances and universe |
||
| 340 | 'rpg_cost_pawnshop' => 1000, // You can get loan in pawnshop |
||
| 341 | 'rpg_cost_scraper' => 1000, // Scrapper buys ship for fraction of cost |
||
| 342 | 'rpg_cost_stockman' => 1000, // Stockman resells ship that was scrapped |
||
| 343 | 'rpg_cost_trader' => 1000, // Trader trades between resources |
||
| 344 | |||
| 345 | // Black Market - Resource exachange rates |
||
| 346 | 'rpg_exchange_metal' => 1, |
||
| 347 | 'rpg_exchange_crystal' => 2, |
||
| 348 | 'rpg_exchange_deuterium' => 4, |
||
| 349 | 'rpg_exchange_darkMatter' => 400, |
||
| 350 | |||
| 351 | 'rpg_flt_explore' => 1000, // DM reward for finding Supernova in expedition |
||
| 352 | |||
| 353 | // Black Market - Scraper rates for ship pre resource |
||
| 354 | 'rpg_scrape_crystal' => 0.50, |
||
| 355 | 'rpg_scrape_deuterium' => 0.25, |
||
| 356 | 'rpg_scrape_metal' => 0.75, |
||
| 357 | |||
| 358 | 'security_ban_extra' => '', |
||
| 359 | 'security_write_full_url_disabled' => 1, // Disables writing full URLs to counter table |
||
| 360 | |||
| 361 | 'server_log_online' => 0, // |
||
| 362 | |||
| 363 | 'server_que_length_hangar' => '5', // |
||
| 364 | 'server_que_length_research' => '1', // |
||
| 365 | 'server_que_length_structures' => '5', // |
||
| 366 | |||
| 367 | 'server_start_date' => '', // |
||
| 368 | |||
| 369 | 'server_updater_check_auto' => 0, // Server autocheck version |
||
| 370 | 'server_updater_check_last' => 0, // Server last check time |
||
| 371 | 'server_updater_check_period' => PERIOD_DAY, // Server autocheck period |
||
| 372 | 'server_updater_check_result' => SNC_VER_NEVER, // Server last check result |
||
| 373 | 'server_updater_id' => 0, // Server ID on update server |
||
| 374 | 'server_updater_key' => '', // Server key on update server |
||
| 375 | |||
| 376 | 'stats_history_days' => 14, // За сколько дней хранить статистику в базе |
||
| 377 | 'stats_hide_admins' => 1, |
||
| 378 | 'stats_hide_player_list' => '', |
||
| 379 | 'stats_hide_pm_link' => 0, |
||
| 380 | 'stats_schedule' => '04:00:00', |
||
| 381 | |||
| 382 | 'tpl_allow_php' => 0, // Allow template to include PHP code. SHOULD BE ALWAYS DISABLE!!!!!!!! |
||
| 383 | 'tpl_minifier' => 1, // Template minifier |
||
| 384 | |||
| 385 | 'uni_price_galaxy' => 10000, |
||
| 386 | 'uni_price_system' => 1000, |
||
| 387 | |||
| 388 | 'upd_lock_time' => 60, // How long update will lock table. Also update increment time when it requires |
||
| 389 | |||
| 390 | 'url_faq' => '', |
||
| 391 | 'url_forum' => '', |
||
| 392 | 'url_purchase_metamatter' => '', |
||
| 393 | 'url_rules' => '', |
||
| 394 | |||
| 395 | 'users_amount' => 1, |
||
| 396 | |||
| 397 | 'user_birthday_celebrate' => 0, // When last time celebrations (i.e. giftgiving) was made |
||
| 398 | 'user_birthday_gift' => 0, // User birthday gift |
||
| 399 | 'user_birthday_range' => PERIOD_MONTH, // How far in past can be user birthday for giving him gift |
||
| 400 | |||
| 401 | 'user_vacation_disable' => 0, |
||
| 402 | |||
| 403 | 'var_db_update' => 0, // Time of last DB update |
||
| 404 | 'var_db_update_end' => 0, // Time when last DB update should end. Need to prevent duplicate update |
||
| 405 | |||
| 406 | 'var_news_last' => 0, // Last news post time |
||
| 407 | |||
| 408 | // Statistic |
||
| 409 | 'var_stat_update' => 0, |
||
| 410 | 'var_stat_update_end' => 0, |
||
| 411 | 'var_stat_update_msg' => 'Update never started', |
||
| 412 | |||
| 413 | ); |
||
| 414 | |||
| 415 | public function __construct($gamePrefix = 'sn_') { |
||
| 418 | |||
| 419 | View Code Duplication | public static function getInstance($gamePrefix = 'sn_', $table_name = 'config') { |
|
| 427 | |||
| 428 | /** |
||
| 429 | * Repacks option with players ID so only exists ID left |
||
| 430 | * |
||
| 431 | * @param string $optionName |
||
| 432 | */ |
||
| 433 | public function repackExistsOptionPlayerIdString($optionName) { |
||
| 440 | |||
| 441 | } |
||
| 442 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.