keboola/php-utils

View on GitHub

Showing 61 of 61 total issues

Function getDataFromPath has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

function getDataFromPath($path, $data, $separator = "/", $ignoreEmpty = true)
{
    if (isset($path) && $path !== $separator) {
        // TODO possibly add functions in the $path? Such as path/to/join(data) would do a join on that data..likely belongs to EX/(sub)Parser/TR
        $str = explode($separator, $path);
Severity: Minor
Found in src/Keboola/Utils/getDataFromPath.php - About 2 hrs 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

Method jsonDecode has 49 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function jsonDecode($json, $assoc = false, $depth = 512, $options = 0, $logJson = false, $lint = false)
{
    $data = json_decode($json, $assoc, $depth, $options);
    switch (json_last_error()) {
        case JSON_ERROR_NONE:
Severity: Minor
Found in src/Keboola/Utils/jsonDecode.php - About 1 hr to fix

    Function buildUrl has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    function buildUrl($url, array $query = null)
    {
        if (!empty($query)) {
            // Cleanup the input array to prevent empty Keys
            foreach ($query as $k => $v) {
    Severity: Minor
    Found in src/Keboola/Utils/buildUrl.php - About 1 hr 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 jsonDecode has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    function jsonDecode($json, $assoc = false, $depth = 512, $options = 0, $logJson = false, $lint = false)
    {
        $data = json_decode($json, $assoc, $depth, $options);
        switch (json_last_error()) {
            case JSON_ERROR_NONE:
    Severity: Minor
    Found in src/Keboola/Utils/jsonDecode.php - About 1 hr 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

    Method buildUrl has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function buildUrl($url, array $query = null)
    {
        if (!empty($query)) {
            // Cleanup the input array to prevent empty Keys
            foreach ($query as $k => $v) {
    Severity: Minor
    Found in src/Keboola/Utils/buildUrl.php - About 1 hr to fix

      Function castToBool has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      function castToBool($castToBool): bool
      {
          if (is_string($castToBool)) {
              if ($castToBool === '1') {
                  return true;
      Severity: Minor
      Found in src/Keboola/Utils/castToBool.php - About 55 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 isEmptyObject has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      function isEmptyObject(\stdClass $object)
      {
          $vars = get_object_vars($object);
          if ($vars == []) {
              return true;
      Severity: Minor
      Found in src/Keboola/Utils/isEmptyObject.php - About 55 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

      Avoid variables with short names like $e. Configured minimum length is 3.
      Open

          $e = new Exception\JsonDecodeException("JSON decode error: {$error}");
      Severity: Minor
      Found in src/Keboola/Utils/jsonDecode.php by phpmd

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#shortvariable

      Avoid variables with short names like $s. Configured minimum length is 3.
      Open

      function toAscii($s)
      Severity: Minor
      Found in src/Keboola/Utils/toAscii.php by phpmd

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#shortvariable

      The parameter $parse_url is not named in camelCase.
      Open

      function httpBuildUrl(array $parse_url)
      {
          // Skip if the URL is relative
          if (!empty($parse_url["scheme"]) && !empty($parse_url["host"])) {
              // scheme - e.g. http
      Severity: Minor
      Found in src/Keboola/Utils/httpBuildUrl.php by phpmd

      CamelCaseParameterName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name parameters.

      Example

      class ClassName {
          public function doSomething($user_name) {
          }
      }

      Source

      Avoid variables with short names like $s. Configured minimum length is 3.
      Open

      function sanitizeColumnName($s, $charlist = '_', $lower = false)

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#shortvariable

      Method jsonDecode has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      function jsonDecode($json, $assoc = false, $depth = 512, $options = 0, $logJson = false, $lint = false)
      Severity: Minor
      Found in src/Keboola/Utils/jsonDecode.php - About 45 mins to fix

        Avoid too many return statements within this method.
        Open

            return false;
        Severity: Major
        Found in src/Keboola/Utils/castToBool.php - About 30 mins to fix

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

          function sanitizeColumnName($s, $charlist = '_', $lower = false)

          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 '62', column '25').
          Open

                  $jsonLint = new \Seld\JsonLint\JsonParser;
          Severity: Minor
          Found in src/Keboola/Utils/jsonDecode.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 '21', column '17').
          Open

                      new \DateTimeZone($timezone)

          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 '13', column '31').
          Open

              $dtzObj = $timezone ? new \DateTimeZone($timezone) : null;
          Severity: Minor
          Found in src/Keboola/Utils/formatDateTime.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 getDataFromPath has a boolean flag argument $ignoreEmpty, which is a certain sign of a Single Responsibility Principle violation.
          Open

          function getDataFromPath($path, $data, $separator = "/", $ignoreEmpty = true)
          Severity: Minor
          Found in src/Keboola/Utils/getDataFromPath.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 jsonDecode has a boolean flag argument $assoc, which is a certain sign of a Single Responsibility Principle violation.
          Open

          function jsonDecode($json, $assoc = false, $depth = 512, $options = 0, $logJson = false, $lint = false)
          Severity: Minor
          Found in src/Keboola/Utils/jsonDecode.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 jsonDecode has a boolean flag argument $lint, which is a certain sign of a Single Responsibility Principle violation.
          Open

          function jsonDecode($json, $assoc = false, $depth = 512, $options = 0, $logJson = false, $lint = false)
          Severity: Minor
          Found in src/Keboola/Utils/jsonDecode.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

          Severity
          Category
          Status
          Source
          Language