gdbots/common-php

View on GitHub

Showing 137 of 137 total issues

Function create has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public static function create($str, $camelize = true)
    {
        // remove special chars (accents, etc.)
        $str = trim(self::normalize($str));
        $str = ltrim($str, '#_ ');
Severity: Minor
Found in src/Common/Util/HashtagUtils.php - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function varToString has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public static function varToString($var)
    {
        if (is_object($var)) {
            return sprintf('Object(%s)', get_class($var));
        }
Severity: Minor
Found in src/Common/Util/StringUtils.php - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Consider simplifying this complex logical expression.
Open

            if (($c >= 224 && $c <= 229) || ($c >= 192 && $c <= 198) || ($c >= 281 && $c <= 286)) {
                $slug .= 'a';
            } else if (($c >= 232 && $c <= 235) || ($c >= 200 && $c <= 203)) {
                $slug .= 'e';
            } else if (($c >= 236 && $c <= 239) || ($c >= 204 && $c <= 207)) {
Severity: Major
Found in src/Common/Util/SlugUtils.php - About 40 mins to fix

    Each class must be in a file by itself
    Open

    class EnumTest extends \PHPUnit_Framework_TestCase
    Severity: Minor
    Found in tests/Common/EnumTest.php by phpcodesniffer

    Function isValid has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function isValid($hashtag)
        {
            $hashtag = ltrim($hashtag, '#');
            if (empty($hashtag)) {
                return false;
    Severity: Minor
    Found in src/Common/Util/HashtagUtils.php - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Missing class import via use statement (line '26', column '23').
    Open

                throw new \InvalidArgumentException(

    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

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

        protected function __construct($slug)
        {
            @trigger_error(sprintf('"%s" is deprecated.  Use "Gdbots\Pbj\WellKnown\SlugIdentifier" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED);
    
            if (!is_string($slug)) {
    Severity: Minor
    Found in src/Identifiers/SlugIdentifier.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 too many return statements within this method.
    Open

                return 'true';
    Severity: Major
    Found in src/Common/Util/StringUtils.php - About 30 mins to fix

      The method loadTraits has a boolean flag argument $deep, which is a certain sign of a Single Responsibility Principle violation.
      Open

          private static function loadTraits($class, $deep = true, $autoload = true)
      Severity: Minor
      Found in src/Common/Util/ClassUtils.php by phpmd

      BooleanArgumentFlag

      Since: 1.4.0

      A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

      Example

      class Foo {
          public function bar($flag = true) {
          }
      }

      Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

      Missing class import via use statement (line '32', column '23').
      Open

                  throw new \InvalidArgumentException(

      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

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

          protected function __construct(UuidInterface $uuid)
          {
              @trigger_error(sprintf('"%s" is deprecated.  Use "Gdbots\Pbj\WellKnown\[Time]UuidIdentifier" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED);
              $this->uuid = $uuid;
          }
      Severity: Minor
      Found in src/Identifiers/UuidIdentifier.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

      The method loadTraits has a boolean flag argument $autoload, which is a certain sign of a Single Responsibility Principle violation.
      Open

          private static function loadTraits($class, $deep = true, $autoload = true)
      Severity: Minor
      Found in src/Common/Util/ClassUtils.php by phpmd

      BooleanArgumentFlag

      Since: 1.4.0

      A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

      Example

      class Foo {
          public function bar($flag = true) {
          }
      }

      Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

      The method createFromCamel has a boolean flag argument $allowSlashes, which is a certain sign of a Single Responsibility Principle violation.
      Open

          public static function createFromCamel($string, $allowSlashes = false)
      Severity: Minor
      Found in src/Common/Util/SlugUtils.php by phpmd

      BooleanArgumentFlag

      Since: 1.4.0

      A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

      Example

      class Foo {
          public function bar($flag = true) {
          }
      }

      Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

      The method getTraits has a boolean flag argument $autoload, which is a certain sign of a Single Responsibility Principle violation.
      Open

          public static function getTraits($class, $deep = true, $autoload = true)
      Severity: Minor
      Found in src/Common/Util/ClassUtils.php by phpmd

      BooleanArgumentFlag

      Since: 1.4.0

      A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

      Example

      class Foo {
          public function bar($flag = true) {
          }
      }

      Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

      Missing class import via use statement (line '32', column '23').
      Open

                  throw new \InvalidArgumentException(
      Severity: Minor
      Found in src/Identifiers/SlugIdentifier.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

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

          protected function __construct($string)
          {
              @trigger_error(sprintf('"%s" is deprecated.  Use "Gdbots\Pbj\WellKnown\StringIdentifier" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED);
      
              if (!is_string($string)) {
      Severity: Minor
      Found in src/Identifiers/StringIdentifier.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

      Missing class import via use statement (line '57', column '23').
      Open

                  throw new \UnexpectedValueException("Value '$value' is not part of the enum " . get_called_class());
      Severity: Minor
      Found in src/Common/Enum.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

      Missing class import via use statement (line '115', column '21').
      Open

              return (new \ReflectionClass($className))->getConstants();
      Severity: Minor
      Found in src/Common/Util/ClassUtils.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

      Missing class import via use statement (line '33', column '23').
      Open

                  throw new \InvalidArgumentException('String cannot be empty.');
      Severity: Minor
      Found in src/Identifiers/StringIdentifier.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

      Missing class import via use statement (line '157', column '19').
      Open

              throw new \BadMethodCallException("No static method or enum constant '$name' in class " . get_called_class());
      Severity: Minor
      Found in src/Common/Enum.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

      Severity
      Category
      Status
      Source
      Language