Conditions | 3 |
Paths | 4 |
Total Lines | 73 |
Code Lines | 29 |
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 | require APPPATH . '/tests/TestCase.php'; |
||
39 | |||
40 | $db_test_case_file = APPPATH . '/tests/DbTestCase.php'; |
||
41 | if (is_readable($db_test_case_file)) |
||
42 | { |
||
43 | require $db_test_case_file; |
||
44 | } |
||
45 | |||
46 | // Replace a few Common functions |
||
47 | require __DIR__ . '/replacing/core/Common.php'; |
||
48 | require BASEPATH . 'core/Common.php'; |
||
49 | |||
50 | // Workaround for missing CodeIgniter's error handler |
||
51 | // See https://github.com/kenjis/ci-phpunit-test/issues/37 |
||
52 | set_error_handler('_error_handler'); |
||
53 | |||
54 | // Load new functions of CIPHPUnitTest |
||
55 | require __DIR__ . '/functions.php'; |
||
56 | // Load ci-phpunit-test CI_Loader |
||
57 | require __DIR__ . '/replacing/core/Loader.php'; |
||
58 | // Load ci-phpunit-test CI_Input |
||
59 | require __DIR__ . '/replacing/core/Input.php'; |
||
60 | |||
61 | // Change current directroy |
||
62 | chdir(FCPATH); |
||
63 | |||
64 | /* |
||
65 | * -------------------------------------------------------------------- |
||
66 | * LOAD THE BOOTSTRAP FILE |
||
67 | * -------------------------------------------------------------------- |
||
68 | * |
||
69 | * And away we go... |
||
70 | */ |
||
71 | require __DIR__ . '/replacing/core/CodeIgniter.php'; |
||
72 | |||
73 | self::replaceHelpers(); |
||
74 | |||
75 | // Create CodeIgniter instance |
||
76 | if (! self::wiredesignzHmvcInstalled()) |
||
77 | { |
||
78 | new CI_Controller(); |
||
79 | } |
||
80 | else |
||
81 | { |
||
82 | new MX_Controller(); |
||
83 | } |
||
84 | |||
85 | // This code is here, not to cause errors with HMVC |
||
86 | self::replaceLoader(); |
||
87 | |||
88 | // Restore $_SERVER. We need this for NetBeans |
||
89 | $_SERVER = $_server_backup; |
||
90 | |||
91 | // Restore cwd to use `Usage: phpunit [options] <directory>` |
||
92 | chdir($cwd_backup); |
||
93 | } |
||
94 | |||
175 |
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.