Conditions | 10 |
Paths | 10 |
Total Lines | 111 |
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 |
||
163 | protected function import( $filename ) |
||
164 | { |
||
165 | $context = $this->getContext(); |
||
166 | $config = $context->getConfig(); |
||
167 | $domains = ['attribute/property', 'media', 'price', 'text']; |
||
168 | |||
169 | /** controller/jobs/attribute/import/xml/domains |
||
170 | * List of item domain names that should be retrieved along with the attribute items |
||
171 | * |
||
172 | * This configuration setting overwrites the shared option |
||
173 | * "controller/common/attribute/import/xml/domains" if you need a |
||
174 | * specific setting for the job controller. Otherwise, you should |
||
175 | * use the shared option for consistency. |
||
176 | * |
||
177 | * @param array Associative list of MShop item domain names |
||
178 | * @since 2019.04 |
||
179 | * @category Developer |
||
180 | * @see controller/jobs/attribute/import/xml/backup |
||
181 | * @see controller/jobs/attribute/import/xml/max-query |
||
182 | */ |
||
183 | $domains = $config->get( 'controller/jobs/attribute/import/xml/domains', $domains ); |
||
184 | |||
185 | /** controller/jobs/attribute/import/xml/backup |
||
186 | * Name of the backup for sucessfully imported files |
||
187 | * |
||
188 | * After a XML file was imported successfully, you can move it to another |
||
189 | * location, so it won't be imported again and isn't overwritten by the |
||
190 | * next file that is stored at the same location in the file system. |
||
191 | * |
||
192 | * You should use an absolute path to be sure but can be relative path |
||
193 | * if you absolutely know from where the job will be executed from. The |
||
194 | * name of the new backup location can contain placeholders understood |
||
195 | * by the PHP strftime() function to create dynamic paths, e.g. "backup/%Y-%m-%d" |
||
196 | * which would create "backup/2000-01-01". For more information about the |
||
197 | * strftime() placeholders, please have a look into the PHP documentation of |
||
198 | * the {@link http://php.net/manual/en/function.strftime.php strftime() function}. |
||
199 | * |
||
200 | * '''Note:''' If no backup name is configured, the file or directory |
||
201 | * won't be moved away. Please make also sure that the parent directory |
||
202 | * and the new directory are writable so the file or directory could be |
||
203 | * moved. |
||
204 | * |
||
205 | * @param integer Name of the backup file, optionally with date/time placeholders |
||
206 | * @since 2019.04 |
||
207 | * @category Developer |
||
208 | * @see controller/jobs/attribute/import/xml/domains |
||
209 | * @see controller/jobs/attribute/import/xml/max-query |
||
210 | */ |
||
211 | $backup = $config->get( 'controller/jobs/attribute/import/xml/backup' ); |
||
212 | |||
213 | /** controller/jobs/attribute/import/xml/max-query |
||
214 | * Maximum number of XML nodes processed at once |
||
215 | * |
||
216 | * Processing and fetching several attribute items at once speeds up importing |
||
217 | * the XML files. The more items can be processed at once, the faster the |
||
218 | * import. More items also increases the memory usage of the importer and |
||
219 | * thus, this parameter should be low enough to avoid reaching the memory |
||
220 | * limit of the PHP process. |
||
221 | * |
||
222 | * @param integer Number of XML nodes |
||
223 | * @since 2019.04 |
||
224 | * @category Developer |
||
225 | * @category User |
||
226 | * @see controller/jobs/attribute/import/xml/domains |
||
227 | * @see controller/jobs/attribute/import/xml/backup |
||
228 | */ |
||
229 | $maxquery = $config->get( 'controller/jobs/attribute/import/xml/max-query', 1000 ); |
||
230 | |||
231 | |||
232 | $nodes = []; |
||
233 | $total = $slice = 0; |
||
234 | $xml = new \XMLReader(); |
||
235 | |||
236 | if( $xml->open( $filename, LIBXML_COMPACT | LIBXML_PARSEHUGE ) === false ) { |
||
237 | throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No XML file "%1$s" found', $filename ) ); |
||
238 | } |
||
239 | |||
240 | while( $xml->read() === true ) |
||
241 | { |
||
242 | if( $xml->depth === 1 && $xml->nodeType === \XMLReader::ELEMENT && $xml->name === 'attributeitem' ) |
||
243 | { |
||
244 | if( ( $dom = $xml->expand() ) === false ) |
||
245 | { |
||
246 | $msg = sprintf( 'Expanding "%1$s" node failed', 'attributeitem' ); |
||
247 | throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
||
248 | } |
||
249 | |||
250 | $nodes[] = $dom; |
||
251 | |||
252 | if( $slice++ >= $maxquery ) |
||
253 | { |
||
254 | $this->importNodes( $nodes, $domains ); |
||
255 | unset( $nodes ); |
||
256 | $nodes = []; |
||
257 | $slice = 0; |
||
258 | } |
||
259 | |||
260 | $total++; |
||
261 | } |
||
262 | } |
||
263 | |||
264 | $this->importNodes( $nodes, $domains ); |
||
265 | unset( $nodes ); |
||
266 | |||
267 | if( !empty( $backup ) && @rename( $filename, strftime( $backup ) ) === false ) |
||
268 | { |
||
269 | $msg = sprintf( 'Unable to move imported file "%1$s" to "%2$s"', $filename, $backup ); |
||
270 | throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
||
271 | } |
||
272 | |||
273 | return $total; |
||
274 | } |
||
332 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths