Passed
Push — master ( 65060b...2b54a2 )
by Julito
10:15
created

FrmEdit::build()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 56
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 39
c 1
b 0
f 0
nc 8
nop 1
dl 0
loc 56
rs 8.3626

How to fix   Long Method   

Long Method

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:

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
5
6
/**
7
 * Class FrmAdd.
8
 */
9
class FrmEdit extends FormValidator
10
{
11
    /**
12
     * @var ImsLtiTool|null
13
     */
14
    private $tool;
15
16
    /**
17
     * FrmAdd constructor.
18
     *
19
     * @param string          $name
20
     * @param array           $attributes
21
     * @param ImsLtiTool|null $tool
22
     */
23
    public function __construct(
24
        $name,
25
        $attributes = [],
26
        ImsLtiTool $tool = null
27
    ) {
28
        parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL, true);
29
30
        $this->tool = $tool;
31
    }
32
33
    /**
34
     * Build the form.
35
     *
36
     * @param bool $globalMode
37
     *
38
     * @throws Exception
39
     */
40
    public function build($globalMode = true)
41
    {
42
        $plugin = ImsLtiPlugin::create();
43
        $course = $this->tool->getCourse();
0 ignored issues
show
Bug introduced by
The method getCourse() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        /** @scrutinizer ignore-call */ 
44
        $course = $this->tool->getCourse();

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.

Loading history...
44
        $parent = $this->tool->getParent();
45
46
        $this->addHeader($plugin->get_lang('ToolSettings'));
47
48
        if (null !== $course && $globalMode) {
49
            $this->addHtml(
50
                Display::return_message(
51
                    sprintf($plugin->get_lang('ToolAddedOnCourseX'), $course->getTitle()),
52
                    'normal',
53
                    false
54
                )
55
            );
56
        }
57
58
        $this->addText('name', get_lang('Name'));
59
        $this->addTextarea('description', get_lang('Description'));
60
61
        if (null === $parent) {
62
            $this->addElement('url', 'launch_url', $plugin->get_lang('LaunchUrl'));
63
            $this->addRule('launch_url', get_lang('Required'), 'required');
64
            $this->addText('consumer_key', $plugin->get_lang('ConsumerKey'));
65
            $this->addText('shared_secret', $plugin->get_lang('SharedSecret'));
66
        }
67
68
        $this->addButtonAdvancedSettings('lti_adv');
69
        $this->addHtml('<div id="lti_adv_options" style="display:none;">');
70
        $this->addTextarea(
71
            'custom_params',
72
            [$plugin->get_lang('CustomParams'), $plugin->get_lang('CustomParamsHelp')]
73
        );
74
75
        if (null === $parent ||
76
            (null !== $parent && !$parent->isActiveDeepLinking())
77
        ) {
78
            $this->addCheckBox(
79
                'deep_linking',
80
                [null, $plugin->get_lang('SupportDeppLinkingHelp'), null],
81
                $plugin->get_lang('SupportDeepLinking')
82
            );
83
        }
84
85
        $this->addHtml('</div>');
86
        $this->addButtonAdvancedSettings('lti_privacy', get_lang('Privacy'));
87
        $this->addHtml('<div id="lti_privacy_options" style="display:none;">');
88
        $this->addCheckBox('share_name', null, $plugin->get_lang('ShareLauncherName'));
89
        $this->addCheckBox('share_email', null, $plugin->get_lang('ShareLauncherEmail'));
90
        $this->addCheckBox('share_picture', null, $plugin->get_lang('ShareLauncherPicture'));
91
        $this->addHtml('</div>');
92
        $this->addButtonCreate($plugin->get_lang('EditExternalTool'));
93
        $this->addHidden('id', $this->tool->getId());
94
        $this->addHidden('action', 'edit');
95
        $this->applyFilter('__ALL__', 'Security::remove_XSS');
96
    }
97
98
    public function setDefaultValues()
99
    {
100
        $this->setDefaults(
101
            [
102
                'name' => $this->tool->getName(),
103
                'description' => $this->tool->getDescription(),
104
                'launch_url' => $this->tool->getLaunchUrl(),
105
                'consumer_key' => $this->tool->getConsumerKey(),
106
                'shared_secret' => $this->tool->getSharedSecret(),
107
                'custom_params' => $this->tool->getCustomParams(),
108
                'deep_linking' => $this->tool->isActiveDeepLinking(),
109
                'share_name' => $this->tool->isSharingName(),
110
                'share_email' => $this->tool->isSharingEmail(),
111
                'share_picture' => $this->tool->isSharingPicture(),
112
            ]
113
        );
114
    }
115
}
116