| Conditions | 2 |
| Paths | 2 |
| Total Lines | 67 |
| Code Lines | 25 |
| 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 |
||
| 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 | // Load autoloader for ci-phpunit-test |
||
| 34 | require __DIR__ . '/autoloader.php'; |
||
| 35 | |||
| 36 | // Autoloader for PHP-Parser |
||
| 37 | // Don't use `require`, because we may have required already |
||
| 38 | // in `patcher/bootstrap.php` |
||
| 39 | require_once __DIR__ . '/patcher/third_party/PHP-Parser/lib/bootstrap.php'; |
||
| 40 | |||
| 41 | require APPPATH . '/tests/TestCase.php'; |
||
| 42 | |||
| 43 | // Replace a few Common functions |
||
| 44 | require __DIR__ . '/replacing/core/Common.php'; |
||
| 45 | require BASEPATH . 'core/Common.php'; |
||
| 46 | |||
| 47 | // Workaround for missing CodeIgniter's error handler |
||
| 48 | // See https://github.com/kenjis/ci-phpunit-test/issues/37 |
||
| 49 | set_error_handler('_error_handler'); |
||
| 50 | |||
| 51 | // Load new functions of CIPHPUnitTest |
||
| 52 | require __DIR__ . '/functions.php'; |
||
| 53 | // Load ci-phpunit-test CI_Loader |
||
| 54 | require __DIR__ . '/replacing/core/Loader.php'; |
||
| 55 | // Load ci-phpunit-test CI_Input |
||
| 56 | require __DIR__ . '/replacing/core/Input.php'; |
||
| 57 | |||
| 58 | // Change current directroy |
||
| 59 | chdir(FCPATH); |
||
| 60 | |||
| 61 | /* |
||
| 62 | * -------------------------------------------------------------------- |
||
| 63 | * LOAD THE BOOTSTRAP FILE |
||
| 64 | * -------------------------------------------------------------------- |
||
| 65 | * |
||
| 66 | * And away we go... |
||
| 67 | */ |
||
| 68 | require __DIR__ . '/replacing/core/CodeIgniter.php'; |
||
| 69 | |||
| 70 | self::replaceHelpers(); |
||
| 71 | |||
| 72 | // Create CodeIgniter instance |
||
| 73 | if (! self::wiredesignzHmvcInstalled()) |
||
| 74 | { |
||
| 75 | new CI_Controller(); |
||
| 76 | } |
||
| 77 | else |
||
| 78 | { |
||
| 79 | new MX_Controller(); |
||
| 80 | } |
||
| 81 | |||
| 82 | // This code is here, not to cause errors with HMVC |
||
| 83 | self::replaceLoader(); |
||
| 84 | |||
| 85 | // Restore $_SERVER. We need this for NetBeans |
||
| 86 | $_SERVER = $_server_backup; |
||
| 87 | } |
||
| 88 | |||
| 161 |
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.