Conditions | 7 |
Paths | 3 |
Total Lines | 80 |
Code Lines | 52 |
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 |
||
24 | public function up(Schema $schema): void |
||
25 | { |
||
26 | $this->log('Starting SCORM migration...'); |
||
27 | |||
28 | $assetRepo = $this->container->get( AssetRepository::class); |
||
|
|||
29 | $lpRepo = $this->container->get(CLpRepository::class);; |
||
30 | |||
31 | $courses = $this->entityManager->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c')->toIterable(); |
||
32 | |||
33 | foreach ($courses as $course) { |
||
34 | $courseId = $course->getId(); |
||
35 | $courseDir = $course->getDirectory(); |
||
36 | $this->log("Processing course ID: $courseId - Directory: $courseDir"); |
||
37 | |||
38 | $scorms = $lpRepo->createQueryBuilder('lp') |
||
39 | ->join('lp.resourceNode', 'rn') |
||
40 | ->join('rn.resourceLinks', 'rl') |
||
41 | ->where('lp.lpType = :type') |
||
42 | ->andWhere('rl.course = :course') |
||
43 | ->setParameter('type', CLp::SCORM_TYPE) |
||
44 | ->setParameter('course', $course) |
||
45 | ->getQuery() |
||
46 | ->getResult(); |
||
47 | |||
48 | if (empty($scorms)) { |
||
49 | $this->log("No SCORMs found for course $courseDir"); |
||
50 | continue; |
||
51 | } |
||
52 | |||
53 | foreach ($scorms as $lp) { |
||
54 | $lpId = $lp->getIid(); |
||
55 | $path = rtrim($lp->getPath(), '/.'); |
||
56 | |||
57 | $this->log("Processing SCORM LP id=$lpId path=$path"); |
||
58 | |||
59 | $folderPath = $this->getUpdateRootPath()."/app/courses/$courseDir/scorm/$path"; |
||
60 | |||
61 | if (!is_dir($folderPath)) { |
||
62 | $this->log("SCORM folder not found: $folderPath"); |
||
63 | continue; |
||
64 | } |
||
65 | |||
66 | $zipName = basename($path).'.zip'; |
||
67 | $tmpZipPath = "/tmp/$zipName"; |
||
68 | |||
69 | if (!file_exists($tmpZipPath)) { |
||
70 | $this->log("Zipping SCORM folder: $folderPath -> $tmpZipPath"); |
||
71 | $this->zipFolder($folderPath, $tmpZipPath); |
||
72 | } |
||
73 | |||
74 | if (!file_exists($tmpZipPath)) { |
||
75 | $this->log("Failed to create zip: $tmpZipPath"); |
||
76 | continue; |
||
77 | } |
||
78 | |||
79 | $file = new UploadedFile($tmpZipPath, $zipName, 'application/zip', null, true); |
||
80 | |||
81 | $asset = new Asset(); |
||
82 | $asset->setCategory(Asset::SCORM) |
||
83 | ->setTitle($zipName) |
||
84 | ->setFile($file) |
||
85 | ->setCompressed(true); |
||
86 | |||
87 | $assetRepo->update($asset); |
||
88 | |||
89 | $this->log("Asset created: id=".$asset->getId()); |
||
90 | |||
91 | $assetRepo->unZipFile($asset, basename($path)); |
||
92 | $this->log("Asset unzipped for: ".$asset->getTitle()); |
||
93 | |||
94 | $lp->setAsset($asset); |
||
95 | $lp->setPath(basename($path).'/.'); |
||
96 | $this->entityManager->persist($lp); |
||
97 | $this->entityManager->flush(); |
||
98 | |||
99 | $this->log("LP updated id=$lpId linked to asset_id=".$asset->getId()); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | $this->log('Finished SCORM migration.'); |
||
104 | } |
||
135 |
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.