htdocs/install/include/functions.php
<?php/** * Functions needed by the ImpressCMS installer * * @copyright http://www.impresscms.org/ The ImpressCMS Project * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL) * @package installer * @author marcan <marcan@impresscms.org> * @author modified by UnderDog <underdog@impresscms.org> * @version $Id: functions.php 12329 2013-09-19 13:53:36Z skenow $ */ /** * Function to get the base domain name from a URL. * credit for this function should goto Phosphorus and Lime, it is released under GPL (v2). * http://phosphorusandlime.blogspot.com/2007/08/php-get-base-domain.html * * @param string $url the URL to be stripped. * @return string */Method `imcms_get_base_domain` has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Function `imcms_get_base_domain` has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
The function imcms_get_base_domain() has an NPath complexity of 256. The configured NPath complexity threshold is 200.
The function imcms_get_base_domain() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
Avoid assigning values to variables in if clauses and the like (line '54', column '7').
Similar blocks of code found in 2 locations. Consider refactoring.
The variable $DOMAIN is not named in camelCase.
The variable $G_TLD is not named in camelCase.
The variable $C_TLD is not named in camelCase.
The variable $full_domain is not named in camelCase.
The variable $base_domain is not named in camelCase.function imcms_get_base_domain($url)Opening brace should be on the same line as the declaration{ $debug = 0; $base_domain = ''; // generic tlds (source: http://en.wikipedia.org/wiki/Generic_top-level_domain) $G_TLD = array(Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'biz','com','edu','gov','info','int','mil','name','net','org','aero','asia','cat','coop','jobs','mobi','museum','pro','tel','travel',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'arpa','root','berlin','bzh','cym','gal','geo','kid','kids','lat','mail','nyc','post','sco','web','xxx',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'nato', 'example','invalid','localhost','test','bitnet','csnet','ip','local','onion','uucp','co'); // country tlds (source: http://en.wikipedia.org/wiki/Country_code_top-level_domain) $C_TLD = array( // activeTabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'ac','ad','ae','af','ag','ai','al','am','an','ao','aq','ar','as','at','au','aw','ax','az',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'ba','bb','bd','be','bf','bg','bh','bi','bj','bm','bn','bo','br','bs','bt','bw','by','bz',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'ca','cc','cd','cf','cg','ch','ci','ck','cl','cm','cn','co','cr','cu','cv','cx','cy','cz',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'de','dj','dk','dm','do','dz','ec','ee','eg','er','es','et','eu','fi','fj','fk','fm','fo',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'fr','ga','gd','ge','gf','gg','gh','gi','gl','gm','gn','gp','gq','gr','gs','gt','gu','gw',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'gy','hk','hm','hn','hr','ht','hu','id','ie','il','im','in','io','iq','ir','is','it','je',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'jm','jo','jp','ke','kg','kh','ki','km','kn','kr','kw','ky','kz','la','lb','lc','li','lk',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'lr','ls','lt','lu','lv','ly','ma','mc','md','mg','mh','mk','ml','mm','mn','mo','mp','mq',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'mr','ms','mt','mu','mv','mw','mx','my','mz','na','nc','ne','nf','ng','ni','nl','no','np',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'nr','nu','nz','om','pa','pe','pf','pg','ph','pk','pl','pn','pr','ps','pt','pw','py','qa',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 're','ro','ru','rw','sa','sb','sc','sd','se','sg','sh','si','sk','sl','sm','sn','sr','st',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'sv','sy','sz','tc','td','tf','tg','th','tj','tk','tl','tm','tn','to','tr','tt','tv','tw',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'tz','ua','ug','uk','us','uy','uz','va','vc','ve','vg','vi','vn','vu','wf','ws','ye','yu',Tabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'za','zm','zw', // inactiveTabs must be used to indent lines; spaces are not allowed
Unexpected spaces found. 'eh','kp','me','rs','um','bv','gb','pm','sj','so','yt','su','tp','bu','cs','dd','zr'); // get domainNewline required after opening brace
Closing brace must be on a line by itself if (!$full_domain = imcms_get_url_domain($url)) {return $base_domain;} // break up domain, reverse $DOMAIN = explode('.', $full_domain);The function imcms_get_base_domain() calls the typical debug function print_r() which is mostly only used during development.
Inline control structures are not allowed if ($debug) print_r($DOMAIN); $DOMAIN = array_reverse($DOMAIN);The function imcms_get_base_domain() calls the typical debug function print_r() which is mostly only used during development.
Inline control structures are not allowed if ($debug) print_r($DOMAIN); // first check for ip addressNewline required after opening brace
Closing brace must be on a line by itself if (count($DOMAIN) == 4 && is_numeric($DOMAIN[0]) && is_numeric($DOMAIN[3])) {return $full_domain;} // if only 2 domain parts, that must be our domainInline control structures are not allowed if (count($DOMAIN) <= 2) return $full_domain; /* finally, with 3+ domain parts: obviously D0 is tld now, if D0 = ctld and D1 = gtld, we might have something like com.uk so, if D0 = ctld && D1 = gtld && D2 != 'www', domain = D2.D1.D0 else if D0 = ctld && D1 = gtld && D2 == 'www', domain = D1.D0 else domain = D1.D0 - these rules are simplified below. */Expected 1 space after closing parenthesis; found 5 if (in_array($DOMAIN[0], $C_TLD) && in_array($DOMAIN[1], $G_TLD) && $DOMAIN[2] != 'www') { $full_domain = $DOMAIN[2].'.'.$DOMAIN[1].'.'.$DOMAIN[0];The method imcms_get_base_domain uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. } else { $full_domain = $DOMAIN[1].'.'.$DOMAIN[0]; } // did we succeed? return $full_domain;} /** * Function to get the domain from a URL. * credit for this function should goto Phosphorus and Lime, it is released under GPL (v2). * http://phosphorusandlime.blogspot.com/2007/08/php-get-base-domain.html * * @param string $url the URL to be stripped. * @return string */The variable $_URL is not named in camelCase.function imcms_get_url_domain($url)Opening brace should be on the same line as the declaration{ $domain = ''; $_URL = parse_url($url); Closing brace must be on a line by itself
Newline required after opening brace if (!empty($_URL) || !empty($_URL['host'])) {$domain = $_URL['host'];} return $domain;Expected 1 blank line at end of file; 2 found}