Conditions | 9 |
Paths | 10 |
Total Lines | 82 |
Code Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
76 | function update ($component_name = null, $mode = self::MODE_ADD) { |
||
77 | time_limit_pause(); |
||
78 | $storage = STORAGE.'/Composer'; |
||
79 | $status_code = 0; |
||
80 | $description = ''; |
||
81 | $this->prepare($storage); |
||
82 | $composer_json = $this->generate_composer_json($component_name, $mode); |
||
83 | $Config = Config::instance(); |
||
84 | $auth_json = _json_decode($Config->module('Composer')->auth_json ?: '[]'); |
||
85 | $Event = Event::instance(); |
||
86 | $Event->fire( |
||
87 | 'Composer/generate_composer_json', |
||
88 | [ |
||
89 | 'composer_json' => &$composer_json, |
||
90 | 'auth_json' => &$auth_json |
||
91 | ] |
||
92 | ); |
||
93 | if ($composer_json['repositories']) { |
||
94 | $this->file_put_json("$storage/tmp/composer.json", $composer_json); |
||
95 | $this->file_put_json("$storage/tmp/auth.json", $auth_json); |
||
96 | if ( |
||
97 | $this->force_update || |
||
98 | !file_exists("$storage/composer.json") || |
||
99 | md5_file("$storage/tmp/composer.json") != md5_file("$storage/composer.json") |
||
100 | ) { |
||
101 | $this->force_update = false; |
||
102 | $Application = new Application( |
||
103 | function ($Composer) use ($Event, &$Application) { |
||
104 | $Event->fire( |
||
105 | 'Composer/Composer', |
||
106 | [ |
||
107 | 'Application' => $Application, |
||
108 | 'Composer' => $Composer |
||
109 | ] |
||
110 | ); |
||
111 | } |
||
112 | ); |
||
113 | $verbosity = !DEBUG && $Config->core['simple_admin_mode'] ? '-vv' : '-vvv'; |
||
114 | $input = new ArrayInput( |
||
115 | [ |
||
116 | 'command' => 'update', |
||
117 | '--working-dir' => "$storage/tmp", |
||
118 | '--no-dev' => true, |
||
119 | '--ansi' => true, |
||
120 | '--prefer-dist' => true, |
||
121 | '--optimize-autoloader' => true, |
||
122 | $verbosity => true |
||
123 | ] |
||
124 | ); |
||
125 | $output = new Output; |
||
126 | $Application->setAutoExit(false); |
||
127 | $status_code = $Application->run($input, $output); |
||
128 | $description = $output->get_buffer(); |
||
129 | if ($status_code == 0) { |
||
130 | rmdir_recursive("$storage/vendor"); |
||
131 | @unlink("$storage/composer.json"); |
||
132 | @unlink("$storage/composer.lock"); |
||
133 | rename("$storage/tmp/vendor", "$storage/vendor"); |
||
134 | rename("$storage/tmp/composer.json", "$storage/composer.json"); |
||
135 | rename("$storage/tmp/composer.lock", "$storage/composer.lock"); |
||
136 | $Event->fire( |
||
137 | 'Composer/updated', |
||
138 | [ |
||
139 | 'composer_json' => file_get_json("$storage/composer.json"), |
||
140 | 'composer_lock' => file_get_json("$storage/composer.lock"), |
||
141 | 'composer_root' => $storage |
||
142 | ] |
||
143 | ); |
||
144 | } |
||
145 | } |
||
146 | } else { |
||
147 | rmdir_recursive("$storage/vendor"); |
||
148 | @unlink("$storage/composer.json"); |
||
149 | @unlink("$storage/composer.lock"); |
||
150 | } |
||
151 | $this->cleanup($storage); |
||
152 | time_limit_pause(false); |
||
153 | return [ |
||
154 | 'code' => $status_code, |
||
155 | 'description' => $description |
||
156 | ]; |
||
157 | } |
||
158 | /** |
||
262 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.