Conditions | 6 |
Paths | 32 |
Total Lines | 91 |
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 |
||
29 | public static function init(array $autoload_dirs = null) |
||
30 | { |
||
31 | if (! defined('TESTPATH')) { |
||
32 | define('TESTPATH', APPPATH.'tests'.DIRECTORY_SEPARATOR); |
||
33 | } |
||
34 | // Current Bootstrap.php should define this, but in case it doesn't: |
||
35 | if (! defined('CI_PHPUNIT_TESTPATH')) { |
||
36 | define('CI_PHPUNIT_TESTPATH', dirname(__FILE__).DIRECTORY_SEPARATOR); |
||
37 | } |
||
38 | |||
39 | // Fix CLI args |
||
40 | $_server_backup = $_SERVER; |
||
41 | $_SERVER['argv'] = [ |
||
42 | 'index.php', |
||
43 | 'welcome' // Dummy |
||
44 | ]; |
||
45 | $_SERVER['argc'] = 2; |
||
46 | |||
47 | self::$autoload_dirs = $autoload_dirs; |
||
48 | |||
49 | $cwd_backup = getcwd(); |
||
50 | |||
51 | // Load autoloader for ci-phpunit-test |
||
52 | require __DIR__ . '/autoloader.php'; |
||
53 | |||
54 | require TESTPATH . 'TestCase.php'; |
||
55 | |||
56 | $db_test_case_file = TESTPATH . 'DbTestCase.php'; |
||
57 | if (is_readable($db_test_case_file)) |
||
58 | { |
||
59 | require $db_test_case_file; |
||
60 | } |
||
61 | |||
62 | $unit_test_case_file = TESTPATH . 'UnitTestCase.php'; |
||
63 | if (is_readable($unit_test_case_file)) |
||
64 | { |
||
65 | require $unit_test_case_file; |
||
66 | } |
||
67 | |||
68 | // Replace a few Common functions |
||
69 | require __DIR__ . '/replacing/core/Common.php'; |
||
70 | require BASEPATH . 'core/Common.php'; |
||
71 | |||
72 | // Workaround for missing CodeIgniter's error handler |
||
73 | // See https://github.com/kenjis/ci-phpunit-test/issues/37 |
||
74 | set_error_handler('_error_handler'); |
||
75 | |||
76 | // Load new functions of CIPHPUnitTest |
||
77 | require __DIR__ . '/functions.php'; |
||
78 | // Load ci-phpunit-test CI_Loader |
||
79 | require __DIR__ . '/replacing/core/Loader.php'; |
||
80 | // Load ci-phpunit-test CI_Input |
||
81 | require __DIR__ . '/replacing/core/Input.php'; |
||
82 | // Load ci-phpunit-test CI_Output |
||
83 | require __DIR__ . '/replacing/core/Output.php'; |
||
84 | |||
85 | // Change current directory |
||
86 | chdir(FCPATH); |
||
87 | |||
88 | // Replace helpers before loading CI (which could auto load helpers) |
||
89 | self::replaceHelpers(); |
||
90 | |||
91 | /* |
||
92 | * -------------------------------------------------------------------- |
||
93 | * LOAD THE BOOTSTRAP FILE |
||
94 | * -------------------------------------------------------------------- |
||
95 | * |
||
96 | * And away we go... |
||
97 | */ |
||
98 | require __DIR__ . '/replacing/core/CodeIgniter.php'; |
||
99 | |||
100 | // Create CodeIgniter instance |
||
101 | if (! self::wiredesignzHmvcInstalled()) |
||
102 | { |
||
103 | new CI_Controller(); |
||
104 | } |
||
105 | else |
||
106 | { |
||
107 | new MX_Controller(); |
||
108 | } |
||
109 | |||
110 | // This code is here, not to cause errors with HMVC |
||
111 | self::replaceLoader(); |
||
112 | self::replaceConfig(); |
||
113 | |||
114 | // Restore $_SERVER. We need this for NetBeans |
||
115 | $_SERVER = $_server_backup; |
||
116 | |||
117 | // Restore cwd to use `Usage: phpunit [options] <directory>` |
||
118 | chdir($cwd_backup); |
||
119 | } |
||
120 | |||
258 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.