k911/swoole-bundle

View on GitHub
src/Server/RequestHandler/AdvancedStaticFilesServer.php

Summary

Maintainability
A
0 mins
Test Coverage
B
87%

Define and throw a dedicated exception instead of using a generic one.
Open

            throw new RuntimeException('AdvancedStaticFilesHandler requires setting "public_dir", which is unavailable. Either disable driver or fill "public_dir" setting.');

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

Remove this unused "MIME_TYPE_APPLICATION_OCTET_STREAM" private field.
Invalid

    private const MIME_TYPE_APPLICATION_OCTET_STREAM = 'application/octet-stream';

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

There are no issues that match your filters.

Category
Status