| Conditions | 9 |
| Paths | 48 |
| Total Lines | 122 |
| Code Lines | 82 |
| 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 |
||
| 45 | && !empty($this->baseTool->publicKey) |
||
| 46 | && !empty($this->baseTool->getClientId()) |
||
| 47 | && !empty($this->baseTool->getLoginUrl()) |
||
| 48 | && !empty($this->baseTool->getRedirectUrl()); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Build the form |
||
| 53 | */ |
||
| 54 | public function build() |
||
| 55 | { |
||
| 56 | $plugin = ImsLtiPlugin::create(); |
||
| 57 | |||
| 58 | $this->addHeader($plugin->get_lang('ToolSettings')); |
||
| 59 | $this->addText('name', get_lang('Name')); |
||
| 60 | $this->addTextarea('description', get_lang('Description')); |
||
| 61 | |||
| 62 | if (null === $this->baseTool) { |
||
| 63 | $this->addUrl('launch_url', $plugin->get_lang('LaunchUrl'), true); |
||
| 64 | $this->addRadio( |
||
| 65 | 'version', |
||
| 66 | $plugin->get_lang('LtiVersion'), |
||
| 67 | [ |
||
| 68 | ImsLti::V_1P1 => 'LTI 1.0 / 1.1', |
||
| 69 | ImsLti::V_1P3 => 'LTI 1.3.0', |
||
| 70 | ] |
||
| 71 | ); |
||
| 72 | $this->addHtml('<div class="'.ImsLti::V_1P1.'" style="display: block;">'); |
||
| 73 | $this->addText('consumer_key', $plugin->get_lang('ConsumerKey'), false); |
||
| 74 | $this->addText('shared_secret', $plugin->get_lang('SharedSecret'), false); |
||
| 75 | $this->addHtml('</div>'); |
||
| 76 | $this->addHtml('<div class="'.ImsLti::V_1P3.'" style="display: none;">'); |
||
| 77 | $this->addTextarea( |
||
| 78 | 'public_key', |
||
| 79 | $plugin->get_lang('PublicKey'), |
||
| 80 | ['style' => 'font-family: monospace;', 'rows' => 5] |
||
| 81 | ); |
||
| 82 | $this->addUrl('login_url', $plugin->get_lang('LoginUrl'), false); |
||
| 83 | $this->addUrl('redirect_url', $plugin->get_lang('RedirectUrl'), false); |
||
| 84 | $this->addHtml('</div>'); |
||
| 85 | } |
||
| 86 | |||
| 87 | $this->addButtonAdvancedSettings('lti_adv'); |
||
| 88 | $this->addHtml('<div id="lti_adv_options" style="display:none;">'); |
||
| 89 | $this->addTextarea( |
||
| 90 | 'custom_params', |
||
| 91 | [$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')] |
||
| 92 | ); |
||
| 93 | $this->addSelect( |
||
| 94 | 'document_target', |
||
| 95 | get_lang('LinkTarget'), |
||
| 96 | ['iframe' => 'iframe', 'window' => 'window'] |
||
| 97 | ); |
||
| 98 | |||
| 99 | if (null === $this->baseTool |
||
| 100 | || ($this->baseTool && !$this->baseTool->isActiveDeepLinking()) |
||
| 101 | ) { |
||
| 102 | $this->addCheckBox( |
||
| 103 | 'deep_linking', |
||
| 104 | [null, $plugin->get_lang('SupportDeppLinkingHelp'), null], |
||
| 105 | $plugin->get_lang('SupportDeepLinking') |
||
| 106 | ); |
||
| 107 | } |
||
| 108 | |||
| 109 | $showAGS = false; |
||
| 110 | |||
| 111 | if (api_get_course_int_id()) { |
||
| 112 | $caterories = Category::load(null, null, api_get_course_id()); |
||
| 113 | |||
| 114 | if (!empty($caterories)) { |
||
| 115 | $showAGS = true; |
||
| 116 | } |
||
| 117 | } else { |
||
| 118 | $showAGS = true; |
||
| 119 | } |
||
| 120 | |||
| 121 | $this->addHtml('<div class="'.ImsLti::V_1P3.'" style="display: none;">'); |
||
| 122 | |||
| 123 | if ($showAGS) { |
||
| 124 | $this->addRadio( |
||
| 125 | '1p3_ags', |
||
| 126 | $plugin->get_lang('AssigmentAndGradesService'), |
||
| 127 | [ |
||
| 128 | LtiAssignmentGradesService::AGS_NONE => $plugin->get_lang('DontUseService'), |
||
| 129 | LtiAssignmentGradesService::AGS_SIMPLE => $plugin->get_lang('AGServiceSimple'), |
||
| 130 | LtiAssignmentGradesService::AGS_FULL => $plugin->get_lang('AGServiceFull'), |
||
| 131 | ] |
||
| 132 | ); |
||
| 133 | } else { |
||
| 134 | $gradebookUrl = api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(); |
||
| 135 | |||
| 136 | $this->addLabel( |
||
| 137 | $plugin->get_lang('AssigmentAndGradesService'), |
||
| 138 | sprintf( |
||
| 139 | $plugin->get_lang('YouNeedCreateTheGradebokInCourseFirst'), |
||
| 140 | Display::url($gradebookUrl, $gradebookUrl) |
||
| 141 | ) |
||
| 142 | ); |
||
| 143 | } |
||
| 144 | |||
| 145 | $this->addRadio( |
||
| 146 | '1p3_nrps', |
||
| 147 | $plugin->get_lang('NamesAndRoleProvisioningService'), |
||
| 148 | [ |
||
| 149 | LtiNamesRoleProvisioningService::NRPS_NONE => $plugin->get_lang('DontUseService'), |
||
| 150 | LtiNamesRoleProvisioningService::NRPS_CONTEXT_MEMBERSHIP => $plugin->get_lang('UseService'), |
||
| 151 | ] |
||
| 152 | ); |
||
| 153 | $this->addHtml('</div>'); |
||
| 154 | |||
| 155 | if (!$this->baseTool) { |
||
| 156 | $this->addText( |
||
| 157 | 'replacement_user_id', |
||
| 158 | [ |
||
| 159 | $plugin->get_lang('ReplacementUserId'), |
||
| 160 | $plugin->get_lang('ReplacementUserIdHelp'), |
||
| 161 | ], |
||
| 162 | false |
||
| 163 | ); |
||
| 164 | $this->applyFilter('replacement_user_id', 'trim'); |
||
| 165 | } |
||
| 166 | |||
| 167 | $this->addHtml('</div>'); |
||
| 221 |