gdbots/pbj-php

View on GitHub

Showing 77 of 77 total issues

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/BigIntType.php and 1 other location - About 1 hr to fix
src/Type/SignedBigIntType.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

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

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

            if ($this->skipValidation()) {
                if ($field->isASingleValue()) {
                    $message->setWithoutValidation($fieldName, $type->decode($value, $field, $this));
                } else {
                    $message->setWithoutValidation($fieldName, array_map(function ($v) use ($type, $field) {
Severity: Minor
Found in src/Serializer/PhpArraySerializer.php and 1 other location - About 45 mins to fix
src/Marshaler/Elastica/DocumentMarshaler.php on lines 180..189

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

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

            if ($this->skipValidation()) {
                if ($field->isASingleValue()) {
                    $message->setWithoutValidation($fieldName, $type->decode($value, $field, $this));
                } else {
                    $message->setWithoutValidation($fieldName, array_map(function ($v) use ($type, $field) {
Severity: Minor
Found in src/Marshaler/Elastica/DocumentMarshaler.php and 1 other location - About 45 mins to fix
src/Serializer/PhpArraySerializer.php on lines 186..195

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

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

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

          public function __construct($message, $code, string $propertyPath = null, $value = null, array $constraints = [])
      Severity: Minor
      Found in src/Exception/AssertionFailed.php - About 35 mins to fix

        Function isValid has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function isValid(string $hashtag): bool
            {
                $hashtag = ltrim($hashtag, '#');
                if (empty($hashtag)) {
                    return false;
        Severity: Minor
        Found in src/Util/HashtagUtil.php - About 35 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 doMarshal has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            private function doMarshal(Message $message): array
            {
                $schema = $message::schema();
                $message->validate();
                $payload = [];
        Severity: Minor
        Found in src/Marshaler/Elastica/DocumentMarshaler.php - About 35 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 getSupportedMessages has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function getSupportedMessages(Field $field): array
            {
                if (!$field->hasAnyOfCuries()) {
                    return MessageResolver::all();
                }
        Severity: Minor
        Found in src/Marshaler/Elastica/MappingBuilder.php - About 35 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 applyNumericOptions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            private function applyNumericOptions(?int $min = null, ?int $max = null, int $precision = 10, int $scale = 2): void
            {
                if (null !== $max) {
                    $this->max = $max;
                }
        Severity: Minor
        Found in src/Field.php - About 35 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 doSerialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            private function doSerialize(Message $message): array
            {
                $schema = $message::schema();
                $message->validate();
                $payload = [];
        Severity: Minor
        Found in src/Serializer/PhpArraySerializer.php - About 35 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 too many return statements within this method.
        Open

                return true;
        Severity: Major
        Found in src/Field.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return $properties;
          Severity: Major
          Found in src/Marshaler/Elastica/MappingBuilder.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                                return [self::TYPE_BINARY => $value];
            Severity: Major
            Found in src/Marshaler/DynamoDb/ItemMarshaler.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                              return true;
              Severity: Major
              Found in src/Util/HashtagUtil.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return $this->default;
                Severity: Major
                Found in src/Field.php - About 30 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language