Showing 307 of 307 total issues
Avoid deeply nested control flow statements. Open
';}elseif(isset($_GET["indexes"])){$a=$_GET["indexes"];$Mc=array("PRIMARY","UNIQUE","INDEX");$R=table_status($a,true);if(preg_match('~MyISAM|M?aria'.($e->server_info>=5.6?'|InnoDB':'').'~i',$R["Engine"]))$Mc[]="FULLTEXT";$w=indexes($a);$He=array();if($y=="mongo"){$He=$w["_id_"];unset($Mc[0]);unset($w["_id_"]);}$L=$_POST;if($_POST&&!$k&&!$_POST["add"]&&!$_POST["drop_col"]){$sa=array();foreach($L["indexes"]as$v){$F=$v["name"];if(in_array($v["type"],$Mc)){$d=array();$md=array();$yb=array();$P=array();ksort($v["columns"]);foreach($v["columns"]as$z=>$c){if($c!=""){$ld=$v["lengths"][$z];$xb=$v["descs"][$z];$P[]=idf_escape($c).($ld?"(".(+$ld).")":"").($xb?" DESC":"");$d[]=$c;$md[]=($ld?$ld:null);$yb[]=$xb;}}if($d){$dc=$w[$F];if($dc){ksort($dc["columns"]);ksort($dc["lengths"]);ksort($dc["descs"]);if($v["type"]==$dc["type"]&&array_values($dc["columns"])===$d&&(!$dc["lengths"]||array_values($dc["lengths"])===$md)&&array_values($dc["descs"])===$yb){unset($w[$F]);continue;}}$sa[]=array($v["type"],$F,$P);}}}foreach($w
Avoid deeply nested control flow statements. Open
as$L){echo"<tr>","<th>".h($L["Name"]),"<td>".($L["Execute at"]?'At given time'."<td>".$L["Execute at"]:'Every'." ".$L["Interval value"]." ".$L["Interval field"]."<td>$L[Starts]"),"<td>$L[Ends]",'<td><a href="'.h(ME).'event='.urlencode($L["Name"]).'">'.'Alter'.'</a>';}echo"</table>\n";$Zb=$e->result("SELECT @@event_scheduler");if($Zb&&$Zb!="ON")echo"<p class='error'><code class='jush-sqlset'>event_scheduler</code>: ".h($Zb)."\n";}echo'<p class="links"><a href="'.h(ME).'event=">'.'Create event'."</a>\n";}if($Tf)echo"<script type='text/javascript'>ajaxSetHtml('".js_escape(ME)."script=db');</script>\n";}}}page_footer();
Avoid deeply nested control flow statements. Open
select($J,$f=null,$ge=array(),$_=0){global$y;$od=array();$w=array();$d=array();$Fa=array();$tg=array();$K=array();odd('');for($t=0;(!$_||$t<$_)&&($L=$J->fetch_row());$t++){if(!$t){echo"<table cellspacing='0' class='nowrap'>\n","<thead><tr>";for($x=0;$x<count($L);$x++){$l=$J->fetch_field();$F=$l->name;$fe=$l->orgtable;$ee=$l->orgname;$K[$l->table]=$fe;if($ge&&$y=="sql")$od[$x]=($F=="table"?"table=":($F=="possible_keys"?"indexes=":null));elseif($fe!=""){if(!isset($w[$fe])){$w[$fe]=array();foreach(indexes($fe,$f)as$v){if($v["type"]=="PRIMARY"){$w[$fe]=array_flip($v["columns"]);break;}}$d[$fe]=$w[$fe];}if(isset($d[$fe][$ee])){unset($d[$fe][$ee]);$w[$fe][$ee]=$x;$od[$x]=$fe;}}if($l->charsetnr==63)$Fa[$x]=true;$tg[$x]=$l->type;echo"<th".($fe!=""||$l->name!=$ee?" title='".h(($fe!=""?"$fe.":"").$ee)."'":"").">".h($F).($ge?doc_link(array('sql'=>"explain-output.html#explain_".strtolower($F))):"");}echo"</thead>\n";}echo"<tr".odd().">";foreach($L
Similar blocks of code found in 2 locations. Consider refactoring. Open
substr($Ed,0,end($U));return$Ed;}function
str2long($Ed,$Ke){$U=array_values(unpack('V*',str_pad($Ed,4*ceil(strlen($Ed)/4),"\0")));if($Ke)$U[]=strlen($Ed);return$U;}function
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 95.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
substr($lf,0,end($W));return$lf;}function
str2long($lf,$Ng){$W=array_values(unpack('V*',str_pad($lf,4*ceil(strlen($lf)/4),"\0")));if($Ng)$W[]=strlen($lf);return$W;}function
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 95.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Consider simplifying this complex logical expression. Open
select($Q,$N,$Z,$s,$de=array(),$_=1,$G=0,$Ie=false){global$b,$y;$Vc=(count($s)<count($N));$I=$b->selectQueryBuild($N,$Z,$s,$de,$_,$G);if(!$I)$I="SELECT".limit(($_GET["page"]!="last"&&+$_&&$s&&$Vc&&$y=="sql"?"SQL_CALC_FOUND_ROWS ":"").implode(", ",$N)."\nFROM ".table($Q),($Z?"\nWHERE ".implode(" AND ",$Z):"").($s&&$Vc?"\nGROUP BY ".implode(", ",$s):"").($de?"\nORDER BY ".implode(", ",$de):""),($_!=""?+$_:null),($G?$_*$G:0),"\n");$Cf=microtime(true);$K=$this->_conn->query($I);if($Ie)echo$b->selectQuery($I,format_time($Cf));return$K;}function
Consider simplifying this complex logical expression. Open
as$F=>$l){$Xc=preg_match('~char|text|enum|set~',$l["type"]);if((is_numeric($X["val"])||!preg_match('~(^|[^o])int|float|double|decimal|bit~',$l["type"]))&&(!preg_match("~[\x80-\xFF]~",$X["val"])||$Xc)){$F=idf_escape($F);$Ya[]=($y=="sql"&&$Xc&&!preg_match("~^utf8_~",$l["collation"])?"CONVERT($F USING ".charset($e).")":$F);}}$K[]=($Ya?"(".implode("$db OR ",$Ya)."$db)":"0");}}}return$K;}function
Consider simplifying this complex logical expression. Open
select($R,$N,$Y,$p,$E=array(),$y=1,$F=0,$nd=false){global$b,$v;$u=(count($p)<count($N));$I=$b->selectQueryBuild($N,$Y,$p,$E,$y,$F);if(!$I)$I="SELECT".limit(($_GET["page"]!="last"&&+$y&&$p&&$u&&$v=="sql"?"SQL_CALC_FOUND_ROWS ":"").implode(", ",$N)."\nFROM ".table($R),($Y?"\nWHERE ".implode(" AND ",$Y):"").($p&&$u?"\nGROUP BY ".implode(", ",$p):"").($E?"\nORDER BY ".implode(", ",$E):""),($y!=""?+$y:null),($F?$y*$F:0),"\n");$Td=microtime(true);$K=$this->_conn->query($I);if($nd)echo$b->selectQuery($I,format_time($Td));return$K;}function
Method limit
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
limit($I,$Y,$y,$Pc=0,$Kd=" "){return" $I$Y".($y!==null?$Kd."LIMIT $y".($Pc?" OFFSET $Pc":""):"");}function
Method update
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
update($Q,$P,$Qe,$_=0,$sf="\n"){$Hg=array();foreach($P
Method enum_input
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
enum_input($U,$wa,$l,$Y,$Sb=null){global$b;preg_match_all("~'((?:[^']|'')*)'~",$l["length"],$rd);$K=($Sb!==null?"<label><input type='$U'$wa value='$Sb'".((is_array($Y)?in_array($Sb,$Y):$Y===0)?" checked":"")."><i>".'empty'."</i></label>":"");foreach($rd[1]as$t=>$X){$X=stripcslashes(str_replace("''","'",$X));$Na=(is_int($Y)?$Y==$t+1:(is_array($Y)?in_array($t+1,$Y):$Y===$X));$K.=" <label><input type='$U'$wa value='".($t+1)."'".($Na?' checked':'').'>'.h($b->editVal($X,$l)).'</label>';}return$K;}function
Method limit
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
limit($I,$Z,$_,$Od=0,$sf=" "){return" $I$Z".($_!==null?$sf."LIMIT $_".($Od?" OFFSET $Od":""):"");}function
Method send_mail
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
send_mail($pb,$Yd,$B,$Sb="",$Gb=array()){$j=(DIRECTORY_SEPARATOR=="/"?"\n":"\r\n");$B=str_replace("\n",$j,wordwrap(str_replace("\r","","$B\n")));$Ba=uniqid("boundary");$qa="";foreach((array)$Gb["error"]as$x=>$V){if(!$V)$qa.="--$Ba$j"."Content-Type: ".str_replace("\n","",$Gb["type"][$x]).$j."Content-Disposition: attachment; filename=\"".preg_replace('~["\\n]~','',$Gb["name"][$x])."\"$j"."Content-Transfer-Encoding: base64$j$j".chunk_split(base64_encode(file_get_contents($Gb["tmp_name"][$x])),76,$j).$j;}$ya="";$bc="Content-Type: text/plain; charset=utf-8$j"."Content-Transfer-Encoding: 8bit";if($qa){$qa.="--$Ba--$j";$ya="--$Ba$j$bc$j$j";$bc="Content-Type: multipart/mixed; boundary=\"$Ba\"";}$bc.=$j."MIME-Version: 1.0$j"."X-Mailer: Adminer Editor".($Sb?$j."From: ".str_replace("\n","",$Sb):"");return
Method edit_fields
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
edit_fields($m,$Xa,$U="TABLE",$o=array(),$cb=false){global$e,$Oc;$m=array_values($m);echo'<thead><tr class="wrap">
Method enum_input
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
enum_input($ue,$c,$l,$W,$sb=null){global$b;preg_match_all("~'((?:[^']|'')*)'~",$l["length"],$Bc);$K=($sb!==null?"<label><input type='$ue'$c value='$sb'".((is_array($W)?in_array($sb,$W):$W===0)?" checked":"")."><i>".'empty'."</i></label>":"");foreach($Bc[1]as$q=>$V){$V=stripcslashes(str_replace("''","'",$V));$Fa=(is_int($W)?$W==$q+1:(is_array($W)?in_array($q+1,$W):$W===$V));$K.=" <label><input type='$ue'$c value='".($q+1)."'".($Fa?' checked':'').'>'.h($b->editVal($V,$l)).'</label>';}return$K;}function
Method update
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
update($R,$P,$td,$y=0,$Kd="\n"){$Ge=array();foreach($P
Function set_charset
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
connect($O,$T,$G){$this->_link=@mysql_connect(($O!=""?$O:ini_get("mysql.default_host")),("$O$T"!=""?$T:ini_get("mysql.default_user")),("$O$T$G"!=""?$G:ini_get("mysql.default_password")),true,131072);if($this->_link)$this->server_info=mysql_get_server_info($this->_link);else$this->error=mysql_error();return(bool)$this->_link;}function
set_charset($Da){if(function_exists('mysql_set_charset')){if(mysql_set_charset($Da,$this->_link))return
true;mysql_set_charset('utf8',$this->_link);}return$this->query("SET NAMES $Da");}function
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function set_charset
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
connect($O,$V,$we){$this->_link=@mysql_connect(($O!=""?$O:ini_get("mysql.default_host")),("$O$V"!=""?$V:ini_get("mysql.default_user")),("$O$V$we"!=""?$we:ini_get("mysql.default_password")),true,131072);if($this->_link)$this->server_info=mysql_get_server_info($this->_link);else$this->error=mysql_error();return(bool)$this->_link;}function
set_charset($La){if(function_exists('mysql_set_charset')){if(mysql_set_charset($La,$this->_link))return
true;mysql_set_charset('utf8',$this->_link);}return$this->query("SET NAMES $La");}function
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function editInput
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
editFunctions($l){$K=array();if($l["null"]&&preg_match('~blob~',$l["type"]))$K["NULL"]='empty';$K[""]=($l["null"]||$l["auto_increment"]||like_bool($l)?"":"*");if(preg_match('~date|time~',$l["type"]))$K["now"]='now';if(preg_match('~_(md5|sha1)$~i',$l["field"],$A))$K[]=strtolower($A[1]);return$K;}function
editInput($R,$l,$c,$W){if($l["type"]=="enum")return(isset($_GET["select"])?"<label><input type='radio'$c value='-1' checked><i>".'original'."</i></label> ":"").enum_input("radio",$c,$l,($W||isset($_GET["select"])?$W:0),($l["null"]?"":null));$Xc=$this->_foreignKeyOptions($R,$l["field"],$W);if($Xc!==null)return(is_array($Xc)?"<select$c>".optionlist($Xc,$W,true)."</select>":"<input value='".h($W)."'$c class='hidden'><input value='".h($Xc)."' class='jsonly' onkeyup=\"whisper('".h(ME."script=complete&source=".urlencode($R)."&field=".urlencode($l["field"]))."&value=', this);\"><div onclick='return whisperClick(event, this.previousSibling);'></div>");if(like_bool($l))return'<input type="checkbox" value="'.h($W?$W:1).'"'.($W?' checked':'')."$c>";$cc="";if(preg_match('~time~',$l["type"]))$cc='HH:MM:SS';if(preg_match('~date|timestamp~',$l["type"]))$cc='[yyyy]-mm-dd'.($cc?" [$cc]":"");if($cc)return"<input value='".h($W)."'$c> ($cc)";if(preg_match('~_(md5|sha1)$~i',$l["field"]))return"<input type='password' value='".h($W)."'$c>";return'';}function
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function get_temp_dir
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
apply_sql_function($o,$d){return($o?($o=="unixepoch"?"DATETIME($d, '$o')":($o=="count distinct"?"COUNT(DISTINCT ":strtoupper("$o("))."$d)"):$d);}function
get_temp_dir(){$K=ini_get("upload_tmp_dir");if(!$K){if(function_exists('sys_get_temp_dir'))$K=sys_get_temp_dir();else{$Fb=@tempnam("","");if(!$Fb)return
false;$K=dirname($Fb);unlink($Fb);}}return$K;}function
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"