gdbots/pbjc-php

View on GitHub
src/Generator/PhpGenerator.php

Summary

Maintainability
D
1 day
Test Coverage

Method generateMessage has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function generateMessage(SchemaDescriptor $schema, GeneratorResponse $response)
    {
        $className = $this->schemaToClassName($schema, true);
        $psr = $this->schemaToNativeNamespace($schema);
        $file = str_replace('\\', '/', "{$psr}\\{$className}");
Severity: Minor
Found in src/Generator/PhpGenerator.php - About 1 hr to fix

    Function updateFieldOptions has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function updateFieldOptions(SchemaDescriptor $schema, FieldDescriptor $field)
        {
            if ($enum = $field->getEnum()) {
                if (null === $field->getLanguage(static::LANGUAGE)->get('default', null)) {
                    $default = $field->getDefault();
    Severity: Minor
    Found in src/Generator/PhpGenerator.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 extractImportsFromFields has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function extractImportsFromFields(array $fields)
        {
            $imports = [];
    
            foreach ($fields as $field) {
    Severity: Minor
    Found in src/Generator/PhpGenerator.php - About 1 hr to fix

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

          protected function extractImportsFromFields(array $fields)
          {
              $imports = [];
      
              foreach ($fields as $field) {
      Severity: Minor
      Found in src/Generator/PhpGenerator.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 using static access to class '\Gdbots\Common\Util\StringUtils' in method 'schemaToNativePackage'.
      Open

              $vendor = StringUtils::toCamelFromSlug($id->getVendor());
      Severity: Minor
      Found in src/Generator/PhpGenerator.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\Gdbots\Common\Util\StringUtils' in method 'enumToNativePackage'.
      Open

              $vendor = StringUtils::toCamelFromSlug($id->getVendor());
      Severity: Minor
      Found in src/Generator/PhpGenerator.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\Gdbots\Common\Util\StringUtils' in method 'schemaToNativeNamespace'.
      Open

                  $message = StringUtils::toCamelFromSlug($id->getMessage());
      Severity: Minor
      Found in src/Generator/PhpGenerator.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\Gdbots\Common\Util\StringUtils' in method 'enumToNativeNamespace'.
      Open

              $package = StringUtils::toCamelFromSlug(str_replace('.', '-', $id->getPackage()));
      Severity: Minor
      Found in src/Generator/PhpGenerator.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid assigning values to variables in if clauses and the like (line '301', column '13').
      Open

          protected function updateFieldOptions(SchemaDescriptor $schema, FieldDescriptor $field)
          {
              if ($enum = $field->getEnum()) {
                  if (null === $field->getLanguage(static::LANGUAGE)->get('default', null)) {
                      $default = $field->getDefault();
      Severity: Minor
      Found in src/Generator/PhpGenerator.php by phpmd

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

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

      Avoid using static access to class '\Gdbots\Common\Util\StringUtils' in method 'schemaToNativeNamespace'.
      Open

              $package = StringUtils::toCamelFromSlug(str_replace('.', '-', $id->getPackage()));
      Severity: Minor
      Found in src/Generator/PhpGenerator.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class '\Gdbots\Common\Util\StringUtils' in method 'schemaToNativeNamespace'.
      Open

                  $category = StringUtils::toCamelFromSlug($id->getCategory());
      Severity: Minor
      Found in src/Generator/PhpGenerator.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          protected function updateFieldOptions(SchemaDescriptor $schema, FieldDescriptor $field)
          {
              if ($enum = $field->getEnum()) {
                  if (null === $field->getLanguage(static::LANGUAGE)->get('default', null)) {
                      $default = $field->getDefault();
      Severity: Major
      Found in src/Generator/PhpGenerator.php and 1 other location - About 7 hrs to fix
      src/Generator/JsGenerator.php on lines 241..265

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 233.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          protected function generateMixinInterface(SchemaDescriptor $schema, GeneratorResponse $response)
          {
              $className = $this->schemaToClassName($schema);
              $psr = $this->schemaToNativeNamespace($schema);
              $file = str_replace('\\', '/', "{$psr}\\{$className}");
      Severity: Minor
      Found in src/Generator/PhpGenerator.php and 1 other location - About 45 mins to fix
      src/Generator/PhpGenerator.php on lines 156..164

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 95.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          protected function generateMessageInterface(SchemaDescriptor $schema, GeneratorResponse $response)
          {
              $className = $this->schemaToClassName($schema);
              $psr = $this->schemaToNativeNamespace($schema);
              $file = str_replace('\\', '/', "{$psr}\\{$className}");
      Severity: Minor
      Found in src/Generator/PhpGenerator.php and 1 other location - About 45 mins to fix
      src/Generator/PhpGenerator.php on lines 197..205

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 95.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

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

              $ns = $this->enumToNativePackage($enum);
      Severity: Minor
      Found in src/Generator/PhpGenerator.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 $ns. Configured minimum length is 3.
      Open

              $ns = parent::enumToNativePackage($enum);
      Severity: Minor
      Found in src/Generator/PhpGenerator.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 $id. Configured minimum length is 3.
      Open

              $id = $schema->getId();
      Severity: Minor
      Found in src/Generator/PhpGenerator.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 $ns. Configured minimum length is 3.
      Open

              $ns = $this->schemaToNativePackage($schema);
      Severity: Minor
      Found in src/Generator/PhpGenerator.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 $id. Configured minimum length is 3.
      Open

              $id = $enum->getId();
      Severity: Minor
      Found in src/Generator/PhpGenerator.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 $id. Configured minimum length is 3.
      Open

              $id = $enum->getId();
      Severity: Minor
      Found in src/Generator/PhpGenerator.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 $ns. Configured minimum length is 3.
      Open

              $ns = parent::schemaToNativePackage($schema);
      Severity: Minor
      Found in src/Generator/PhpGenerator.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 $id. Configured minimum length is 3.
      Open

              $id = $schema->getId();
      Severity: Minor
      Found in src/Generator/PhpGenerator.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

      CASE statements must be defined using a colon
      Open

                      case TypeName::STRING_ENUM;

      CASE statements must be defined using a colon
      Open

                      case TypeName::INT_ENUM;

      CASE statements must be defined using a colon
      Open

                      case TypeName::MESSAGE;

      There are no issues that match your filters.

      Category
      Status