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