gdbots/pbj-php

View on GitHub

Showing 68 of 77 total issues

Method doDeserialize has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function doDeserialize(array $data): Message
    {
        $schemaId = SchemaId::fromString((string)$data[Schema::PBJ_FIELD_NAME]);
        $className = MessageResolver::resolveId($schemaId);
        $message = new $className();
Severity: Major
Found in src/Serializer/PhpArraySerializer.php - About 2 hrs to fix

    Method doUnmarshal has 56 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function doUnmarshal(array $data): Message
        {
            $schemaId = SchemaId::fromString((string)$data[Schema::PBJ_FIELD_NAME]);
            $className = MessageResolver::resolveId($schemaId);
            $message = new $className();
    Severity: Major
    Found in src/Marshaler/Elastica/DocumentMarshaler.php - About 2 hrs to fix

      MappingBuilder has 21 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class MappingBuilder
      {
          /**
           * Generally we use "__" to indicate a derived field but kibana won't recognize it.
           * So for now, we'll use "d__" to indicate a derived field for ES.
      Severity: Minor
      Found in src/Marshaler/Elastica/MappingBuilder.php - About 2 hrs to fix

        Schema has 21 functions (exceeds 20 allowed). Consider refactoring.
        Open

        final class Schema implements \JsonSerializable
        {
            const PBJ_FIELD_NAME = '_schema';
        
            private string $className;
        Severity: Minor
        Found in src/Schema.php - About 2 hrs to fix

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

              public function guard(mixed $value, Field $field): void
              {
                  $fieldName = $field->getName();
                  Assertion::string($value, null, $fieldName);
          
          
          Severity: Minor
          Found in src/Type/AbstractStringType.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

          Consider simplifying this complex logical expression.
          Open

                      } else if (($c >= 8219 && $c <= 8223) || $c == 8242 || $c == 8243 || $c == 8216 || $c == 8217 || $c == 168 || $c == 180 || $c == 729 || $c == 733) {
                          //all the strange curly single and double quotes
                          // Ignore them
                      } else if ($c == 188) {
                          $slug .= '-one-quarter-';
          Severity: Critical
          Found in src/Util/SlugUtil.php - About 2 hrs to fix

            Function applyDefault has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                private function applyDefault($default = null): void
                {
                    $this->default = $default;
            
                    if ($this->type->isScalar()) {
            Severity: Minor
            Found in src/Field.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 buildSchema has 47 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function buildSchema(Schema $schema): array
                {
                    $properties = [];
            
                    if ($this->getPathDepth() > static::MAX_PATH_DEPTH) {
            Severity: Minor
            Found in src/Marshaler/Elastica/MappingBuilder.php - About 1 hr to fix

              Function encodeValue has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function encodeValue(mixed $value, Field $field): array
                  {
                      $type = $field->getType();
              
                      if ($type->encodesToScalar()) {
              Severity: Minor
              Found in src/Marshaler/DynamoDb/ItemMarshaler.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 marshal has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function marshal(Message $message): array
                  {
                      $schema = $message::schema();
                      $message->validate();
                      $payload = [];
              Severity: Minor
              Found in src/Marshaler/DynamoDb/ItemMarshaler.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 getNestedMessages has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function getNestedMessages(): array
                  {
                      $messages = [];
                      foreach (static::schema()->getFields() as $field) {
                          if ($field->getType()->isMessage()) {
              Severity: Minor
              Found in src/AbstractMessage.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 marshal has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function marshal(Message $message): array
                  {
                      $schema = $message::schema();
                      $message->validate();
                      $payload = [];
              Severity: Minor
              Found in src/Marshaler/DynamoDb/ItemMarshaler.php - About 1 hr to fix

                Method create has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

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

                  Method applyDefault has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function applyDefault($default = null): void
                      {
                          $this->default = $default;
                  
                          if ($this->type->isScalar()) {
                  Severity: Minor
                  Found in src/Field.php - About 1 hr to fix

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

                        public function getDefault(?Message $message = null): mixed
                        {
                            if (null === $this->default) {
                                if ($this->useTypeDefault) {
                                    return $this->isASingleValue() ? $this->type->getDefault() : [];
                    Severity: Minor
                    Found in src/Field.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 varToString has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function varToString($var): string
                        {
                            if (is_object($var)) {
                                return sprintf('Object(%s)', get_class($var));
                            }
                    Severity: Minor
                    Found in src/Util/StringUtil.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(string $str, bool $camelize = true): ?string
                        {
                            // remove special chars (accents, etc.)
                            $str = trim(self::normalize($str));
                            $str = ltrim($str, '#_ ');
                    Severity: Minor
                    Found in src/Util/HashtagUtil.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 encodeASetValue has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function encodeASetValue(array $value, Field $field): array
                        {
                            $type = $field->getType();
                    
                            if ($type->isString()) {
                    Severity: Minor
                    Found in src/Marshaler/DynamoDb/ItemMarshaler.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/Util/SlugUtil.php - About 40 mins to fix

                      Method __construct has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          private function __construct(string $vendor, string $package, string $category, string $message, string $version)
                      Severity: Minor
                      Found in src/SchemaId.php - About 35 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language