src/Server/RequestHandler/AdvancedStaticFilesServer.php
Define and throw a dedicated exception instead of using a generic one. Open
Open
throw new RuntimeException('AdvancedStaticFilesHandler requires setting "public_dir", which is unavailable. Either disable driver or fill "public_dir" setting.');
- 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
Remove this unused "MIME_TYPE_APPLICATION_OCTET_STREAM" private field. Invalid
Invalid
private const MIME_TYPE_APPLICATION_OCTET_STREAM = 'application/octet-stream';
- Read upRead up
- Exclude checks
If a private
field is declared but not used in the program, it can be considered dead code and should therefore be removed. This will
improve maintainability because developers will not wonder what the variable is used for.
Noncompliant Code Example
class MyClass { private $foo = 4; //foo is unused public function compute($a) { return $a * 4; } }
Compliant Solution
class MyClass { public function compute($a) { return $a * 4; } }
See
- CERT, MSC12-CPP. - Detect and remove code that has no effect