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