| Conditions | 5 |
| Paths | 6 |
| Total Lines | 54 |
| Code Lines | 38 |
| 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 |
||
| 25 | public function up(Schema $schema): void |
||
| 26 | { |
||
| 27 | $kernel = $this->container->get('kernel'); |
||
|
|
|||
| 28 | $rootPath = $kernel->getProjectDir(); |
||
| 29 | |||
| 30 | $batchSize = self::BATCH_SIZE; |
||
| 31 | $counter = 1; |
||
| 32 | $dql = 'SELECT v FROM Chamilo\CoreBundle\Entity\ExtraFieldValues v'; |
||
| 33 | $dql .= ' JOIN v.field f'; |
||
| 34 | $dql .= ' WHERE f.variable = :variable AND f.itemType = :itemType'; |
||
| 35 | $q = $this->entityManager->createQuery($dql); |
||
| 36 | $q->setParameters([ |
||
| 37 | 'variable' => 'image', |
||
| 38 | 'itemType' => ExtraField::SESSION_FIELD_TYPE, |
||
| 39 | ]); |
||
| 40 | |||
| 41 | $sessionRepo = $this->container->get(SessionRepository::class); |
||
| 42 | |||
| 43 | /** @var ExtraFieldValues $item */ |
||
| 44 | foreach ($q->toIterable() as $item) { |
||
| 45 | $path = $item->getFieldValue(); |
||
| 46 | if (empty($path)) { |
||
| 47 | continue; |
||
| 48 | } |
||
| 49 | $filePath = $rootPath.'/app/upload/'.$path; |
||
| 50 | error_log('MIGRATIONS :: $filePath -- '.$filePath.' ...'); |
||
| 51 | if ($this->fileExists($filePath)) { |
||
| 52 | $fileName = basename($path); |
||
| 53 | $mimeType = mime_content_type($filePath); |
||
| 54 | $file = new UploadedFile($filePath, $fileName, $mimeType, null, true); |
||
| 55 | $asset = (new Asset()) |
||
| 56 | ->setCategory(Asset::SESSION) |
||
| 57 | ->setTitle($fileName) |
||
| 58 | ->setFile($file) |
||
| 59 | ; |
||
| 60 | $this->entityManager->persist($asset); |
||
| 61 | $this->entityManager->flush(); |
||
| 62 | $item->setAsset($asset); |
||
| 63 | $this->entityManager->persist($item); |
||
| 64 | |||
| 65 | $sessionId = $item->getItemId(); |
||
| 66 | |||
| 67 | /** @var Session $session */ |
||
| 68 | $session = $sessionRepo->find($sessionId); |
||
| 69 | $session->setImage($asset); |
||
| 70 | $sessionRepo->update($session); |
||
| 71 | } |
||
| 72 | |||
| 73 | if (($counter % $batchSize) === 0) { |
||
| 74 | $this->entityManager->flush(); |
||
| 75 | } |
||
| 76 | $counter++; |
||
| 77 | } |
||
| 78 | $this->entityManager->flush(); |
||
| 79 | } |
||
| 83 |
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.