include/RequirementsValidation.php
Define and throw a dedicated exception instead of using a generic one. Open
Open
throw new \Exception("The {$extension} library is missing");
- 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
Open
throw new \Exception('Wrong PHP version, recommended version >= 7.4');
- 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
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$extensions = get_loaded_extensions();
- Exclude checks
Line exceeds 120 characters; contains 145 characters Open
Open
foreach (['PDO', 'pdo_mysql', 'json', 'session', 'mbstring', 'fileinfo', 'intl', 'SPL', 'Reflection', 'SimpleXML', 'bcmath'] as $extension) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (!\in_array($extension, $extensions)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
throw new \Exception("The {$extension} library is missing");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
foreach (['PDO', 'pdo_mysql', 'json', 'session', 'mbstring', 'fileinfo', 'intl', 'SPL', 'Reflection', 'SimpleXML', 'bcmath'] as $extension) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
throw new \Exception('Wrong PHP version, recommended version >= 7.4');
- Exclude checks