| Conditions | 15 |
| Paths | 23 |
| Total Lines | 69 |
| Code Lines | 45 |
| 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 |
||
| 22 | public function up(Schema $schema): void |
||
| 23 | { |
||
| 24 | $quizQuestionRepo = $this->container->get(CQuizQuestionRepository::class); |
||
|
|
|||
| 25 | $documentRepo = $this->container->get(CDocumentRepository::class); |
||
| 26 | |||
| 27 | $questions = $quizQuestionRepo->findAll(); |
||
| 28 | |||
| 29 | foreach ($questions as $question) { |
||
| 30 | $courseAdmin = $this->getAdmin(); |
||
| 31 | $pictureId = $question->getPicture(); |
||
| 32 | $course = null; |
||
| 33 | |||
| 34 | if (!$question->hasResourceNode()) { |
||
| 35 | if ($pictureId) { |
||
| 36 | $document = $this->findDocumentByPictureId($pictureId, $documentRepo); |
||
| 37 | if ($document && $document->hasResourceNode() && $document->getResourceNode()->getResourceLinks()->first()) { |
||
| 38 | $course = $document->getResourceNode()->getResourceLinks()->first()->getCourse(); |
||
| 39 | error_log('Creating resource node for question IID ' . $question->getIid()); |
||
| 40 | |||
| 41 | $resourceNode = $quizQuestionRepo->addResourceNode($question, $courseAdmin, $course); |
||
| 42 | $this->entityManager->persist($resourceNode); |
||
| 43 | |||
| 44 | // Flush here to ensure the resource node is saved |
||
| 45 | $this->entityManager->flush(); |
||
| 46 | } else { |
||
| 47 | error_log('No course association for question IID ' . $question->getIid() . ' with document ' . $pictureId); |
||
| 48 | continue; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | if ($question->hasResourceNode() && $pictureId && !$question->getResourceNode()->hasResourceFile()) { |
||
| 54 | error_log('Existing resource node found for question IID ' . $question->getIid() . ' but no ResourceFile.'); |
||
| 55 | |||
| 56 | $document = $this->findDocumentByPictureId($pictureId, $documentRepo); |
||
| 57 | if ($document) { |
||
| 58 | error_log('Document found for picture ID ' . $pictureId . ' and question IID ' . $question->getIid()); |
||
| 59 | |||
| 60 | if ($document->hasResourceNode() && !$document->getResourceNode()->hasResourceFile()) { |
||
| 61 | $course = $document->getResourceNode()->getResourceLinks()->first()->getCourse(); |
||
| 62 | $filePath = $this->getUpdateRootPath() . '/app/courses/' . $course->getDirectory() . '/document/images/' . $document->getTitle(); |
||
| 63 | if (file_exists($filePath)) { |
||
| 64 | $this->addLegacyFileToResource($filePath, $documentRepo, $document, $document->getIid()); |
||
| 65 | $this->entityManager->persist($document); |
||
| 66 | $this->entityManager->flush(); |
||
| 67 | error_log('ResourceFile created and flushed for document with IID ' . $document->getIid()); |
||
| 68 | } else { |
||
| 69 | continue; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | if ($document->getResourceNode()->hasResourceFile()) { |
||
| 74 | $resourceFile = $document->getResourceNode()->getResourceFiles()->first(); |
||
| 75 | error_log('Resource file ready for question IID ' . $question->getIid() . ': ' . $resourceFile->getOriginalName()); |
||
| 76 | |||
| 77 | $contents = $documentRepo->getResourceFileContent($document); |
||
| 78 | $quizQuestionRepo->addFileFromString( |
||
| 79 | $question, |
||
| 80 | $resourceFile->getOriginalName(), |
||
| 81 | $resourceFile->getMimeType(), |
||
| 82 | $contents |
||
| 83 | ); |
||
| 84 | $this->entityManager->persist($question); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | $this->entityManager->flush(); |
||
| 91 | } |
||
| 102 |
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.