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