| Conditions | 3 |
| Paths | 4 |
| Total Lines | 78 |
| Code Lines | 30 |
| 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 |
||
| 21 | public static function init(array $autoload_dirs = null) |
||
| 22 | { |
||
| 23 | // Fix CLI args |
||
| 24 | $_server_backup = $_SERVER; |
||
| 25 | $_SERVER['argv'] = [ |
||
| 26 | 'index.php', |
||
| 27 | 'welcome' // Dummy |
||
| 28 | ]; |
||
| 29 | $_SERVER['argc'] = 2; |
||
| 30 | |||
| 31 | self::$autoload_dirs = $autoload_dirs; |
||
| 32 | |||
| 33 | $cwd_backup = getcwd(); |
||
| 34 | |||
| 35 | // Load autoloader for ci-phpunit-test |
||
| 36 | require __DIR__ . '/autoloader.php'; |
||
| 37 | |||
| 38 | // Autoloader for PHP-Parser |
||
| 39 | // Don't use `require`, because we may have required already |
||
| 40 | // in `patcher/bootstrap.php` |
||
| 41 | require_once __DIR__ . '/patcher/third_party/PHP-Parser/lib/bootstrap.php'; |
||
| 42 | |||
| 43 | require APPPATH . '/tests/TestCase.php'; |
||
| 44 | |||
| 45 | $db_test_case_file = APPPATH . '/tests/DbTestCase.php'; |
||
| 46 | if (is_readable($db_test_case_file)) |
||
| 47 | { |
||
| 48 | require $db_test_case_file; |
||
| 49 | } |
||
| 50 | |||
| 51 | // Replace a few Common functions |
||
| 52 | require __DIR__ . '/replacing/core/Common.php'; |
||
| 53 | require BASEPATH . 'core/Common.php'; |
||
| 54 | |||
| 55 | // Workaround for missing CodeIgniter's error handler |
||
| 56 | // See https://github.com/kenjis/ci-phpunit-test/issues/37 |
||
| 57 | set_error_handler('_error_handler'); |
||
| 58 | |||
| 59 | // Load new functions of CIPHPUnitTest |
||
| 60 | require __DIR__ . '/functions.php'; |
||
| 61 | // Load ci-phpunit-test CI_Loader |
||
| 62 | require __DIR__ . '/replacing/core/Loader.php'; |
||
| 63 | // Load ci-phpunit-test CI_Input |
||
| 64 | require __DIR__ . '/replacing/core/Input.php'; |
||
| 65 | |||
| 66 | // Change current directroy |
||
| 67 | chdir(FCPATH); |
||
| 68 | |||
| 69 | /* |
||
| 70 | * -------------------------------------------------------------------- |
||
| 71 | * LOAD THE BOOTSTRAP FILE |
||
| 72 | * -------------------------------------------------------------------- |
||
| 73 | * |
||
| 74 | * And away we go... |
||
| 75 | */ |
||
| 76 | require __DIR__ . '/replacing/core/CodeIgniter.php'; |
||
| 77 | |||
| 78 | self::replaceHelpers(); |
||
| 79 | |||
| 80 | // Create CodeIgniter instance |
||
| 81 | if (! self::wiredesignzHmvcInstalled()) |
||
| 82 | { |
||
| 83 | new CI_Controller(); |
||
| 84 | } |
||
| 85 | else |
||
| 86 | { |
||
| 87 | new MX_Controller(); |
||
| 88 | } |
||
| 89 | |||
| 90 | // This code is here, not to cause errors with HMVC |
||
| 91 | self::replaceLoader(); |
||
| 92 | |||
| 93 | // Restore $_SERVER. We need this for NetBeans |
||
| 94 | $_SERVER = $_server_backup; |
||
| 95 | |||
| 96 | // Restore cwd to use `Usage: phpunit [options] <directory>` |
||
| 97 | chdir($cwd_backup); |
||
| 98 | } |
||
| 99 | |||
| 180 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.