| Total Complexity | 58 |
| Total Lines | 221 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like PathStuffController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PathStuffController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class PathStuffController |
||
| 28 | { |
||
| 29 | public $xoopsPath = array( |
||
| 30 | 'lib' => '', |
||
| 31 | 'data' => '', |
||
| 32 | ); |
||
| 33 | public $path_lookup = array( |
||
| 34 | 'data' => 'VAR_PATH', |
||
| 35 | 'lib' => 'PATH', |
||
| 36 | ); |
||
| 37 | |||
| 38 | public $validPath = array( |
||
| 39 | 'data' => 0, |
||
| 40 | 'lib' => 0, |
||
| 41 | ); |
||
| 42 | |||
| 43 | public $permErrors = array( |
||
| 44 | 'data' => null, |
||
| 45 | ); |
||
| 46 | |||
| 47 | public function __construct() |
||
| 48 | { |
||
| 49 | if (isset($_SESSION['settings']['VAR_PATH'])) { |
||
| 50 | foreach ($this->path_lookup as $req => $sess) { |
||
| 51 | $this->xoopsPath[$req] = $_SESSION['settings'][$sess]; |
||
| 52 | } |
||
| 53 | } else { |
||
| 54 | $path = XOOPS_ROOT_PATH; |
||
| 55 | if (defined("XOOPS_PATH")) { |
||
| 56 | $this->xoopsPath['lib'] = XOOPS_PATH; |
||
| 57 | } elseif (defined("XOOPS_TRUST_PATH")) { |
||
| 58 | $this->xoopsPath['lib'] = XOOPS_TRUST_PATH; |
||
| 59 | } else { |
||
| 60 | $this->xoopsPath['lib'] = dirname($path) . "/xoops_lib"; |
||
| 61 | if (!is_dir($this->xoopsPath['lib'] . "/")) { |
||
| 62 | $this->xoopsPath['lib'] = $path . "/xoops_lib"; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | if (defined("XOOPS_VAR_PATH")) { |
||
| 66 | $this->xoopsPath['data'] = XOOPS_VAR_PATH; |
||
| 67 | } else { |
||
| 68 | $this->xoopsPath['data'] = dirname($path) . "/xoops_data"; |
||
| 69 | if (!is_dir($this->xoopsPath['data'] . "/")) { |
||
| 70 | $this->xoopsPath['data'] = $path . "/xoops_data"; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | public function execute() |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | public function readRequest() |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | public function validate() |
||
| 109 | { |
||
| 110 | foreach (array_keys($this->xoopsPath) as $path) { |
||
| 111 | if ($this->checkPath($path)) { |
||
| 112 | $this->checkPermissions($path); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | $validPaths = (array_sum(array_values($this->validPath)) == count(array_keys($this->validPath))) ? 1 : 0; |
||
| 116 | $validPerms = true; |
||
| 117 | foreach ($this->permErrors as $key => $errs) { |
||
| 118 | if (empty($errs)) { |
||
| 119 | continue; |
||
| 120 | } |
||
| 121 | foreach ($errs as $path => $status) { |
||
| 122 | if (empty($status)) { |
||
| 123 | $validPerms = false; |
||
| 124 | break; |
||
| 125 | } |
||
| 126 | } |
||
| 127 | } |
||
| 128 | return ($validPaths && $validPerms); |
||
| 129 | } |
||
| 130 | |||
| 131 | public function checkPath($PATH = '') |
||
| 132 | { |
||
| 133 | $ret = 1; |
||
| 134 | if ($PATH == 'lib' || empty($PATH)) { |
||
| 135 | $path = 'lib'; |
||
| 136 | if (is_dir($this->xoopsPath[$path]) && is_readable($this->xoopsPath[$path])) { |
||
| 137 | $this->validPath[$path] = 1; |
||
| 138 | } |
||
| 139 | $ret *= $this->validPath[$path]; |
||
| 140 | } |
||
| 141 | if ($PATH == 'data' || empty($PATH)) { |
||
| 142 | $path = 'data'; |
||
| 143 | if (is_dir($this->xoopsPath[$path]) && is_readable($this->xoopsPath[$path])) { |
||
| 144 | $this->validPath[$path] = 1; |
||
| 145 | } |
||
| 146 | $ret *= $this->validPath[$path]; |
||
| 147 | } |
||
| 148 | return $ret; |
||
| 149 | } |
||
| 150 | |||
| 151 | public function setPermission($parent, $path, &$error) |
||
| 171 | } |
||
| 172 | |||
| 173 | public function checkPermissions($path = "data") |
||
| 200 | } |
||
| 201 | |||
| 202 | |||
| 203 | /** |
||
| 204 | * Write-enable the specified file/folder |
||
| 205 | * @param string $path |
||
| 206 | * @param string $group |
||
| 207 | * @param bool $recurse |
||
| 208 | * @return false on failure, method (u-ser,g-roup,w-orld) on success |
||
| 209 | */ |
||
| 210 | public function makeWritable($path, $group = false, $create = true) |
||
| 248 | } |
||
| 249 | } |
||
| 250 |