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