Completed
Pull Request — develop (#209)
by Felipe
26:08 queued 36s
created

DomainsController::doProperties()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 125
Code Lines 84

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 84
nc 10
nop 1
dl 0
loc 125
rs 8.1463
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
/**
4
 * PHPPgAdmin v6.0.0-beta.48
5
 */
6
7
namespace PHPPgAdmin\Controller;
8
9
use PHPPgAdmin\Decorators\Decorator;
10
11
/**
12
 * Base controller class.
13
 *
14
 * @package PHPPgAdmin
15
 */
16
class DomainsController extends BaseController
1 ignored issue
show
Coding Style introduced by
The property $controller_title is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
17
{
18
    public $controller_title = 'strdomains';
19
20
    /**
21
     * Default method to render the controller according to the action parameter.
22
     */
23
    public function render()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
24
    {
25
        if ('tree' == $this->action) {
26
            return $this->doTree();
27
        }
28
29
        $this->printHeader();
30
        $this->printBody();
31
32
        switch ($this->action) {
33
            case 'add_check':
34
                $this->addCheck(true);
35
36
                break;
37
            case 'save_add_check':
38
                if (isset($_POST['cancel'])) {
39
                    $this->doProperties();
40
                } else {
41
                    $this->addCheck(false);
42
                }
43
44
                break;
45
            case 'drop_con':
46
                if (isset($_POST['drop'])) {
47
                    $this->doDropConstraint(false);
48
                } else {
49
                    $this->doProperties();
50
                }
51
52
                break;
53
            case 'confirm_drop_con':
54
                $this->doDropConstraint(true);
55
56
                break;
57
            case 'save_create':
58
                if (isset($_POST['cancel'])) {
59
                    $this->doDefault();
60
                } else {
61
                    $this->doSaveCreate();
62
                }
63
64
                break;
65
            case 'create':
66
                $this->doCreate();
67
68
                break;
69
            case 'drop':
70
                if (isset($_POST['drop'])) {
71
                    $this->doDrop(false);
72
                } else {
73
                    $this->doDefault();
74
                }
75
76
                break;
77
            case 'confirm_drop':
78
                $this->doDrop(true);
79
80
                break;
81
            case 'save_alter':
82
                if (isset($_POST['alter'])) {
83
                    $this->doSaveAlter();
84
                } else {
85
                    $this->doProperties();
86
                }
87
88
                break;
89
            case 'alter':
90
                $this->doAlter();
91
92
                break;
93
            case 'properties':
94
                $this->doProperties();
95
96
                break;
97
            default:
98
                $this->doDefault();
99
100
                break;
101
        }
102
103
        return $this->printFooter();
104
    }
105
106
    /**
107
     * Show default list of domains in the database.
108
     *
109
     * @param mixed $msg
110
     */
111
    public function doDefault($msg = '')
112
    {
113
        $data = $this->misc->getDatabaseAccessor();
114
115
        $this->printTrail('schema');
0 ignored issues
show
Documentation introduced by
'schema' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
116
        $this->printTabs('schema', 'domains');
117
        $this->printMsg($msg);
118
119
        $domains = $data->getDomains();
120
121
        $columns = [
122
            'domain'  => [
123
                'title' => $this->lang['strdomain'],
124
                'field' => Decorator::field('domname'),
125
                'url'   => "domains?action=properties&amp;{$this->misc->href}&amp;",
126
                'vars'  => ['domain' => 'domname'],
127
            ],
128
            'type'    => [
129
                'title' => $this->lang['strtype'],
130
                'field' => Decorator::field('domtype'),
131
            ],
132
            'notnull' => [
133
                'title'  => $this->lang['strnotnull'],
134
                'field'  => Decorator::field('domnotnull'),
135
                'type'   => 'bool',
136
                'params' => ['true' => 'NOT NULL', 'false' => ''],
137
            ],
138
            'default' => [
139
                'title' => $this->lang['strdefault'],
140
                'field' => Decorator::field('domdef'),
141
            ],
142
            'owner'   => [
143
                'title' => $this->lang['strowner'],
144
                'field' => Decorator::field('domowner'),
145
            ],
146
            'actions' => [
147
                'title' => $this->lang['stractions'],
148
            ],
149
            'comment' => [
150
                'title' => $this->lang['strcomment'],
151
                'field' => Decorator::field('domcomment'),
152
            ],
153
        ];
154
155
        $actions = [
156
            'alter' => [
157
                'content' => $this->lang['stralter'],
158
                'attr'    => [
159
                    'href' => [
160
                        'url'     => 'domains',
161
                        'urlvars' => [
162
                            'action' => 'alter',
163
                            'domain' => Decorator::field('domname'),
164
                        ],
165
                    ],
166
                ],
167
            ],
168
            'drop'  => [
169
                'content' => $this->lang['strdrop'],
170
                'attr'    => [
171
                    'href' => [
172
                        'url'     => 'domains',
173
                        'urlvars' => [
174
                            'action' => 'confirm_drop',
175
                            'domain' => Decorator::field('domname'),
176
                        ],
177
                    ],
178
                ],
179
            ],
180
        ];
181
182
        if (!$data->hasAlterDomains()) {
183
            unset($actions['alter']);
184
        }
185
186
        echo $this->printTable($domains, $columns, $actions, 'domains-domains', $this->lang['strnodomains']);
187
188
        $navlinks = [
189
            'create' => [
190
                'attr'    => [
191
                    'href' => [
192
                        'url'     => 'domains',
193
                        'urlvars' => [
194
                            'action'   => 'create',
195
                            'server'   => $_REQUEST['server'],
196
                            'database' => $_REQUEST['database'],
197
                            'schema'   => $_REQUEST['schema'],
198
                        ],
199
                    ],
200
                ],
201
                'content' => $this->lang['strcreatedomain'],
202
            ],
203
        ];
204
        $this->printNavLinks($navlinks, 'domains-domains', get_defined_vars());
205
    }
206
207
    /**
208
     * Generate XML for the browser tree.
209
     */
210 View Code Duplication
    public function doTree()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
211
    {
212
        $data = $this->misc->getDatabaseAccessor();
213
214
        $domains = $data->getDomains();
215
216
        $reqvars = $this->misc->getRequestVars('domain');
217
218
        $attrs = [
219
            'text'    => Decorator::field('domname'),
220
            'icon'    => 'Domain',
221
            'toolTip' => Decorator::field('domcomment'),
222
            'action'  => Decorator::actionurl(
223
                'domains',
224
                $reqvars,
225
                [
226
                    'action' => 'properties',
227
                    'domain' => Decorator::field('domname'),
228
                ]
229
            ),
230
        ];
231
232
        return $this->printTree($domains, $attrs, 'domains');
233
    }
234
235
    /**
236
     * Function to save after altering a domain.
237
     */
238
    public function doSaveAlter()
239
    {
240
        $data = $this->misc->getDatabaseAccessor();
241
242
        $status = $data->alterDomain(
243
            $_POST['domain'],
244
            $_POST['domdefault'],
245
            isset($_POST['domnotnull']),
246
            $_POST['domowner']
247
        );
248
        if (0 == $status) {
249
            $this->doProperties($this->lang['strdomainaltered']);
250
        } else {
251
            $this->doAlter($this->lang['strdomainalteredbad']);
252
        }
253
    }
254
255
    /**
256
     * Allow altering a domain.
257
     *
258
     * @param mixed $msg
259
     */
260
    public function doAlter($msg = '')
261
    {
262
        $data = $this->misc->getDatabaseAccessor();
263
264
        $this->printTrail('domain');
0 ignored issues
show
Documentation introduced by
'domain' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
265
        $this->printTitle($this->lang['stralter'], 'pg.domain.alter');
266
        $this->printMsg($msg);
267
268
        // Fetch domain info
269
        $domaindata = $data->getDomain($_REQUEST['domain']);
270
        // Fetch all users
271
        $users = $data->getUsers();
272
273
        if ($domaindata->recordCount() > 0) {
274
            if (!isset($_POST['domname'])) {
275
                $_POST['domtype']                 = $domaindata->fields['domtype'];
276
                $_POST['domdefault']              = $domaindata->fields['domdef'];
277
                $domaindata->fields['domnotnull'] = $data->phpBool($domaindata->fields['domnotnull']);
278
                if ($domaindata->fields['domnotnull']) {
279
                    $_POST['domnotnull'] = 'on';
280
                }
281
282
                $_POST['domowner'] = $domaindata->fields['domowner'];
283
            }
284
285
            // Display domain info
286
            echo '<form action="'.\SUBFOLDER.'/src/views/domains" method="post">'.PHP_EOL;
287
            echo '<table>'.PHP_EOL;
288
            echo "<tr><th class=\"data left required\" style=\"width: 70px\">{$this->lang['strname']}</th>".PHP_EOL;
289
            echo '<td class="data1">', $this->misc->printVal($domaindata->fields['domname']), '</td></tr>'.PHP_EOL;
290
            echo "<tr><th class=\"data left required\">{$this->lang['strtype']}</th>".PHP_EOL;
291
            echo '<td class="data1">', $this->misc->printVal($domaindata->fields['domtype']), '</td></tr>'.PHP_EOL;
292
            echo "<tr><th class=\"data left\"><label for=\"domnotnull\">{$this->lang['strnotnull']}</label></th>".PHP_EOL;
293
            echo '<td class="data1"><input type="checkbox" id="domnotnull" name="domnotnull"', (isset($_POST['domnotnull']) ? ' checked="checked"' : ''), ' /></td></tr>'.PHP_EOL;
294
            echo "<tr><th class=\"data left\">{$this->lang['strdefault']}</th>".PHP_EOL;
295
            echo '<td class="data1"><input name="domdefault" size="32" value="',
296
            htmlspecialchars($_POST['domdefault']), '" /></td></tr>'.PHP_EOL;
297
            echo "<tr><th class=\"data left required\">{$this->lang['strowner']}</th>".PHP_EOL;
298
            echo '<td class="data1"><select name="domowner">';
299
            while (!$users->EOF) {
300
                $uname = $users->fields['usename'];
301
                echo '<option value="', htmlspecialchars($uname), '"',
302
                ($uname == $_POST['domowner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), '</option>'.PHP_EOL;
303
                $users->moveNext();
304
            }
305
            echo '</select></td></tr>'.PHP_EOL;
306
            echo '</table>'.PHP_EOL;
307
            echo '<p><input type="hidden" name="action" value="save_alter" />'.PHP_EOL;
308
            echo '<input type="hidden" name="domain" value="', htmlspecialchars($_REQUEST['domain']), '" />'.PHP_EOL;
309
            echo $this->misc->form;
310
            echo "<input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />".PHP_EOL;
311
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL;
312
            echo '</form>'.PHP_EOL;
313
        } else {
314
            echo "<p>{$this->lang['strnodata']}</p>".PHP_EOL;
315
        }
316
    }
317
318
    /**
319
     * Confirm and then actually add a CHECK constraint.
320
     *
321
     * @param mixed $confirm
322
     * @param mixed $msg
323
     */
324
    public function addCheck($confirm, $msg = '')
325
    {
326
        $data = $this->misc->getDatabaseAccessor();
327
328
        $this->coalesceArr($_POST, 'name', '');
329
330
        $this->coalesceArr($_POST, 'definition', '');
331
332
        if ($confirm) {
333
            $this->printTrail('domain');
0 ignored issues
show
Documentation introduced by
'domain' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
334
            $this->printTitle($this->lang['straddcheck'], 'pg.constraint.check');
335
            $this->printMsg($msg);
336
337
            echo '<form action="'.\SUBFOLDER.'/src/views/domains" method="post">'.PHP_EOL;
338
            echo '<table>'.PHP_EOL;
339
            echo "<tr><th class=\"data\">{$this->lang['strname']}</th>".PHP_EOL;
340
            echo "<th class=\"data required\">{$this->lang['strdefinition']}</th></tr>".PHP_EOL;
341
342
            echo "<tr><td class=\"data1\"><input name=\"name\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
343
            htmlspecialchars($_POST['name']), '" /></td>'.PHP_EOL;
344
345
            echo '<td class="data1">(<input name="definition" size="32" value="',
346
            htmlspecialchars($_POST['definition']), '" />)</td></tr>'.PHP_EOL;
347
            echo '</table>'.PHP_EOL;
348
349
            echo '<p><input type="hidden" name="action" value="save_add_check" />'.PHP_EOL;
350
            echo '<input type="hidden" name="domain" value="', htmlspecialchars($_REQUEST['domain']), '" />'.PHP_EOL;
351
            echo $this->misc->form;
352
            echo "<input type=\"submit\" name=\"add\" value=\"{$this->lang['stradd']}\" />".PHP_EOL;
353
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL;
354
            echo '</form>'.PHP_EOL;
355 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
356
            if ('' == trim($_POST['definition'])) {
357
                $this->addCheck(true, $this->lang['strcheckneedsdefinition']);
358
            } else {
359
                $status = $data->addDomainCheckConstraint(
360
                    $_POST['domain'],
361
                    $_POST['definition'],
362
                    $_POST['name']
363
                );
364
                if (0 == $status) {
365
                    $this->doProperties($this->lang['strcheckadded']);
366
                } else {
367
                    $this->addCheck(true, $this->lang['strcheckaddedbad']);
368
                }
369
            }
370
        }
371
    }
372
373
    /**
374
     * Show confirmation of drop constraint and perform actual drop.
375
     *
376
     * @param mixed $confirm
377
     * @param mixed $msg
378
     */
379 View Code Duplication
    public function doDropConstraint($confirm, $msg = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
380
    {
381
        $data = $this->misc->getDatabaseAccessor();
382
383
        if ($confirm) {
384
            $this->printTrail('domain');
0 ignored issues
show
Documentation introduced by
'domain' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
385
            $this->printTitle($this->lang['strdrop'], 'pg.constraint.drop');
386
            $this->printMsg($msg);
387
388
            echo '<p>', sprintf(
389
                $this->lang['strconfdropconstraint'],
390
                $this->misc->printVal($_REQUEST['constraint']),
391
                $this->misc->printVal($_REQUEST['domain'])
392
            ), '</p>'.PHP_EOL;
393
            echo '<form action="'.\SUBFOLDER.'/src/views/domains" method="post">'.PHP_EOL;
394
            echo '<input type="hidden" name="action" value="drop_con" />'.PHP_EOL;
395
            echo '<input type="hidden" name="domain" value="', htmlspecialchars($_REQUEST['domain']), '" />'.PHP_EOL;
396
            echo '<input type="hidden" name="constraint" value="', htmlspecialchars($_REQUEST['constraint']), '" />'.PHP_EOL;
397
            echo $this->misc->form;
398
            echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$this->lang['strcascade']}</label></p>".PHP_EOL;
399
            echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />".PHP_EOL;
400
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />".PHP_EOL;
401
            echo '</form>'.PHP_EOL;
402
        } else {
403
            $status = $data->dropDomainConstraint($_POST['domain'], $_POST['constraint'], isset($_POST['cascade']));
404
            if (0 == $status) {
405
                $this->doProperties($this->lang['strconstraintdropped']);
406
            } else {
407
                $this->doDropConstraint(true, $this->lang['strconstraintdroppedbad']);
408
            }
409
        }
410
    }
411
412
    /**
413
     * Show properties for a domain.  Allow manipulating constraints as well.
414
     *
415
     * @param mixed $msg
416
     */
417
    public function doProperties($msg = '')
418
    {
419
        $data = $this->misc->getDatabaseAccessor();
420
421
        $this->printTrail('domain');
0 ignored issues
show
Documentation introduced by
'domain' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
422
        $this->printTitle($this->lang['strproperties'], 'pg.domain');
423
        $this->printMsg($msg);
424
425
        $domaindata = $data->getDomain($_REQUEST['domain']);
426
427
        if ($domaindata->recordCount() > 0) {
428
            // Show comment if any
429
            if (null !== $domaindata->fields['domcomment']) {
430
                echo '<p class="comment">', $this->misc->printVal($domaindata->fields['domcomment']), '</p>'.PHP_EOL;
431
            }
432
433
            // Display domain info
434
            $domaindata->fields['domnotnull'] = $data->phpBool($domaindata->fields['domnotnull']);
435
            echo '<table>'.PHP_EOL;
436
            echo "<tr><th class=\"data left\" style=\"width: 70px\">{$this->lang['strname']}</th>".PHP_EOL;
437
            echo '<td class="data1">', $this->misc->printVal($domaindata->fields['domname']), '</td></tr>'.PHP_EOL;
438
            echo "<tr><th class=\"data left\">{$this->lang['strtype']}</th>".PHP_EOL;
439
            echo '<td class="data1">', $this->misc->printVal($domaindata->fields['domtype']), '</td></tr>'.PHP_EOL;
440
            echo "<tr><th class=\"data left\">{$this->lang['strnotnull']}</th>".PHP_EOL;
441
            echo '<td class="data1">', ($domaindata->fields['domnotnull'] ? 'NOT NULL' : ''), '</td></tr>'.PHP_EOL;
442
            echo "<tr><th class=\"data left\">{$this->lang['strdefault']}</th>".PHP_EOL;
443
            echo '<td class="data1">', $this->misc->printVal($domaindata->fields['domdef']), '</td></tr>'.PHP_EOL;
444
            echo "<tr><th class=\"data left\">{$this->lang['strowner']}</th>".PHP_EOL;
445
            echo '<td class="data1">', $this->misc->printVal($domaindata->fields['domowner']), '</td></tr>'.PHP_EOL;
446
            echo '</table>'.PHP_EOL;
447
448
            // Display domain constraints
449
            echo "<h3>{$this->lang['strconstraints']}</h3>".PHP_EOL;
450
            if ($data->hasDomainConstraints()) {
451
                $domaincons = $data->getDomainConstraints($_REQUEST['domain']);
452
453
                $columns = [
454
                    'name'       => [
455
                        'title' => $this->lang['strname'],
456
                        'field' => Decorator::field('conname'),
457
                    ],
458
                    'definition' => [
459
                        'title' => $this->lang['strdefinition'],
460
                        'field' => Decorator::field('consrc'),
461
                    ],
462
                    'actions'    => [
463
                        'title' => $this->lang['stractions'],
464
                    ],
465
                ];
466
467
                $actions = [
468
                    'drop' => [
469
                        'content' => $this->lang['strdrop'],
470
                        'attr'    => [
471
                            'href' => [
472
                                'url'     => 'domains',
473
                                'urlvars' => [
474
                                    'action'     => 'confirm_drop_con',
475
                                    'domain'     => $_REQUEST['domain'],
476
                                    'constraint' => Decorator::field('conname'),
477
                                    'type'       => Decorator::field('contype'),
478
                                ],
479
                            ],
480
                        ],
481
                    ],
482
                ];
483
484
                echo $this->printTable($domaincons, $columns, $actions, 'domains-properties', $this->lang['strnodata']);
485
            }
486
        } else {
487
            echo "<p>{$this->lang['strnodata']}</p>".PHP_EOL;
488
        }
489
490
        $navlinks = [
491
            'drop' => [
492
                'attr'    => [
493
                    'href' => [
494
                        'url'     => 'domains',
495
                        'urlvars' => [
496
                            'action'   => 'confirm_drop',
497
                            'server'   => $_REQUEST['server'],
498
                            'database' => $_REQUEST['database'],
499
                            'schema'   => $_REQUEST['schema'],
500
                            'domain'   => $_REQUEST['domain'],
501
                        ],
502
                    ],
503
                ],
504
                'content' => $this->lang['strdrop'],
505
            ],
506
        ];
507
        if ($data->hasAlterDomains()) {
508
            $navlinks['addcheck'] = [
509
                'attr'    => [
510
                    'href' => [
511
                        'url'     => 'domains',
512
                        'urlvars' => [
513
                            'action'   => 'add_check',
514
                            'server'   => $_REQUEST['server'],
515
                            'database' => $_REQUEST['database'],
516
                            'schema'   => $_REQUEST['schema'],
517
                            'domain'   => $_REQUEST['domain'],
518
                        ],
519
                    ],
520
                ],
521
                'content' => $this->lang['straddcheck'],
522
            ];
523
            $navlinks['alter'] = [
524
                'attr'    => [
525
                    'href' => [
526
                        'url'     => 'domains',
527
                        'urlvars' => [
528
                            'action'   => 'alter',
529
                            'server'   => $_REQUEST['server'],
530
                            'database' => $_REQUEST['database'],
531
                            'schema'   => $_REQUEST['schema'],
532
                            'domain'   => $_REQUEST['domain'],
533
                        ],
534
                    ],
535
                ],
536
                'content' => $this->lang['stralter'],
537
            ];
538
        }
539
540
        $this->printNavLinks($navlinks, 'domains-properties', get_defined_vars());
541
    }
542
543
    /**
544
     * Show confirmation of drop and perform actual drop.
545
     *
546
     * @param mixed $confirm
547
     */
548 View Code Duplication
    public function doDrop($confirm)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
549
    {
550
        $data = $this->misc->getDatabaseAccessor();
551
552
        if ($confirm) {
553
            $this->printTrail('domain');
0 ignored issues
show
Documentation introduced by
'domain' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
554
            $this->printTitle($this->lang['strdrop'], 'pg.domain.drop');
555
556
            echo '<p>', sprintf($this->lang['strconfdropdomain'], $this->misc->printVal($_REQUEST['domain'])), '</p>'.PHP_EOL;
557
            echo '<form action="'.\SUBFOLDER.'/src/views/domains" method="post">'.PHP_EOL;
558
            echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /><label for=\"cascade\">{$this->lang['strcascade']}</label></p>".PHP_EOL;
559
            echo '<p><input type="hidden" name="action" value="drop" />'.PHP_EOL;
560
            echo '<input type="hidden" name="domain" value="', htmlspecialchars($_REQUEST['domain']), '" />'.PHP_EOL;
561
            echo $this->misc->form;
562
            echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />".PHP_EOL;
563
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL;
564
            echo '</form>'.PHP_EOL;
565
        } else {
566
            $status = $data->dropDomain($_POST['domain'], isset($_POST['cascade']));
567
            if (0 == $status) {
568
                $this->doDefault($this->lang['strdomaindropped']);
569
            } else {
570
                $this->doDefault($this->lang['strdomaindroppedbad']);
571
            }
572
        }
573
    }
574
575
    /**
576
     * Displays a screen where they can enter a new domain.
577
     *
578
     * @param mixed $msg
579
     */
580
    public function doCreate($msg = '')
581
    {
582
        $data = $this->misc->getDatabaseAccessor();
583
584
        $this->coalesceArr($_POST, 'domname', '');
585
586
        $this->coalesceArr($_POST, 'domtype', '');
587
588
        $this->coalesceArr($_POST, 'domlength', '');
589
590
        $this->coalesceArr($_POST, 'domarray', '');
591
592
        $this->coalesceArr($_POST, 'domdefault', '');
593
594
        $this->coalesceArr($_POST, 'domcheck', '');
595
596
        $types = $data->getTypes(true);
597
598
        $this->printTrail('schema');
0 ignored issues
show
Documentation introduced by
'schema' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
599
        $this->printTitle($this->lang['strcreatedomain'], 'pg.domain.create');
600
        $this->printMsg($msg);
601
602
        echo '<form action="'.\SUBFOLDER.'/src/views/domains" method="post">'.PHP_EOL;
603
        echo '<table>'.PHP_EOL;
604
        echo "<tr><th class=\"data left required\" style=\"width: 70px\">{$this->lang['strname']}</th>".PHP_EOL;
605
        echo "<td class=\"data1\"><input name=\"domname\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
606
        htmlspecialchars($_POST['domname']), '" /></td></tr>'.PHP_EOL;
607
        echo "<tr><th class=\"data left required\">{$this->lang['strtype']}</th>".PHP_EOL;
608
        echo '<td class="data1">'.PHP_EOL;
609
        // Output return type list
610
        echo '<select name="domtype">'.PHP_EOL;
611
        while (!$types->EOF) {
612
            echo '<option value="', htmlspecialchars($types->fields['typname']), '"',
613
            ($types->fields['typname'] == $_POST['domtype']) ? ' selected="selected"' : '', '>',
614
            $this->misc->printVal($types->fields['typname']), '</option>'.PHP_EOL;
615
            $types->moveNext();
616
        }
617
        echo '</select>'.PHP_EOL;
618
619
        // Type length
620
        echo '<input type="text" size="4" name="domlength" value="', htmlspecialchars($_POST['domlength']), '" />';
621
622
        // Output array type selector
623
        echo '<select name="domarray">'.PHP_EOL;
624
        echo '<option value=""', ('' == $_POST['domarray']) ? ' selected="selected"' : '', '></option>'.PHP_EOL;
625
        echo '<option value="[]"', ('[]' == $_POST['domarray']) ? ' selected="selected"' : '', '>[ ]</option>'.PHP_EOL;
626
        echo '</select></td></tr>'.PHP_EOL;
627
628
        echo "<tr><th class=\"data left\"><label for=\"domnotnull\">{$this->lang['strnotnull']}</label></th>".PHP_EOL;
629
        echo '<td class="data1"><input type="checkbox" id="domnotnull" name="domnotnull"',
630
        (isset($_POST['domnotnull']) ? ' checked="checked"' : ''), ' /></td></tr>'.PHP_EOL;
631
        echo "<tr><th class=\"data left\">{$this->lang['strdefault']}</th>".PHP_EOL;
632
        echo '<td class="data1"><input name="domdefault" size="32" value="',
633
        htmlspecialchars($_POST['domdefault']), '" /></td></tr>'.PHP_EOL;
634
        if ($data->hasDomainConstraints()) {
635
            echo "<tr><th class=\"data left\">{$this->lang['strconstraints']}</th>".PHP_EOL;
636
            echo '<td class="data1">CHECK (<input name="domcheck" size="32" value="',
637
            htmlspecialchars($_POST['domcheck']), '" />)</td></tr>'.PHP_EOL;
638
        }
639
        echo '</table>'.PHP_EOL;
640
        echo '<p><input type="hidden" name="action" value="save_create" />'.PHP_EOL;
641
        echo $this->misc->form;
642
        echo "<input type=\"submit\" value=\"{$this->lang['strcreate']}\" />".PHP_EOL;
643
        echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL;
644
        echo '</form>'.PHP_EOL;
645
    }
646
647
    /**
648
     * Actually creates the new domain in the database.
649
     */
650
    public function doSaveCreate()
651
    {
652
        $data = $this->misc->getDatabaseAccessor();
653
654
        $this->coalesceArr($_POST, 'domcheck', '');
655
656
        // Check that they've given a name and a definition
657
        if ('' == $_POST['domname']) {
658
            $this->doCreate($this->lang['strdomainneedsname']);
659
        } else {
660
            $status = $data->createDomain(
661
                $_POST['domname'],
662
                $_POST['domtype'],
663
                $_POST['domlength'],
664
                '' != $_POST['domarray'],
665
                isset($_POST['domnotnull']),
666
                $_POST['domdefault'],
667
                $_POST['domcheck']
668
            );
669
            if (0 == $status) {
670
                $this->doDefault($this->lang['strdomaincreated']);
671
            } else {
672
                $this->doCreate($this->lang['strdomaincreatedbad']);
673
            }
674
        }
675
    }
676
}
677