Total Complexity | 40 |
Total Lines | 286 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Complex classes like ContainerUtils 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 ContainerUtils, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class ContainerUtils |
||
20 | { |
||
21 | use \PHPPgAdmin\Traits\HelperTrait; |
||
22 | |||
23 | protected $container; |
||
24 | /** @var Connector */ |
||
25 | protected static $instance; |
||
26 | |||
27 | /** |
||
28 | * Constructor of the ContainerUtils class. |
||
29 | * |
||
30 | * @param \Slim\Container $container The app container |
||
31 | */ |
||
32 | public function __construct() |
||
83 | } |
||
84 | |||
85 | public static function createContainer($conf) |
||
124 | } |
||
125 | |||
126 | public function maybeRenderIframes($response, $subject, $query_string) |
||
127 | { |
||
128 | $c = $this->container; |
||
129 | $in_test = $c->view->offsetGet('in_test'); |
||
130 | |||
131 | if ($in_test === '1') { |
||
132 | $className = '\PHPPgAdmin\Controller\\'.ucfirst($subject).'Controller'; |
||
133 | $controller = new $className($c); |
||
134 | |||
135 | return $controller->render(); |
||
136 | } |
||
137 | |||
138 | $viewVars = [ |
||
139 | 'url' => '/src/views/'.$subject.($query_string ? '?'.$query_string : ''), |
||
140 | 'headertemplate' => 'header.twig', |
||
141 | ]; |
||
142 | |||
143 | return $c->view->render($response, 'iframe_view.twig', $viewVars); |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * Gets the theme from |
||
148 | * 1. The $_REQUEST global (when it's chosen from start screen) |
||
149 | * 2. Server specific config theme |
||
150 | * 3.- $_SESSION global (subsequent requests after 1.) |
||
151 | * 4.- $_COOKIE global (mostly fallback for $_SESSION after 1.- and 3.-) |
||
152 | * 5.- theme as set in config |
||
153 | * 6.- 'default' theme. |
||
154 | * |
||
155 | * @param <type> $conf The conf |
||
156 | * @param null|mixed $_server_info |
||
157 | * |
||
158 | * @return string the theme |
||
159 | */ |
||
160 | public function getTheme(array $conf, $_server_info = null) |
||
161 | { |
||
162 | $_theme = null; |
||
163 | // List of themes |
||
164 | $themefolders = $this->getThemeFolders(); |
||
165 | // Check if theme is in $_REQUEST, $_SESSION or $_COOKIE |
||
166 | // 1.- First priority: $_REQUEST, this happens when you use the selector |
||
167 | if (array_key_exists('theme', $_REQUEST) && |
||
168 | array_key_exists($_REQUEST['theme'], $themefolders)) { |
||
169 | $_theme = $_REQUEST['theme']; |
||
170 | } elseif ( // otherwise, see if there's a theme associated with this particular server |
||
171 | !is_null($_server_info) && |
||
172 | array_key_exists('theme', $_server_info) && |
||
173 | is_string($_server_info['theme']) && |
||
174 | array_key_exists($_COOKIE['ppaTheme'], $themefolders)) { |
||
175 | $_theme = $_server_info['theme']; |
||
176 | } elseif (array_key_exists('ppaTheme', $_SESSION) && |
||
177 | array_key_exists($_SESSION['ppaTheme'], $themefolders)) { |
||
178 | // otherwise check $_SESSION |
||
179 | $_theme = $_SESSION['ppaTheme']; |
||
180 | } elseif (array_key_exists('ppaTheme', $_SESSION) && |
||
181 | array_key_exists($_COOKIE['ppaTheme'], $themefolders)) { |
||
182 | // oterwise check $_COOKIE |
||
183 | $_theme = $_COOKIE['ppaTheme']; |
||
184 | } elseif ( // see if there's a valid theme set in config file |
||
185 | array_key_exists('theme', $conf) && |
||
186 | is_string($conf['theme']) && |
||
187 | array_key_exists($conf['theme'], $themefolders)) { |
||
188 | $_theme = $conf['theme']; |
||
189 | } else { |
||
190 | // okay then, use default theme |
||
191 | $_theme = 'default'; |
||
192 | } |
||
193 | |||
194 | return $_theme; |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Traverse THEME_PATH, consider as theme folders those which |
||
199 | * contain a `global.css` stylesheet. |
||
200 | * |
||
201 | * @return array the theme folders |
||
202 | */ |
||
203 | private function getThemeFolders() |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * Determines the redirection url according to query string. |
||
235 | * |
||
236 | * @return string the redirect url |
||
237 | */ |
||
238 | public function getRedirectUrl() |
||
239 | { |
||
240 | $query_string = $this->container->requestobj->getUri()->getQuery(); |
||
241 | |||
242 | // if server_id isn't set, then you will be redirected to intro |
||
243 | if ($this->container->requestobj->getQueryParam('server') === null) { |
||
244 | $destinationurl = \SUBFOLDER.'/src/views/intro'; |
||
245 | } else { |
||
246 | // otherwise, you'll be redirected to the login page for that server; |
||
247 | $destinationurl = \SUBFOLDER.'/src/views/login'.($query_string ? '?'.$query_string : ''); |
||
248 | } |
||
249 | |||
250 | return $destinationurl; |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * Gets the destination with the last active tab selected for that controller |
||
255 | * Usually used after going through a redirect route. |
||
256 | * |
||
257 | * @param string $subject The subject, usually a view name like 'server' or 'table' |
||
258 | * |
||
259 | * @return string The destination url with last tab set in the query string |
||
260 | */ |
||
261 | public function getDestinationWithLastTab($subject) |
||
262 | { |
||
263 | $_server_info = $this->container->misc->getServerInfo(); |
||
264 | $this->addFlash($subject, 'getDestinationWithLastTab'); |
||
265 | //$this->prtrace('$_server_info', $_server_info); |
||
266 | // If username isn't set in server_info, you should login |
||
267 | if (!isset($_server_info['username'])) { |
||
268 | $destinationurl = $this->getRedirectUrl(); |
||
269 | } else { |
||
270 | $url = $this->container->misc->getLastTabURL($subject); |
||
271 | $this->addFlash($url, 'getLastTabURL for '.$subject); |
||
272 | // Load query vars into superglobal arrays |
||
273 | if (isset($url['urlvars'])) { |
||
274 | $urlvars = []; |
||
275 | foreach ($url['urlvars'] as $key => $urlvar) { |
||
276 | //$this->prtrace($key, $urlvar); |
||
277 | $urlvars[$key] = \PHPPgAdmin\Decorators\Decorator::get_sanitized_value($urlvar, $_REQUEST); |
||
278 | } |
||
279 | $_REQUEST = array_merge($_REQUEST, $urlvars); |
||
280 | $_GET = array_merge($_GET, $urlvars); |
||
281 | } |
||
282 | |||
283 | $actionurl = \PHPPgAdmin\Decorators\Decorator::actionurl($url['url'], $_GET); |
||
284 | $destinationurl = $actionurl->value($_GET); |
||
285 | } |
||
286 | $destinationurl = str_replace('views/?', "views/{$subject}?", $destinationurl); |
||
287 | // $this->prtrace('destinationurl for ' . $subject, $destinationurl); |
||
288 | return $destinationurl; |
||
289 | } |
||
290 | |||
291 | /** |
||
292 | * Adds an error to the errors array property of the container. |
||
293 | * |
||
294 | * @param string $errormsg The error msg |
||
295 | * |
||
296 | * @return \Slim\Container The app container |
||
297 | */ |
||
298 | public function addError($errormsg) |
||
305 | } |
||
306 | } |
||
307 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths