Failed Conditions
Pull Request — master (#3198)
by
unknown
04:14
created

UserProfile::show()   C

Complexity

Conditions 8
Paths 48

Size

Total Lines 107

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 48
nop 0
dl 0
loc 107
rs 6.7555
c 0
b 0
f 0

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
3
namespace dokuwiki\Ui;
4
5
use dokuwiki\Extension\Event;
6
use dokuwiki\Form\Form;
7
8
/**
9
 * DokuWiki User Profile Interface
10
 *
11
 * @package dokuwiki\Ui
12
 */
13
class UserProfile extends Ui
14
{
15
    /**
16
     * Display the User Profile Form Panel
17
     *
18
     * @author   Andreas Gohr <[email protected]>
19
     *
20
     * @triggers HTML_UPDATEPROFILEFORM_OUTPUT
21
     * @triggers HTML_PROFILEDELETEFORM_OUTPUT
22
     * @return void
23
     */
24
    public function show()
25
    {
26
        global $lang;
27
        global $conf;
28
        global $INPUT;
29
        global $INFO;
30
        /** @var AuthPlugin $auth */
31
        global $auth;
32
33
        // print intro
34
        print p_locale_xhtml('updateprofile');
35
        print '<div class="centeralign">';
36
37
        $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
38
        $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
39
40
        // create the updateprofile form
41
        $form = new Form(['id' => 'dw__register']);
42
        $form->addTagOpen('div')->addClass('no');
43
        $form->addFieldsetOpen($lang['profile']);
44
        $form->setHiddenField('do', 'profile');
45
        $form->setHiddenField('save', '1');
46
47
        $attr = array('size' => '50', 'disabled' => 'disabled');
48
        $input = $form->addTextInput('login', $lang['user'])->attrs($attr)->addClass('edit')
49
            ->val($INPUT->server->str('REMOTE_USER'));
50
        $input->getLabel()->attr('class', 'block');
51
        $form->addHTML("<br>\n");
52
53
        $attr = array('size' => '50');
54
        if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
55
        $input = $form->addTextInput('fullname', $lang['fullname'])->attrs($attr)->addClass('edit')
56
            ->val($fullname);
57
        $input->getLabel()->attr('class', 'block');
58
        $form->addHTML("<br>\n");
59
60
        $attr = array('type' => 'email', 'size' =>  '50');
61
        if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
62
        $input = $form->addTextInput('email', $lang['email'])->attrs($attr)->addClass('edit')
63
            ->val($email);
64
        $input->getLabel()->attr('class', 'block');
65
        $form->addHTML("<br>\n");
66
67
        if ($auth->canDo('modPass')) {
68
            $attr = array('size'=>'50');
69
            $input = $form->addPasswordInput('newpass', $lang['newpass'])->attrs($attr)->addClass('edit');
70
            $input->getLabel()->attr('class', 'block');
71
            $form->addHTML("<br>\n");
72
73
            $input = $form->addPasswordInput('passchk', $lang['passchk'])->attrs($attr)->addClass('edit');
74
            $input->getLabel()->attr('class', 'block');
75
            $form->addHTML("<br>\n");
76
        }
77
78
        if ($conf['profileconfirm']) {
79
            $form->addHTML("<br>\n");
80
            $attr = array('size' => '50', 'required' => 'required');
81
            $input = $form->addPasswordInput('oldpass', $lang['oldpass'])->attrs($attr)->addClass('edit');
82
            $input->getLabel()->attr('class', 'block');
83
            $form->addHTML("<br>\n");
84
        }
85
86
        $form->addButton('', $lang['btn_save'])->attr('type', 'submit');
87
        $form->addButton('', $lang['btn_reset'])->attr('type', 'reset');
88
89
        $form->addFieldsetClose();
90
        $form->addTagClose('div');
91
92
        // emit HTML_UPDATEPROFILEFORM_OUTPUT event
93
        Event::createAndTrigger('HTML_UPDATEPROFILEFORM_OUTPUT', $form, null, false);
94
        print $form->toHTML();
95
96
97
        if ($auth->canDo('delUser') && actionOK('profile_delete')) {
98
99
            // create the profiledelete form
100
            $form = new Form(['id' => 'dw__profiledelete']);
101
            $form->addTagOpen('div')->addClass('no');
102
            $form->addFieldsetOpen($lang['profdeleteuser']);
103
            $form->setHiddenField('do', 'profile_delete');
104
            $form->setHiddenField('delete', '1');
105
106
            $form->addCheckbox('confirm_delete', $lang['profconfdelete'])
107
                ->attrs(['required' => 'required'])
108
                ->id('dw__confirmdelete')
109
                ->val('1');
110
111
            if ($conf['profileconfirm']) {
112
                $form->addHTML("<br>\n");
113
                $attr = array('size' => '50', 'required' => 'required');
114
                $input = $form->addPasswordInput('oldppass', $lang['oldpass'])->attrs($attr)
115
                    ->addClass('edit');
116
                $input->getLabel()->attr('class', 'block');
117
                $form->addHTML("<br>\n");
118
            }
119
120
            $form->addButton('', $lang['btn_deleteuser'])->attr('type', 'submit');
121
            $form->addFieldsetClose();
122
            $form->addTagClose('div');
123
124
            // emit HTML_PROFILEDELETEFORM_OUTPUT event
125
            Event::createAndTrigger('HTML_PROFILEDELETEFORM_OUTPUT', $form, null, false);
126
            print $form->toHTML();
127
        }
128
129
        print '</div>';
130
    }
131
132
}
133