We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 8 |
| Paths | 19 |
| Total Lines | 78 |
| Code Lines | 50 |
| 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 |
||
| 238 | protected function migrateField($table, $row) |
||
| 239 | { |
||
| 240 | $fieldItem = trim($row[$this->fieldsToMigrate[$table]]); |
||
| 241 | |||
| 242 | if (empty($fieldItem) || is_numeric($fieldItem)) { |
||
| 243 | return; |
||
| 244 | } |
||
| 245 | $fileadminDirectory = rtrim($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/') . '/'; |
||
| 246 | $i = 0; |
||
| 247 | |||
| 248 | $storageUid = (int)$this->storage->getUid(); |
||
| 249 | $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
||
| 250 | |||
| 251 | $fileUid = null; |
||
| 252 | $sourcePath = Environment::getPublicPath() . '/' . $fieldItem; |
||
| 253 | |||
| 254 | // maybe the file was already moved, so check if the original file still exists |
||
| 255 | if (file_exists($sourcePath)) { |
||
| 256 | $title = 'Migrate field ' . $sourcePath; |
||
| 257 | |||
| 258 | // see if the file already exists in the storage |
||
| 259 | $fileSha1 = sha1_file($sourcePath); |
||
| 260 | |||
| 261 | $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
||
| 262 | $existingFileRecord = $queryBuilder->select('uid')->from('sys_file')->where( |
||
| 263 | $queryBuilder->expr()->eq( |
||
| 264 | 'missing', |
||
| 265 | $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT) |
||
| 266 | ), |
||
| 267 | $queryBuilder->expr()->eq( |
||
| 268 | 'sha1', |
||
| 269 | $queryBuilder->createNamedParameter($fileSha1, \PDO::PARAM_STR) |
||
| 270 | ), |
||
| 271 | $queryBuilder->expr()->eq( |
||
| 272 | 'storage', |
||
| 273 | $queryBuilder->createNamedParameter($storageUid, \PDO::PARAM_INT) |
||
| 274 | ) |
||
| 275 | )->execute()->fetch(); |
||
| 276 | |||
| 277 | // the file exists |
||
| 278 | if (is_array($existingFileRecord)) { |
||
| 279 | $fileUid = $existingFileRecord['uid']; |
||
| 280 | } |
||
| 281 | } |
||
| 282 | |||
| 283 | if ($fileUid > 0) { |
||
| 284 | $fields = [ |
||
| 285 | 'fieldname' => $this->fieldsToMigrate[$table], |
||
| 286 | 'table_local' => 'sys_file', |
||
| 287 | 'pid' => ($table === 'pages' ? $row['uid'] : $row['pid']), |
||
| 288 | 'uid_foreign' => $row['uid'], |
||
| 289 | 'uid_local' => $fileUid, |
||
| 290 | 'tablenames' => $table, |
||
| 291 | 'crdate' => time(), |
||
| 292 | 'tstamp' => time(), |
||
| 293 | 'sorting_foreign' => $i, |
||
| 294 | ]; |
||
| 295 | |||
| 296 | $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file_reference'); |
||
| 297 | |||
| 298 | $result = $queryBuilder |
||
| 299 | ->insert('sys_file_reference') |
||
| 300 | ->values($fields) |
||
| 301 | ->execute(); |
||
| 302 | |||
| 303 | ++$i; |
||
| 304 | } |
||
| 305 | |||
| 306 | // Update referencing table's original field to now contain the count of references, |
||
| 307 | // but only if all new references could be set |
||
| 308 | if ($i === 1) { |
||
| 309 | $queryBuilder = $connectionPool->getQueryBuilderForTable($table); |
||
| 310 | $queryBuilder->update($table)->where( |
||
| 311 | $queryBuilder->expr()->eq( |
||
| 312 | 'uid', |
||
| 313 | $queryBuilder->createNamedParameter($row['uid'], \PDO::PARAM_INT) |
||
| 314 | ) |
||
| 315 | )->set($this->fieldsToMigrate[$table], $i)->execute(); |
||
| 316 | } |
||
| 319 |
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