| Conditions | 4 |
| Paths | 3 |
| Total Lines | 56 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 25 | function reset_instance() |
||
| 26 | { |
||
| 27 | // Reset loaded classes |
||
| 28 | load_class('', '', NULL, TRUE); |
||
| 29 | is_loaded('', TRUE); |
||
| 30 | |||
| 31 | // Reset config functions |
||
| 32 | reset_config(); |
||
| 33 | |||
| 34 | // Close db connection |
||
| 35 | $CI =& get_instance(); |
||
| 36 | if (isset($CI->db)) |
||
| 37 | { |
||
| 38 | if ( |
||
| 39 | $CI->db->dsn !== 'sqlite::memory:' |
||
| 40 | && $CI->db->database !== ':memory:' |
||
| 41 | ) |
||
| 42 | { |
||
| 43 | $CI->db->close(); |
||
| 44 | $CI->db = null; |
||
| 45 | } |
||
| 46 | else |
||
| 47 | { |
||
| 48 | // Don't close if SQLite in-memory database |
||
| 49 | // If we close it, all tables and stored data will be gone |
||
| 50 | load_class_instance('db', $CI->db); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | // Load core classes |
||
| 55 | $BM =& load_class('Benchmark', 'core'); |
||
| 56 | CIPHPUnitTestSuperGlobal::set_Global('BM', $BM); |
||
| 57 | $EXT =& load_class('Hooks', 'core'); |
||
| 58 | CIPHPUnitTestSuperGlobal::set_Global('EXT', $EXT); |
||
| 59 | $CFG =& load_class('Config', 'core'); |
||
| 60 | CIPHPUnitTestSuperGlobal::set_Global('CFG', $CFG); |
||
| 61 | $UNI =& load_class('URI', 'core'); |
||
| 62 | CIPHPUnitTestSuperGlobal::set_Global('UNI', $UNI); |
||
| 63 | // $URI =& load_class('Utf8', 'core'); |
||
|
|
|||
| 64 | // CIPHPUnitTestSuperGlobal::set_Global('URI', $URI); |
||
| 65 | $RTR =& load_class('Router', 'core'); |
||
| 66 | CIPHPUnitTestSuperGlobal::set_Global('RTR', $RTR); |
||
| 67 | $OUT =& load_class('Output', 'core'); |
||
| 68 | CIPHPUnitTestSuperGlobal::set_Global('OUT', $OUT); |
||
| 69 | $SEC =& load_class('Security', 'core'); |
||
| 70 | CIPHPUnitTestSuperGlobal::set_Global('SEC', $SEC); |
||
| 71 | $IN =& load_class('Input', 'core'); |
||
| 72 | CIPHPUnitTestSuperGlobal::set_Global('IN', $IN); |
||
| 73 | $LANG =& load_class('Lang', 'core'); |
||
| 74 | CIPHPUnitTestSuperGlobal::set_Global('LANG', $LANG); |
||
| 75 | |||
| 76 | CIPHPUnitTest::loadLoader(); |
||
| 77 | |||
| 78 | // Remove CodeIgniter instance |
||
| 79 | $CI = new CIPHPUnitTestNullCodeIgniter(); |
||
| 80 | } |
||
| 81 | |||
| 100 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.