Conditions | 6 |
Paths | 9 |
Total Lines | 51 |
Code Lines | 43 |
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 declare(strict_types=1); |
||
45 | public static function getDirectoryStatus(?string $path, ?int $mode = null, ?string $redirectFile = null) |
||
46 | { |
||
47 | $mode ??= 0777; |
||
48 | $pathIcon16 = Admin::iconUrl('', '16'); |
||
49 | |||
50 | if (empty($path)) { |
||
51 | return false; |
||
52 | } |
||
53 | if (null === $redirectFile) { |
||
54 | $redirectFile = $_SERVER['SCRIPT_NAME']; |
||
55 | } |
||
56 | $moduleDirName = \basename(\dirname(__DIR__, 2)); |
||
57 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
||
58 | if (!@\is_dir($path)) { |
||
59 | $path_status = "<img src='$pathIcon16/0.png' >"; |
||
60 | $path_status .= "$path (" . \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTAVAILABLE') . ') '; |
||
61 | $path_status .= "<form action='" . $_SERVER['SCRIPT_NAME'] . "' method='post'>"; |
||
62 | $path_status .= "<input type='hidden' name='op' value='createdir'>"; |
||
63 | $path_status .= "<input type='hidden' name='path' value='$path'>"; |
||
64 | $path_status .= "<input type='hidden' name='redirect' value='$redirectFile'>"; |
||
65 | $path_status .= "<button class='submit' onClick='this.form.submit();'>" . \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_CREATETHEDIR') . '</button>'; |
||
66 | $path_status .= '</form>'; |
||
67 | } elseif (@\is_writable($path)) { |
||
68 | $path_status = "<img src='$pathIcon16/1.png' >"; |
||
69 | $path_status .= "$path (" . \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_AVAILABLE') . ') '; |
||
70 | $currentMode = \mb_substr(\decoct(\fileperms($path)), 2); |
||
71 | if ($currentMode != \decoct($mode)) { |
||
72 | $path_status = "<img src='$pathIcon16/0.png' >"; |
||
73 | $path_status .= $path . \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTWRITABLE'), \decoct($mode), $currentMode); |
||
74 | $path_status .= "<form action='" . $_SERVER['SCRIPT_NAME'] . "' method='post'>"; |
||
75 | $path_status .= "<input type='hidden' name='op' value='setdirperm'>"; |
||
76 | $path_status .= "<input type='hidden' name='mode' value='$mode'>"; |
||
77 | $path_status .= "<input type='hidden' name='path' value='$path'>"; |
||
78 | $path_status .= "<input type='hidden' name='redirect' value='$redirectFile'>"; |
||
79 | $path_status .= "<button class='submit' onClick='this.form.submit();'>" . \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_SETMPERM') . '</button>'; |
||
80 | $path_status .= '</form>'; |
||
81 | } |
||
82 | } else { |
||
83 | $currentMode = \mb_substr(\decoct(\fileperms($path)), 2); |
||
84 | $path_status = "<img src='$pathIcon16/0.png' >"; |
||
85 | $path_status .= $path . \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTWRITABLE'), \decoct($mode), $currentMode); |
||
86 | $path_status .= "<form action='" . $_SERVER['SCRIPT_NAME'] . "' method='post'>"; |
||
87 | $path_status .= "<input type='hidden' name='op' value='setdirperm'>"; |
||
88 | $path_status .= "<input type='hidden' name='mode' value='$mode'>"; |
||
89 | $path_status .= "<input type='hidden' name='path' value='$path'>"; |
||
90 | $path_status .= "<input type='hidden' name='redirect' value='$redirectFile'>"; |
||
91 | $path_status .= "<button class='submit' onClick='this.form.submit();'>" . \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_SETMPERM') . '</button>'; |
||
92 | $path_status .= '</form>'; |
||
93 | } |
||
94 | |||
95 | return $path_status; |
||
96 | } |
||
162 |