Argument 1 (error_handler)
is Closure(mixed,mixed,mixed,mixed):void
but \set_error_handler()
takes callable(int,string):bool|callable(int,string,string):bool|callable(int,string,string,int):bool|callable(int,string,string,int,array):bool|null
Open
set_error_handler(function ($errNo, $errStr, $errFile, $errLine) {
- Exclude checks
Either remove this useless object instantiation of class "\App\Cli" or use it Open
new \App\Cli();
- Read upRead up
- Exclude checks
There is no good reason to create a new object to not do anything with it. Most of the time, this is due to a missing piece of code and so could lead to an unexpected behavior in production.
If it was done on purpose because the constructor has side-effects, then that side-effect code should be moved into a separate, static method and called directly.
Noncompliant Code Example
if ($x < 0) { new foo; // Noncompliant }
Compliant Solution
$var = NULL; if ($x < 0) { $var = new foo; }
Define and throw a dedicated exception instead of using a generic one. Open
throw new \Exception($errNo . ': ' . $errStr . ' in ' . $errFile . ', line ' . $errLine);
- 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
Define and throw a dedicated exception instead of using a generic one. Open
throw new \Exception('Console access only from the operating system CLI.');
- 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
Spaces must be used to indent lines; tabs are not allowed Open
require __DIR__ . '/include/RequirementsValidation.php';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo "Examples:\nphp74 cli.php\n/usr/local/php74/bin/php74 cli.php\n/usr/local/php80/bin/php80 cli.php\n";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo str_repeat('--', 40) . PHP_EOL;
- 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
echo str_repeat('--', 40) . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo str_repeat('--', 40) . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
new \App\Cli();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('test' === \App\Config::main('systemMode')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo $th->getMessage() . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \Exception($errNo . ': ' . $errStr . ' in ' . $errFile . ', line ' . $errLine);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array($errNo, [E_ERROR, E_WARNING, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (PHP_SAPI !== 'cli') {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \Exception('Console access only from the operating system CLI.');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo rtrim(str_replace(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR, '', $e->__toString()), PHP_EOL);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw $e;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks