gdbots/pbjc-php

View on GitHub

Showing 579 of 579 total issues

Method getFieldDescriptor has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function getFieldDescriptor(SchemaId $schemaId, array $field)
    {
        // force default type to be "string"
        if (!isset($field['type'])) {
            $field['type'] = 'string';
Severity: Minor
Found in src/SchemaParser.php - About 2 hrs to fix

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

        public static function loadFile($file, $schemaOrCallable = null)
        {
            $content = @file_get_contents($file);
            if ('' === trim($content)) {
                throw new \InvalidArgumentException(sprintf('File %s does not contain valid XML, it is empty.', $file));
    Severity: Minor
    Found in src/Util/XmlUtils.php - About 1 hr to fix

      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

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

            protected function generateMessage(SchemaDescriptor $schema, GeneratorResponse $response)
            {
                $id = $schema->getId();
                $className = $this->schemaToClassName($schema, true);
                $file = "{$id->getVendor()}/{$id->getPackage()}";
        Severity: Minor
        Found in src/Generator/JsGenerator.php - About 1 hr to fix

          Method getSchemas has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getSchemas()
              {
                  return [
                      [
                          'data' => __DIR__ . '/Fixtures/json-schema/article.json',
          Severity: Minor
          Found in tests/JsonValidatorTest.php - About 1 hr to fix

            Method convertDomElementToArray has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function convertDomElementToArray(\DomElement $element, $checkPrefix = true)
                {
                    $prefix = (string)$element->prefix;
                    $empty = true;
                    $config = [];
            Severity: Minor
            Found in src/Util/XmlUtils.php - About 1 hr to fix

              Method execute has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function execute(InputInterface $input, OutputInterface $output)
                  {
                      $io = new SymfonyStyle($input, $output);
              
                      $file = $input->getOption('config') ?: sprintf('%s/pbjc.yml', getcwd());
              Severity: Minor
              Found in src/Command/CompileCommand.php - About 1 hr to fix

                Method fromFile has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function fromFile($file)
                    {
                        /** @var \DOMDocument $xmlDomDocument */
                        if (!$xmlDomDocument = XmlUtils::loadFile($file, __DIR__ . '/../xsd/enums.xsd')) {
                            throw new \RuntimeException(sprintf(
                Severity: Minor
                Found in src/EnumParser.php - About 1 hr to fix

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

                      private function getFieldDescriptor(SchemaId $schemaId, array $field)
                      {
                          // force default type to be "string"
                          if (!isset($field['type'])) {
                              $field['type'] = 'string';
                  Severity: Minor
                  Found in src/SchemaParser.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 __construct has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function __construct($id, array $parameters = [])
                      {
                          $this->id = $id instanceof SchemaId ? $id : SchemaId::fromString($id);
                  
                          foreach ($parameters as $key => $value) {
                  Severity: Minor
                  Found in src/SchemaDescriptor.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 run has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function run($language, CompileOptions $options)
                      {
                          $namespaces = $options->getNamespaces();
                  
                          if (!$namespaces || count($namespaces) === 0) {
                  Severity: Minor
                  Found in src/Compiler.php - About 1 hr to fix

                    Method setUp has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function setUp()
                        {
                            SchemaStore::addSchema(
                                SchemaId::fromString('pbj:vendor2:package2:category2:message2:1-0-0'),
                                new SchemaDescriptor(
                    Severity: Minor
                    Found in tests/SchemaDescriptorTest.php - About 1 hr to fix

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

                          private function getLanguageOptions(array $data)
                          {
                              $options = new LanguageBag();
                      
                              foreach ($data as $key => $value) {
                      Severity: Major
                      Found in src/EnumParser.php and 1 other location - About 1 hr to fix
                      src/SchemaParser.php on lines 233..250

                      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 111.

                      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

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

                          private function getLanguageOptions(array $data)
                          {
                              $options = new LanguageBag();
                      
                              foreach ($data as $key => $value) {
                      Severity: Major
                      Found in src/SchemaParser.php and 1 other location - About 1 hr to fix
                      src/EnumParser.php on lines 149..166

                      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 111.

                      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

                      The class FieldDescriptor has 20 fields. Consider redesigning FieldDescriptor to keep the number of fields under 15.
                      Open

                      final class FieldDescriptor
                      {
                          /**
                           * Regular expression pattern for matching a valid field name.  The pattern allows
                           * for camelCase fields name but snake_case is recommend.
                      Severity: Minor
                      Found in src/FieldDescriptor.php by phpmd

                      TooManyFields

                      Since: 0.1

                      Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

                      Example

                      class Person {
                         protected $one;
                         private $two;
                         private $three;
                         [... many more fields ...]
                      }

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

                      Method validate has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function validate(SchemaDescriptor $a, SchemaDescriptor $b)
                          {
                              $fa = array_merge($a->getInheritedFields(), $a->getFields());
                              $fb = array_merge($b->getInheritedFields(), $b->getFields());
                      
                      
                      Severity: Minor
                      Found in src/Validator/FieldAttributeEqualTo.php - About 1 hr to fix

                        Method render has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            protected function render($template, array $parameters)
                            {
                                return str_replace(
                                    [
                                        '    ',
                        Severity: Minor
                        Found in src/Generator/JsonSchemaGenerator.php - About 1 hr to fix

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

                              public function fromFile($file)
                              {
                                  /** @var \DOMDocument $xmlDomDocument */
                                  if (!$xmlDomDocument = XmlUtils::loadFile($file, __DIR__ . '/../xsd/enums.xsd')) {
                                      throw new \RuntimeException(sprintf(
                          Severity: Minor
                          Found in src/EnumParser.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 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

                          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/JsGenerator.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

                          Severity
                          Category
                          Status
                          Source
                          Language