gdbots/common-php

View on GitHub

Showing 137 of 137 total issues

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

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

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

    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

    Missing class import via use statement (line '26', 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

    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

    Avoid too many return statements within this method.
    Open

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

      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 isValidTimestamp has a boolean flag argument $allowNegative, which is a certain sign of a Single Responsibility Principle violation.
      Open

          public static function isValidTimestamp($timestamp, $allowNegative = false)
      Severity: Minor
      Found in src/Common/Util/DateUtils.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 '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

      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

      Avoid too many return statements within this method.
      Open

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

        Missing class import via use statement (line '54', column '30').
        Open

                $date = $date ?: new \DateTime();

        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 '37', column '23').
        Open

                    throw new \InvalidArgumentException('Longitude must be within range [-180.0, 180.0]');
        Severity: Minor
        Found in src/Common/GeoPoint.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

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

            public static function isValid($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

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

                    throw new \InvalidArgumentException(
        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

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

            public function __construct($number, $scale = null)
            {
                @trigger_error(sprintf('"%s" is deprecated.  Use "Gdbots\Pbj\WellKnown\BigNumber" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED);
                parent::__construct($number, $scale);
            }
        Severity: Minor
        Found in src/Common/BigNumber.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 '65', column '19').
        Open

                throw new \InvalidArgumentException('Payload must be a GeoJson "Point" type.');
        Severity: Minor
        Found in src/Common/GeoPoint.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