Conditions | 8 |
Paths | 32 |
Total Lines | 53 |
Code Lines | 35 |
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 |
||
40 | public function generateImportData(): void |
||
41 | { |
||
42 | $countInstances = 0; |
||
43 | $xpath = static::newxPath(static::$manifest, static::$namespaces); |
||
44 | // Scan for detached resources of type 'webcontent' |
||
45 | $resources = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@type="'.static::CC_TYPE_WEBCONTENT.'"]'); |
||
46 | $this->createInstances($resources, 0, $countInstances); |
||
47 | |||
48 | // Scan for organization items or resources that are tests (question banks) |
||
49 | $items = $xpath->query('/imscc:manifest/imscc:organizations/imscc:organization/imscc:item | /imscc:manifest/imscc:resources/imscc:resource[@type="'.static::CC_TYPE_QUESTION_BANK.'"]'); |
||
50 | $this->createInstances($items, 0,$countInstances); |
||
51 | |||
52 | $resources = new Cc13Resource(); |
||
53 | $forums = new Cc13Forum(); |
||
54 | $quiz = new Cc13Quiz(); |
||
55 | |||
56 | // Get the embedded XML files describing resources to import |
||
57 | $documentValues = $resources->generateData('document'); |
||
58 | $linkValues = $resources->generateData('link'); |
||
59 | $forumValues = $forums->generateData(); |
||
60 | $quizValues = $quiz->generateData(); |
||
61 | |||
62 | if (!empty($forums) or !empty($quizValues) or !empty($documentValues)) { |
||
63 | $courseInfo = api_get_course_info(); |
||
64 | $sessionId = api_get_session_id(); |
||
65 | $groupId = api_get_group_id(); |
||
66 | $documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['directory'].'/document'; |
||
67 | |||
68 | create_unexisting_directory( |
||
69 | $courseInfo, |
||
70 | api_get_user_id(), |
||
71 | $sessionId, |
||
72 | $groupId, |
||
73 | null, |
||
74 | $documentPath, |
||
75 | '/commoncartridge', |
||
76 | 'Common Cartridge folder', |
||
77 | 0 |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | // Import the resources, by type |
||
82 | if (!empty($forums)) { |
||
83 | $saved = $forums->storeForums($forumValues); |
||
84 | } |
||
85 | if (!empty($quizValues)) { |
||
86 | $saved = $quiz->storeQuizzes($quizValues); |
||
87 | } |
||
88 | if (!empty($documentValues)) { |
||
89 | $saved = $resources->storeDocuments($documentValues, static::$pathToManifestFolder); |
||
90 | } |
||
91 | if (!empty($linkValues)) { |
||
92 | $saved = $resources->storeLinks($linkValues); |
||
93 | } |
||
96 |