Conditions | 9 |
Paths | 60 |
Total Lines | 66 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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 |
||
36 | function b_wgfilemanager_dirfavlist_show($options) |
||
37 | { |
||
38 | global $xoopsModule; |
||
39 | |||
40 | $helper = Helper::getInstance(); |
||
41 | $directoryHandler = $helper->getHandler('Directory'); |
||
42 | $fileHandler = $helper->getHandler('File'); |
||
43 | |||
44 | $typeBlock = $options[0]; |
||
45 | $lengthName = $options[1]; |
||
46 | if (isset($options[2])) { |
||
47 | $typeList = (int)$options[2]; |
||
48 | } |
||
49 | $GLOBALS['xoopsTpl']->assign('wgfilemanager_typeblock', $typeBlock); |
||
50 | $GLOBALS['xoTheme']->addStylesheet(\WGFILEMANAGER_URL . '/assets/css/default.css'); |
||
51 | |||
52 | $block = []; |
||
53 | |||
54 | $dirId = Request::getInt('dir_id', 0); |
||
55 | if ((!empty($xoopsModule))) { |
||
56 | $moduleDirName = \basename(\dirname(__DIR__)); |
||
57 | /* echo "<br>xoopsModule:".$moduleDirName. " " . $xoopsModule->getByDirname($moduleDirName)->getVar('mid'); |
||
58 | echo "<br>xoopsModule:".$xoopsModule->getVar('mid');*/ |
||
59 | if ($xoopsModule->getByDirname($moduleDirName)->getVar('mid') === $xoopsModule->getVar('mid')) { |
||
60 | $dirId = Request::getInt('dir_id', 1); |
||
61 | } |
||
62 | } |
||
63 | $collapseFav = false; |
||
64 | $collapseDir = false; |
||
65 | if ('collapsable' === (string)$options[0]) { |
||
66 | switch ($typeList) { |
||
67 | case 1: |
||
68 | $collapseFav = true; |
||
69 | $collapseDir = false; |
||
70 | break; |
||
71 | case 2: |
||
72 | $collapseFav = false; |
||
73 | $collapseDir = true; |
||
74 | break; |
||
75 | case 0: |
||
76 | default: |
||
77 | $collapseFav = true; |
||
78 | $collapseDir = true; |
||
79 | break; |
||
80 | } |
||
81 | } |
||
82 | $GLOBALS['xoopsTpl']->assign('collapseFav', $collapseFav); |
||
83 | $GLOBALS['xoopsTpl']->assign('collapseDir', $collapseDir); |
||
84 | |||
85 | //get directory list |
||
86 | $block['dir_list'] = $directoryHandler->getDirList(0, $dirId); |
||
87 | |||
88 | $block['fav_list'] = []; |
||
89 | if ((bool)$helper->getConfig('use_favorites')) { |
||
90 | //get fav list |
||
91 | $favList = []; |
||
92 | //get directory fav list |
||
93 | $favList['dirs'] = $directoryHandler->getFavDirList(); |
||
94 | //get directory fav list |
||
95 | $favList['files'] = $fileHandler->getFavFileList(); |
||
96 | $block['fav_list'] = $favList; |
||
97 | } |
||
98 | $GLOBALS['xoopsTpl']->assign('countFavlist', count($favList['dirs']) + count($favList['files'])); |
||
99 | $GLOBALS['xoopsTpl']->assign('wgfilemanager_url', \WGFILEMANAGER_URL); |
||
100 | $GLOBALS['xoopsTpl']->assign('wgfilemanager_icon_bi_url', \WGFILEMANAGER_ICONS_URL . '/bootstrap/'); |
||
101 | return $block; |
||
102 | |||
126 |
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: