Method real_connect
has 7 arguments (exceeds 4 allowed). Consider refactoring. Wontfix
public function real_connect($host = null, $username = null, $passwd = null, $dbname = null, $port = null, $socket = null, $flags = null)
Method __construct
has 7 arguments (exceeds 4 allowed). Consider refactoring. Wontfix
public function __construct($host = null, $username = null, $passwd = null, $dbname = null, $port = null, $socket = null, $debug = null) // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
Rename "$debug" which has the same name as the field declared at line 45. Open
$debug = $event->getSubject();
- Read upRead up
- Exclude checks
Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.
Noncompliant Code Example
class Foo { public $myField; public function doSomething() { $myField = 0; ... } }
See
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Remove this unused private "currentDatabase" method. Open
private function currentDatabase()
- Read upRead up
- Exclude checks
private
methods that are never executed are dead code: unnecessary, inoperative code that should be removed. Cleaning out dead code
decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.
Noncompliant Code Example
public class Foo { private function Foo() {} // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class. public static function doSomething() { $foo = new Foo(); ... } private function unusedPrivateFunction() { // Noncompliant } }
Compliant Solution
public class Foo { private function Foo(){} // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class. public static function doSomething() { $foo = new Foo(); } }
See
- CERT, MSC07-CPP. - Detect and remove dead code
Define and throw a dedicated exception instead of using a generic one. Open
throw new RuntimeException($errstr, $errno);
- Read upRead up
- Exclude checks
If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.
Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.
Noncompliant Code Example
throw new Exception(); // Noncompliant
Compliant Solution
throw new InvalidArgumentException(); // or throw new UnexpectedValueException();
See
- MITRE, CWE-397 - Declaration of Throws for Generic Exception
- CERT, ERR07-J. - Do not throw RuntimeException, Exception, or Throwable