| Conditions | 11 |
| Paths | 131 |
| Total Lines | 89 |
| Code Lines | 49 |
| 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 |
||
| 6 | public static function convert($packagedir, $outdir, $objCourse) |
||
| 7 | { |
||
| 8 | $dir = realpath($packagedir); |
||
| 9 | if (empty($dir)) { |
||
| 10 | throw new InvalidArgumentException('Directory does not exist!'); |
||
| 11 | } |
||
| 12 | $odir = realpath($outdir); |
||
| 13 | if (empty($odir)) { |
||
| 14 | throw new InvalidArgumentException('Directory does not exist!'); |
||
| 15 | } |
||
| 16 | |||
| 17 | if (!empty($objCourse)) { |
||
| 18 | //Initialize the manifest metadata class |
||
| 19 | $meta = new CcMetadataManifest(); |
||
| 20 | |||
| 21 | //Package metadata |
||
| 22 | $metageneral = new CcMetadataGeneral(); |
||
| 23 | $metageneral->setLanguage($objCourse->info['language']); |
||
| 24 | $metageneral->setTitle($objCourse->info['title'], $objCourse->info['language']); |
||
| 25 | $metageneral->setDescription('', $objCourse->info['language']); |
||
| 26 | $metageneral->setCatalog('category'); |
||
| 27 | $metageneral->setEntry($objCourse->info['categoryName']); |
||
| 28 | $meta->addMetadataGeneral($metageneral); |
||
| 29 | |||
| 30 | // Create the manifest |
||
| 31 | $manifest = new CcManifest(); |
||
| 32 | |||
| 33 | $manifest->addMetadataManifest($meta); |
||
| 34 | |||
| 35 | $organization = null; |
||
| 36 | |||
| 37 | //Get the course structure - this will be transformed into organization |
||
| 38 | //Step 1 - Get the list and order of sections/topics |
||
| 39 | |||
| 40 | $count = 1; |
||
| 41 | $sections = []; |
||
| 42 | $resources = $objCourse->resources; |
||
| 43 | |||
| 44 | // We check the quiz sections |
||
| 45 | if (isset($resources['quiz'])) { |
||
| 46 | $quizSections = self::getItemSections($resources['quiz'], 'quiz', $count, $objCourse->info['code'], $resources['Exercise_Question']); |
||
| 47 | $sections = array_merge($sections, $quizSections); |
||
| 48 | } |
||
| 49 | |||
| 50 | // We check the document sections |
||
| 51 | if (isset($resources['document'])) { |
||
| 52 | $documentSections = self::getItemSections($resources['document'], 'document', $count, $objCourse->info['code']); |
||
| 53 | $sections = array_merge($sections, $documentSections); |
||
| 54 | } |
||
| 55 | |||
| 56 | // We check the wiki sections |
||
| 57 | if (isset($resources['wiki'])) { |
||
| 58 | $wikiSections = self::getItemSections($resources['wiki'], 'wiki', $count, $objCourse->info['code']); |
||
| 59 | $sections = array_merge($sections, $wikiSections); |
||
| 60 | } |
||
| 61 | |||
| 62 | // We check the forum sections |
||
| 63 | if (isset($resources['forum'])) { |
||
| 64 | $forumSections = self::getItemSections($resources['forum'], 'forum', $count, $objCourse->info['code'], $resources['Forum_Category']); |
||
| 65 | $sections = array_merge($sections, $forumSections); |
||
| 66 | } |
||
| 67 | |||
| 68 | // We check the link sections |
||
| 69 | if (isset($resources['link'])) { |
||
| 70 | $linkSections = self::getItemSections($resources['link'], 'link', $count, $objCourse->info['code'], $resources['Link_Category']); |
||
| 71 | $sections = array_merge($sections, $linkSections); |
||
| 72 | } |
||
| 73 | |||
| 74 | //organization title |
||
| 75 | $organization = new CcOrganization(); |
||
| 76 | foreach ($sections as $sectionid => $values) { |
||
| 77 | $item = new CcItem(); |
||
| 78 | $item->title = $values[0]; |
||
| 79 | self::processSequence($item, $manifest, $values[1], $dir, $odir); |
||
| 80 | $organization->addItem($item); |
||
| 81 | } |
||
| 82 | $manifest->putNodes(); |
||
| 83 | |||
| 84 | if (!empty($organization)) { |
||
| 85 | $manifest->addNewOrganization($organization); |
||
| 86 | } |
||
| 87 | |||
| 88 | $manifestpath = $outdir.DIRECTORY_SEPARATOR.'imsmanifest.xml'; |
||
| 89 | $saved = $manifest->saveTo($manifestpath); |
||
| 90 | |||
| 91 | return $saved; |
||
| 92 | } |
||
| 93 | |||
| 94 | return false; |
||
| 95 | } |
||
| 292 |