Showing 12 of 12 total issues

The class Log has 11 public methods. Consider refactoring Log to keep number of public methods under 10.
Open

class Log implements LogInterface
{
    const EMERGENCY = 1;
    const ALERT = 2;
    const CRITICAL = 4;
Severity: Minor
Found in src/Log.php by phpmd

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

Method setupErrorHandling has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function setupErrorHandling(callable $handler = null)
    {
        set_error_handler(function ($errno, $errstr, $errfile, $errline) {
            // do not touch errors that are not marked for reporting
            if (!($errno & error_reporting())) {
Severity: Minor
Found in src/Log.php - About 1 hr to fix

    Avoid too many return statements within this method.
    Open

                    return 'notice';
    Severity: Major
    Found in src/Log.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                      return 'warning';
      Severity: Major
      Found in src/Log.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                        return 'info';
        Severity: Major
        Found in src/Log.php - About 30 mins to fix

          Missing class import via use statement (line '102', column '22').
          Open

                      $e = new \ErrorException($errstr, $errno, $errno, $errfile, $errline);
          Severity: Minor
          Found in src/Log.php by phpmd

          MissingImport

          Since: 2.7.0

          Importing all external classes in a file through use statements makes them clearly visible.

          Example

          function make() {
              return new \stdClass();
          }

          Source http://phpmd.org/rules/cleancode.html#MissingImport

          Avoid too many return statements within this method.
          Open

                          return 'debug';
          Severity: Major
          Found in src/Log.php - About 30 mins to fix

            Remove error control operator '@' on line 75.
            Open

                public static function logToFile(string $location = null) {
                    return function ($message, $context, $severity, $level) use ($location) {
                        $location = $location !== null ? $location : ini_get('error_log');
                        if (!is_dir(dirname($location))) {
                            mkdir(dirname($location), 0755, true);
            Severity: Minor
            Found in src/Log.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Avoid unused parameters such as '$severity'.
            Open

                    return function ($message, $context, $severity, $level) use ($location) {
            Severity: Minor
            Found in src/Log.php by phpmd

            UnusedFormalParameter

            Since: 0.2

            Avoid passing parameters to methods or constructors and then not using those parameters.

            Example

            class Foo
            {
                private function bar($howdy)
                {
                    // $howdy is not used
                }
            }

            Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

            The method setupErrorHandling() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
            Open

                public function setupErrorHandling(callable $handler = null)
                {
                    set_error_handler(function ($errno, $errstr, $errfile, $errline) {
                        // do not touch errors that are not marked for reporting
                        if (!($errno & error_reporting())) {
            Severity: Minor
            Found in src/Log.php by phpmd

            CyclomaticComplexity

            Since: 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example

            // Cyclomatic Complexity = 11
            class Foo {
            1   public function example() {
            2       if ($a == $b) {
            3           if ($a1 == $b1) {
                            fiddle();
            4           } elseif ($a2 == $b2) {
                            fiddle();
                        } else {
                            fiddle();
                        }
            5       } elseif ($c == $d) {
            6           while ($c == $d) {
                            fiddle();
                        }
            7        } elseif ($e == $f) {
            8           for ($n = 0; $n < $h; $n++) {
                            fiddle();
                        }
                    } else {
                        switch ($z) {
            9               case 1:
                                fiddle();
                                break;
            10              case 2:
                                fiddle();
                                break;
            11              case 3:
                                fiddle();
                                break;
                            default:
                                fiddle();
                                break;
                        }
                    }
                }
            }

            Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

            Opening brace should be on a new line
            Open

                public static function logToFile(string $location = null) {
            Severity: Minor
            Found in src/Log.php by phpcodesniffer

            Whitespace found at end of line
            Open

                 * All notice / deprecated / strict errors are only logged, everything else triggers an exception. 
            Severity: Minor
            Found in src/Log.php by phpcodesniffer
            Severity
            Category
            Status
            Source
            Language