gdbots/pbj-php

View on GitHub

Showing 77 of 77 total issues

Method xmlEscape has 70 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function xmlEscape(string $str): string
    {
        // array used to figure what number to decrement from character order value
        // according to number of characters used to map unicode to ascii by utf-8
        $decrement = [];
Severity: Major
Found in src/Util/StringUtil.php - About 2 hrs to fix

    Function buildSchema has a Cognitive Complexity of 19 (exceeds 5 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 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

    FieldBuilder has 23 functions (exceeds 20 allowed). Consider refactoring.
    Open

    final class FieldBuilder
    {
        private string $name;
        private Type $type;
        private ?FieldRule $rule = null;
    Severity: Minor
    Found in src/FieldBuilder.php - About 2 hrs to fix

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

              string    $name,
              Type      $type,
              FieldRule $rule,
              bool      $required = false,
              ?int      $minLength = null,
      Severity: Major
      Found in src/Field.php - About 2 hrs to fix

        Function validate has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            final public function validate(bool $strict = false, bool $recursive = false): static
            {
                if (!$strict && $this->isFrozen()) {
                    return $this;
                }
        Severity: Minor
        Found in src/AbstractMessage.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 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

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

                              public function decode(mixed $value, Field $field, ?Codec $codec = null): BigInteger|string|null
                              {
                                  if (null === $value || $value instanceof BigInteger) {
                                      return $value;
                                  }
                          Severity: Major
                          Found in src/Type/SignedBigIntType.php and 1 other location - About 1 hr to fix
                          src/Type/BigIntType.php on lines 40..51

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

                          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

                          Severity
                          Category
                          Status
                          Source
                          Language