| Conditions | 5 |
| Paths | 16 |
| Total Lines | 85 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 22 | public static function init(array $autoload_dirs = null) |
||
| 23 | { |
||
| 24 | if (! defined('TESTPATH')) { |
||
| 25 | define('TESTPATH', APPPATH.'tests'.DIRECTORY_SEPARATOR); |
||
| 26 | } |
||
| 27 | |||
| 28 | // Fix CLI args |
||
| 29 | $_server_backup = $_SERVER; |
||
| 30 | $_SERVER['argv'] = [ |
||
| 31 | 'index.php', |
||
| 32 | 'welcome' // Dummy |
||
| 33 | ]; |
||
| 34 | $_SERVER['argc'] = 2; |
||
| 35 | |||
| 36 | self::$autoload_dirs = $autoload_dirs; |
||
| 37 | |||
| 38 | $cwd_backup = getcwd(); |
||
| 39 | |||
| 40 | // Load autoloader for ci-phpunit-test |
||
| 41 | require __DIR__ . '/autoloader.php'; |
||
| 42 | |||
| 43 | require TESTPATH . 'TestCase.php'; |
||
| 44 | |||
| 45 | $db_test_case_file = TESTPATH . 'DbTestCase.php'; |
||
| 46 | if (is_readable($db_test_case_file)) |
||
| 47 | { |
||
| 48 | require $db_test_case_file; |
||
| 49 | } |
||
| 50 | |||
| 51 | $unit_test_case_file = TESTPATH . 'UnitTestCase.php'; |
||
| 52 | if (is_readable($unit_test_case_file)) |
||
| 53 | { |
||
| 54 | require $unit_test_case_file; |
||
| 55 | } |
||
| 56 | |||
| 57 | // Replace a few Common functions |
||
| 58 | require __DIR__ . '/replacing/core/Common.php'; |
||
| 59 | require BASEPATH . 'core/Common.php'; |
||
| 60 | |||
| 61 | // Workaround for missing CodeIgniter's error handler |
||
| 62 | // See https://github.com/kenjis/ci-phpunit-test/issues/37 |
||
| 63 | set_error_handler('_error_handler'); |
||
| 64 | |||
| 65 | // Load new functions of CIPHPUnitTest |
||
| 66 | require __DIR__ . '/functions.php'; |
||
| 67 | // Load ci-phpunit-test CI_Loader |
||
| 68 | require __DIR__ . '/replacing/core/Loader.php'; |
||
| 69 | // Load ci-phpunit-test CI_Input |
||
| 70 | require __DIR__ . '/replacing/core/Input.php'; |
||
| 71 | // Load ci-phpunit-test CI_Output |
||
| 72 | require __DIR__ . '/replacing/core/Output.php'; |
||
| 73 | |||
| 74 | // Change current directory |
||
| 75 | chdir(FCPATH); |
||
| 76 | |||
| 77 | /* |
||
| 78 | * -------------------------------------------------------------------- |
||
| 79 | * LOAD THE BOOTSTRAP FILE |
||
| 80 | * -------------------------------------------------------------------- |
||
| 81 | * |
||
| 82 | * And away we go... |
||
| 83 | */ |
||
| 84 | require __DIR__ . '/replacing/core/CodeIgniter.php'; |
||
| 85 | |||
| 86 | self::replaceHelpers(); |
||
| 87 | |||
| 88 | // Create CodeIgniter instance |
||
| 89 | if (! self::wiredesignzHmvcInstalled()) |
||
| 90 | { |
||
| 91 | new CI_Controller(); |
||
| 92 | } |
||
| 93 | else |
||
| 94 | { |
||
| 95 | new MX_Controller(); |
||
| 96 | } |
||
| 97 | |||
| 98 | // This code is here, not to cause errors with HMVC |
||
| 99 | self::replaceLoader(); |
||
| 100 | |||
| 101 | // Restore $_SERVER. We need this for NetBeans |
||
| 102 | $_SERVER = $_server_backup; |
||
| 103 | |||
| 104 | // Restore cwd to use `Usage: phpunit [options] <directory>` |
||
| 105 | chdir($cwd_backup); |
||
| 106 | } |
||
| 107 | |||
| 223 |