Conditions | 21 |
Paths | 3457 |
Total Lines | 230 |
Code Lines | 178 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 declare(strict_types=1); |
||
56 | $groups = Request::getArray('groups', [], 'POST'); |
||
57 | $options = Request::getArray('options', [], 'POST'); |
||
58 | $submitblock = Request::getString('submitblock', '', 'POST'); |
||
59 | $fct = Request::getString('fct', '', 'POST'); |
||
60 | $title = Request::getString('title', '', 'POST'); |
||
61 | $side = Request::getString('side', '0', 'POST'); |
||
62 | $weight = Request::getString('weight', '0', 'POST'); |
||
63 | $visible = Request::getString('visible', '0', 'POST'); |
||
64 | } |
||
65 | |||
66 | if ('list' === $op) { |
||
67 | // xoops_cp_header(); |
||
68 | $blocksadmin->listBlocks(); |
||
69 | require_once __DIR__ . '/admin_footer.php'; |
||
70 | exit(); |
||
71 | } |
||
72 | |||
73 | if (\in_array($op, ['edit', 'edit_ok', 'delete', 'delete_ok', 'clone', 'clone_ok'])) { |
||
74 | $bid = Request::getInt('bid', 0); |
||
75 | $ok = Request::getInt('ok', 0); |
||
76 | |||
77 | if ('clone' === $op) { |
||
78 | $blocksadmin->cloneBlock($bid); |
||
79 | } |
||
80 | |||
81 | if ('delete' === $op) { |
||
82 | if (1 === $ok) { |
||
83 | // if (!$GLOBALS['xoopsSecurity']->check()) { |
||
84 | // redirect_header($helper->url('admin/blocksadmin.php'), 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||
85 | // } |
||
86 | $blocksadmin->deleteBlock($bid); |
||
87 | } else { |
||
88 | // xoops_cp_header(); |
||
89 | xoops_confirm(['ok' => 1, 'op' => 'delete', 'bid' => $bid], 'blocksadmin.php', constant('CO_' . $moduleDirNameUpper . '_' . 'DELETE_BLOCK_CONFIRM'), constant('CO_' . $moduleDirNameUpper . '_' . 'CONFIRM'), true); |
||
90 | xoops_cp_footer(); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | if ('edit' === $op) { |
||
95 | $blocksadmin->editBlock($bid); |
||
96 | } |
||
97 | |||
98 | if ('edit_ok' === $op) { |
||
99 | $blocksadmin->updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups); |
||
100 | } |
||
101 | |||
102 | if ('clone_ok' === $op) { |
||
103 | $blocksadmin->isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | if ('order' === $op) { |
||
108 | $bid = Request::getArray('bid', []); |
||
109 | |||
110 | $title = Request::getArray('title', [], 'POST'); |
||
111 | $side = Request::getArray('side', [], 'POST'); |
||
112 | $weight = Request::getArray('weight', [], 'POST'); |
||
113 | $visible = Request::getArray('visible', [], 'POST'); |
||
114 | $bcachetime = Request::getArray('bcachetime', [], 'POST'); |
||
115 | $bmodule = Request::getArray('bmodule', [], 'POST');//mb |
||
116 | |||
117 | $oldtitle = Request::getArray('oldtitle', [], 'POST'); |
||
118 | $oldside = Request::getArray('oldside', [], 'POST'); |
||
119 | $oldweight = Request::getArray('oldweight', [], 'POST'); |
||
120 | $oldvisible = Request::getArray('oldvisible', [], 'POST'); |
||
121 | $oldgroups = Request::getArray('oldgroups', [], 'POST'); |
||
122 | $oldbcachetime = Request::getArray('oldcachetime', [], 'POST'); |
||
123 | $oldbmodule = Request::getArray('oldbmodule', [], 'POST');//mb |
||
124 | |||
125 | $blocksadmin->orderBlock( |
||
126 | $bid, |
||
127 | $oldtitle, |
||
128 | $oldside, |
||
129 | $oldweight, |
||
130 | $oldvisible, |
||
131 | $oldgroups, |
||
132 | $oldbcachetime, |
||
133 | $oldbmodule, |
||
134 | $title, |
||
135 | $weight, |
||
136 | $visible, |
||
137 | $side, |
||
138 | $bcachetime, |
||
139 | $groups, |
||
140 | $bmodule |
||
141 | ); |
||
142 | } |
||
143 | } else { |
||
144 | echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'); |
||
145 | } |
||
146 | |||
147 | require __DIR__ . '/admin_footer.php'; |
||
148 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: