Conditions | 27 |
Paths | > 20000 |
Total Lines | 173 |
Lines | 6 |
Ratio | 3.47 % |
Changes | 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 namespace EvolutionCMS\Legacy; |
||
257 | public function buildCache($modx) |
||
258 | { |
||
259 | $content = "<?php\n"; |
||
260 | |||
261 | // SETTINGS & DOCUMENT LISTINGS CACHE |
||
262 | |||
263 | // get settings |
||
264 | $rs = $modx->getDatabase()->select('*', $modx->getDatabase()->getFullTableName('system_settings')); |
||
265 | $config = array(); |
||
266 | $content .= '$c=&$this->config;'; |
||
267 | while (list($key, $value) = $modx->getDatabase()->getRow($rs, 'num')) { |
||
268 | $content .= '$c[\'' . $modx->getDatabase()->escape($key) . '\']="' . $this->escapeDoubleQuotes($value) . '";'; |
||
269 | $config[$key] = $value; |
||
270 | } |
||
271 | |||
272 | if ($config['enable_filter']) { |
||
273 | if (Models\SitePlugin::activePhx()->count()) { |
||
274 | $content .= '$this->config[\'enable_filter\']=\'0\';'; |
||
275 | } |
||
276 | } |
||
277 | |||
278 | if ($config['aliaslistingfolder'] == 1) { |
||
279 | $f['id'] = 'c.id'; |
||
280 | $f['alias'] = "IF( c.alias='', c.id, c.alias)"; |
||
281 | $f['parent'] = 'c.parent'; |
||
282 | $f['isfolder'] = 'c.isfolder'; |
||
283 | $f['alias_visible'] = 'c.alias_visible'; |
||
284 | $from = array(); |
||
285 | $from[] = $modx->getDatabase()->getFullTableName('site_content') . ' c'; |
||
286 | $from[] = 'LEFT JOIN ' . $modx->getDatabase()->getFullTableName('site_content') . ' p ON p.id=c.parent'; |
||
287 | $where = 'c.deleted=0 AND (c.isfolder=1 OR p.alias_visible=0)'; |
||
288 | $rs = $modx->getDatabase()->select($f, $from, $where, 'c.parent, c.menuindex'); |
||
289 | } else { |
||
290 | $rs = $modx->getDatabase()->select( |
||
291 | "id, IF(alias='', id, alias) AS alias, parent, isfolder, alias_visible", |
||
292 | $modx->getDatabase()->getFullTableName('site_content'), |
||
293 | 'deleted=0', |
||
294 | 'parent, menuindex' |
||
295 | ); |
||
296 | } |
||
297 | |||
298 | $use_alias_path = ($config['friendly_urls'] && $config['use_alias_path']) ? 1 : 0; |
||
299 | $tmpPath = ''; |
||
300 | $content .= '$this->aliasListing=array();'; |
||
301 | $content .= '$a=&$this->aliasListing;'; |
||
302 | $content .= '$d=&$this->documentListing;'; |
||
303 | $content .= '$m=&$this->documentMap;'; |
||
304 | while ($doc = $modx->getDatabase()->getRow($rs)) { |
||
305 | $docid = $doc['id']; |
||
306 | if ($use_alias_path) { |
||
307 | $tmpPath = $this->getParents($doc['parent']); |
||
308 | $alias = (strlen($tmpPath) > 0 ? "$tmpPath/" : '') . $doc['alias']; |
||
309 | $key = $alias; |
||
310 | } else { |
||
311 | $key = $doc['alias']; |
||
312 | } |
||
313 | |||
314 | $doc['path'] = $tmpPath; |
||
315 | $content .= '$a[' . $docid . ']=array(\'id\'=>' . $docid . ',\'alias\'=>\'' . $doc['alias'] . '\',\'path\'=>\'' . $doc['path'] . '\',\'parent\'=>' . $doc['parent'] . ',\'isfolder\'=>' . $doc['isfolder'] . ',\'alias_visible\'=>' . $doc['alias_visible'] . ');'; |
||
316 | $content .= '$d[\'' . $key . '\']=' . $docid . ';'; |
||
317 | $content .= '$m[]=array(' . $doc['parent'] . '=>' . $docid . ');'; |
||
318 | } |
||
319 | |||
320 | // get content types |
||
321 | $rs = $modx->getDatabase()->select( |
||
322 | 'id, contentType', |
||
323 | $modx->getDatabase()->getFullTableName('site_content'), |
||
324 | "contentType!='text/html'" |
||
325 | ); |
||
326 | $content .= '$c=&$this->contentTypes;'; |
||
327 | while ($doc = $modx->getDatabase()->getRow($rs)) { |
||
328 | $content .= '$c[\'' . $doc['id'] . '\']=\'' . $doc['contentType'] . '\';'; |
||
329 | } |
||
330 | |||
331 | // WRITE Chunks to cache file |
||
332 | $rs = $modx->getDatabase()->select('*', $modx->getDatabase()->getFullTableName('site_htmlsnippets')); |
||
333 | $content .= '$c=&$this->chunkCache;'; |
||
334 | while ($doc = $modx->getDatabase()->getRow($rs)) { |
||
335 | $content .= '$c[\'' . $modx->getDatabase()->escape($doc['name']) . '\']=\'' . ($doc['disabled'] ? '' : $this->escapeSingleQuotes($doc['snippet'])) . '\';'; |
||
336 | } |
||
337 | |||
338 | // WRITE snippets to cache file |
||
339 | $f = 'ss.*, sm.properties as sharedproperties'; |
||
340 | $from = $modx->getDatabase()->getFullTableName('site_snippets') . ' ss LEFT JOIN ' . |
||
341 | $modx->getDatabase()->getFullTableName('site_modules') . ' sm on sm.guid=ss.moduleguid'; |
||
342 | $rs = $modx->getDatabase()->select($f, $from); |
||
343 | $content .= '$s=&$this->snippetCache;'; |
||
344 | while ($row = $modx->getDatabase()->getRow($rs)) { |
||
345 | $key = $modx->getDatabase()->escape($row['name']); |
||
346 | if ($row['disabled']) { |
||
347 | $content .= '$s[\'' . $key . '\']=\'return false;\';'; |
||
348 | } else { |
||
349 | $value = trim($row['snippet']); |
||
350 | if ($modx->getConfig('minifyphp_incache')) { |
||
351 | $value = $this->php_strip_whitespace($value); |
||
352 | } |
||
353 | $content .= '$s[\'' . $key . '\']=\'' . $this->escapeSingleQuotes($value) . '\';'; |
||
354 | $properties = $modx->parseProperties($row['properties']); |
||
355 | $sharedproperties = $modx->parseProperties($row['sharedproperties']); |
||
356 | $properties = array_merge($sharedproperties, $properties); |
||
357 | View Code Duplication | if (0 < count($properties)) { |
|
358 | $content .= '$s[\'' . $key . 'Props\']=\'' . $this->escapeSingleQuotes(json_encode($properties)) . '\';'; |
||
359 | } |
||
360 | } |
||
361 | } |
||
362 | |||
363 | // WRITE plugins to cache file |
||
364 | $f = 'sp.*, sm.properties as sharedproperties'; |
||
365 | $from = []; |
||
366 | $from[] = $modx->getDatabase()->getFullTableName('site_plugins') . ' sp'; |
||
367 | $from[] = 'LEFT JOIN ' . $modx->getDatabase()->getFullTableName('site_modules') . ' sm on sm.guid=sp.moduleguid'; |
||
368 | $rs = $modx->getDatabase()->select($f, $from, 'sp.disabled=0'); |
||
369 | $content .= '$p=&$this->pluginCache;'; |
||
370 | while ($row = $modx->getDatabase()->getRow($rs)) { |
||
371 | $key = $modx->getDatabase()->escape($row['name']); |
||
372 | $value = trim($row['plugincode']); |
||
373 | if ($modx->getConfig('minifyphp_incache')) { |
||
374 | $value = $this->php_strip_whitespace($value); |
||
375 | } |
||
376 | $content .= '$p[\'' . $key . '\']=\'' . $this->escapeSingleQuotes($value) . '\';'; |
||
377 | if ($row['properties'] != '' || $row['sharedproperties'] != '') { |
||
378 | $properties = $modx->parseProperties($row['properties']); |
||
379 | $sharedproperties = $modx->parseProperties($row['sharedproperties']); |
||
380 | $properties = array_merge($sharedproperties, $properties); |
||
381 | View Code Duplication | if (0 < count($properties)) { |
|
382 | $content .= '$p[\'' . $key . 'Props\']=\'' . $this->escapeSingleQuotes(json_encode($properties)) . '\';'; |
||
383 | } |
||
384 | } |
||
385 | } |
||
386 | |||
387 | // WRITE system event triggers |
||
388 | $f = 'sysevt.name as evtname, event.pluginid, plugin.name as pname'; |
||
389 | $from = array(); |
||
390 | $from[] = $modx->getDatabase()->getFullTableName('system_eventnames') . ' sysevt'; |
||
391 | $from[] = 'INNER JOIN ' . $modx->getDatabase()->getFullTableName('site_plugin_events') . ' event ON event.evtid=sysevt.id'; |
||
392 | $from[] = 'INNER JOIN ' . $modx->getDatabase()->getFullTableName('site_plugins') . ' plugin ON plugin.id=event.pluginid'; |
||
393 | $rs = $modx->getDatabase()->select($f, $from, 'plugin.disabled=0', 'sysevt.name, event.priority'); |
||
394 | $content .= '$e=&$this->pluginEvent;'; |
||
395 | $events = array(); |
||
396 | while ($row = $modx->getDatabase()->getRow($rs)) { |
||
397 | $evtname = $row['evtname']; |
||
398 | if (!isset($events[$evtname])) { |
||
399 | $events[$evtname] = array(); |
||
400 | } |
||
401 | $events[$evtname][] = $row['pname']; |
||
402 | } |
||
403 | foreach ($events as $evtname => $pluginnames) { |
||
404 | $events[$evtname] = $pluginnames; |
||
405 | $content .= '$e[\'' . $evtname . '\']=array(\'' . implode('\',\'', |
||
406 | $this->escapeSingleQuotes($pluginnames)) . '\');'; |
||
407 | } |
||
408 | |||
409 | $content .= "\n"; |
||
410 | |||
411 | // close and write the file |
||
412 | $filename = $modx->getSiteCacheFilePath(); |
||
413 | |||
414 | // invoke OnBeforeCacheUpdate event |
||
415 | $modx->invokeEvent('OnBeforeCacheUpdate'); |
||
416 | |||
417 | if (@file_put_contents($filename, $content) === false) { |
||
418 | exit("Cannot write main Evolution CMS cache file! Make sure the assets/cache directory is writable!"); |
||
419 | } |
||
420 | |||
421 | if (!is_file($this->cachePath . '/.htaccess')) { |
||
422 | file_put_contents($this->cachePath . '/.htaccess', "order deny,allow\ndeny from all\n"); |
||
423 | } |
||
424 | |||
425 | // invoke OnCacheUpdate event |
||
426 | $modx->invokeEvent('OnCacheUpdate'); |
||
427 | |||
428 | return true; |
||
429 | } |
||
430 | |||
506 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.