Method email_new_pw
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
function email_new_pw($to) {
include ('mysql_access.php');
$aresponse=$db->query("SELECT username FROM contact_information WHERE email='$to'");
Function email_new_pw
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
function email_new_pw($to) {
include ('mysql_access.php');
$aresponse=$db->query("SELECT username FROM contact_information WHERE email='$to'");
- 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
The function email_new_pw() has 103 lines of code. Current threshold is set to 100. Avoid really long methods. Open
function email_new_pw($to) {
include ('mysql_access.php');
$aresponse=$db->query("SELECT username FROM contact_information WHERE email='$to'");
- Exclude checks
The function email_new_pw() has a Cyclomatic Complexity of 22. The configured cyclomatic complexity threshold is 10. Open
function email_new_pw($to) {
include ('mysql_access.php');
$aresponse=$db->query("SELECT username FROM contact_information WHERE email='$to'");
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
$aresponse=$db->query("SELECT username FROM contact_information WHERE email='$to'");
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
$update = $db->query($sql) or exit("There was an error, contact Webmaster");
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Missing class import via use statement (line '98', column '16'). Open
$hasher = new PasswordHash(8,true);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The function email_new_pw() contains an exit expression. Open
$update = $db->query($sql) or exit("There was an error, contact Webmaster");
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
Avoid unused local variables such as '$update'. Open
$update = $db->query($sql) or exit("There was an error, contact Webmaster");
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Similar blocks of code found in 2 locations. Consider refactoring. Open
switch ($num) {
case 1:
$word1 = 'Dog';
break;
case 2:
- 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 133.
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
switch ($num) {
case 1:
$word2 = 'Dog';
break;
case 2:
- 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 133.
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
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 13 and the first side effect is on line 2. Open
<?php
- Exclude checks
Avoid variables with short names like $to. Configured minimum length is 3. Open
function email_new_pw($to) {
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Spaces must be used for alignment; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Space found before comma in function call Open
$num = rand ( 1 , 10 );
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$hash = $hasher->HashPassword($password);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$subject = "Your password has been reset!";
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
<?php
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
<p>email:<input type="text" name="user_email" style="width: 7em">
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
</form>
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
switch ($num) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
// use wordwrap() if lines are longer than 70 characters
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
//$msg = wordwrap($msg,70);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
// send email
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (isset($_POST['user_email']))
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
</p><p>
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$num = rand ( 11, 999 );
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$msg = "$user ($to) APO password has been reset to : $password.";
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
break;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$password = $word1 . $word2 . $num;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$hash = htmlspecialchars($hash, ENT_QUOTES);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
<form form name="signin" action="" method="post">
- Exclude checks
Space found before comma in function call Open
$num = rand ( 1 , 10 );
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$num = rand ( 1 , 10 );
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
mail($to,$subject,$msg);
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
email_new_pw($_POST['user_email']);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
<p>Enter your email to recieve a new password.</p>
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
?>
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$hasher = new PasswordHash(8,true);
- Exclude checks
Function closing brace must go on the next line following the body; found 1 blank lines before brace Open
}
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
// the message
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
<input type="submit" name="submit" value="Receive Password"/></p>
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$aresponse=$db->query("SELECT username FROM contact_information WHERE email='$to'");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
include ('mysql_access.php');
- Exclude checks
End of line character is invalid; expected "\n" but found "\r\n" Open
<?php
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$user=$aresult['username'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$aresult=mysqli_fetch_array($aresponse);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($num) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$num = rand ( 1 , 10 );
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
//generate a random pw with 2 words and 2 numbers
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 2:
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word1 = 'Bridge';
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 5:
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word1 = 'Purple';
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word1 = 'Purple';
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
default:
- Exclude checks
Whitespace found at end of line Open
break;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 2:
- Exclude checks
Space before opening parenthesis of function call prohibited Open
require_once ('mysql_access.php');
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word2 = 'Purple';
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word1 = 'password';
- Exclude checks
Opening brace should be on a new line Open
function email_new_pw($to) {
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
default:
- Exclude checks
Space before opening parenthesis of function call prohibited Open
$num = rand ( 1 , 10 );
- Exclude checks
Space before opening parenthesis of function call prohibited Open
$num = rand ( 11, 999 );
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word1 = 'House';
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word1 = 'Bridge';
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word2 = 'Bridge';
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
$num = rand ( 1 , 10 );
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word2 = 'Biggest';
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word1 = 'Biggest';
- Exclude checks
Expected 1 space after closing parenthesis; found 10 Open
if (isset($_POST['user_email']))
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 8:
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word2 = 'Biggest';
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word2 = 'password';
- Exclude checks
Space before opening parenthesis of function call prohibited Open
require_once ("PasswordHash.php");
- Exclude checks
Space after opening parenthesis of function call prohibited Open
$num = rand ( 1 , 10 );
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 7:
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word2 = 'Dog';
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 3:
- Exclude checks
Whitespace found at end of line Open
break;
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
$num = rand ( 11, 999 );
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 4:
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 5:
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word2 = 'House';
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 10:
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word1 = 'Dog';
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word1 = 'House';
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 10:
- Exclude checks
Space after opening parenthesis of function call prohibited Open
$num = rand ( 1 , 10 );
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 4:
- Exclude checks
Space after opening parenthesis of function call prohibited Open
$num = rand ( 11, 999 );
- Exclude checks
No space found after comma in function call Open
mail($to,$subject,$msg);
- Exclude checks
Space before opening parenthesis of function call prohibited Open
require_once ('session.php');
- Exclude checks
Space before opening parenthesis of function call prohibited Open
$num = rand ( 1 , 10 );
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 9:
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 3:
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 9:
- Exclude checks
Whitespace found at end of line Open
}
- Exclude checks
No space found after comma in function call Open
mail($to,$subject,$msg);
- Exclude checks
Whitespace found at end of line Open
break;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 1:
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word2 = 'Bridge';
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word2 = 'Purple';
- Exclude checks
No space found after comma in function call Open
$hasher = new PasswordHash(8,true);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 6:
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word1 = 'Biggest';
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
if (isset($_POST['user_email']))
- Exclude checks
Space before opening parenthesis of function call prohibited Open
include ('mysql_access.php');
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 1:
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word2 = 'Dog';
- Exclude checks
Expected 0 spaces before closing bracket; 1 found Open
$num = rand ( 1 , 10 );
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 8:
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word1 = 'Dog';
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
$word2 = 'House';
- Exclude checks
Whitespace found at end of line Open
break;
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 6:
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
case 7:
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks