Conditions | 10 |
Paths | 10 |
Total Lines | 110 |
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 |
||
131 | protected function import( $filename ) |
||
132 | { |
||
133 | $context = $this->getContext(); |
||
134 | $config = $context->getConfig(); |
||
135 | $domains = ['customer', 'customer/address', 'customer/property', 'media', 'product', 'text']; |
||
136 | |||
137 | /** controller/jobs/customer/import/xml/domains |
||
138 | * List of item domain names that should be retrieved along with the customer items |
||
139 | * |
||
140 | * This configuration setting overwrites the shared option |
||
141 | * "controller/common/customer/import/xml/domains" if you need a |
||
142 | * specific setting for the job controller. Otherwise, you should |
||
143 | * use the shared option for consistency. |
||
144 | * |
||
145 | * @param array Associative list of MShop item domain names |
||
146 | * @since 2019.04 |
||
147 | * @category Developer |
||
148 | * @see controller/jobs/customer/import/xml/backup |
||
149 | * @see controller/jobs/customer/import/xml/max-query |
||
150 | */ |
||
151 | $domains = $config->get( 'controller/jobs/customer/import/xml/domains', $domains ); |
||
152 | |||
153 | /** controller/jobs/customer/import/xml/backup |
||
154 | * Name of the backup for sucessfully imported files |
||
155 | * |
||
156 | * After a XML file was imported successfully, you can move it to another |
||
157 | * location, so it won't be imported again and isn't overwritten by the |
||
158 | * next file that is stored at the same location in the file system. |
||
159 | * |
||
160 | * You should use an absolute path to be sure but can be relative path |
||
161 | * if you absolutely know from where the job will be executed from. The |
||
162 | * name of the new backup location can contain placeholders understood |
||
163 | * by the PHP strftime() function to create dynamic paths, e.g. "backup/%Y-%m-%d" |
||
164 | * which would create "backup/2000-01-01". For more information about the |
||
165 | * strftime() placeholders, please have a look into the PHP documentation of |
||
166 | * the {@link http://php.net/manual/en/function.strftime.php strftime() function}. |
||
167 | * |
||
168 | * '''Note:''' If no backup name is configured, the file or directory |
||
169 | * won't be moved away. Please make also sure that the parent directory |
||
170 | * and the new directory are writable so the file or directory could be |
||
171 | * moved. |
||
172 | * |
||
173 | * @param integer Name of the backup file, optionally with date/time placeholders |
||
174 | * @since 2019.04 |
||
175 | * @category Developer |
||
176 | * @see controller/jobs/customer/import/xml/domains |
||
177 | * @see controller/jobs/customer/import/xml/max-query |
||
178 | */ |
||
179 | $backup = $config->get( 'controller/jobs/customer/import/xml/backup' ); |
||
180 | |||
181 | /** controller/jobs/customer/import/xml/max-query |
||
182 | * Maximum number of XML nodes processed at once |
||
183 | * |
||
184 | * Processing and fetching several customer items at once speeds up importing |
||
185 | * the XML files. The more items can be processed at once, the faster the |
||
186 | * import. More items also increases the memory usage of the importer and |
||
187 | * thus, this parameter should be low enough to avoid reaching the memory |
||
188 | * limit of the PHP process. |
||
189 | * |
||
190 | * @param integer Number of XML nodes |
||
191 | * @since 2019.04 |
||
192 | * @category Developer |
||
193 | * @category User |
||
194 | * @see controller/jobs/customer/import/xml/domains |
||
195 | * @see controller/jobs/customer/import/xml/backup |
||
196 | */ |
||
197 | $maxquery = $config->get( 'controller/jobs/customer/import/xml/max-query', 1000 ); |
||
198 | |||
199 | $nodes = []; |
||
200 | $total = $slice = 0; |
||
201 | $xml = new \XMLReader(); |
||
202 | |||
203 | if( $xml->open( $filename, LIBXML_COMPACT | LIBXML_PARSEHUGE ) === false ) { |
||
204 | throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No XML file "%1$s" found', $filename ) ); |
||
205 | } |
||
206 | |||
207 | while( $xml->read() === true ) |
||
208 | { |
||
209 | if( $xml->depth === 1 && $xml->nodeType === \XMLReader::ELEMENT && $xml->name === 'customeritem' ) |
||
210 | { |
||
211 | if( ( $dom = $xml->expand() ) === false ) |
||
212 | { |
||
213 | $msg = sprintf( 'Expanding "%1$s" node failed', 'customeritem' ); |
||
214 | throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
||
215 | } |
||
216 | |||
217 | $nodes[] = $dom; |
||
218 | |||
219 | if( $slice++ >= $maxquery ) |
||
220 | { |
||
221 | $this->importNodes( $nodes, $domains ); |
||
222 | unset( $nodes ); |
||
223 | $nodes = []; |
||
224 | $slice = 0; |
||
225 | } |
||
226 | |||
227 | $total++; |
||
228 | } |
||
229 | } |
||
230 | |||
231 | $this->importNodes( $nodes, $domains ); |
||
232 | unset( $nodes ); |
||
233 | |||
234 | if( !empty( $backup ) && @rename( $filename, strftime( $backup ) ) === false ) |
||
235 | { |
||
236 | $msg = sprintf( 'Unable to move imported file "%1$s" to "%2$s"', $filename, $backup ); |
||
237 | throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
||
238 | } |
||
239 | |||
240 | return $total; |
||
241 | } |
||
309 |
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