Failed Conditions
Push — master ( 96da53...0afbc1 )
by Andreas
06:02 queued 03:20
created

UserProfile::show()   C

Complexity

Conditions 8
Paths 48

Size

Total Lines 103

Duplication

Lines 0
Ratio 0 %

Importance

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