wikimedia/mediawiki-core

View on GitHub
includes/json/JsonCodec.php

Summary

Maintainability
D
1 day
Test Coverage

Function detectNonSerializableDataInternal has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    private function detectNonSerializableDataInternal(
        $value,
        bool $expectDeserialize,
        string $accumulatedPath,
        bool $exhaustive = false
Severity: Minor
Found in includes/json/JsonCodec.php - About 3 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

Function serializeOne has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    private function serializeOne( &$value ) {
        if ( $value instanceof JsonSerializable ) {
            $value = $value->jsonSerialize();
            if ( !is_array( $value ) ) {
                // Although JsonSerializable doesn't /require/ the result to be
Severity: Minor
Found in includes/json/JsonCodec.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

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

    public function deserialize( $json, string $expectedClass = null ) {
        Assert::parameterType( [ 'stdClass', 'array', 'string' ], $json, '$json' );
        Assert::precondition(
            !$expectedClass || is_subclass_of( $expectedClass, JsonDeserializable::class ),
            '$expectedClass parameter must be subclass of JsonDeserializable, got ' . $expectedClass
Severity: Minor
Found in includes/json/JsonCodec.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 deserialize has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function deserialize( $json, string $expectedClass = null ) {
        Assert::parameterType( [ 'stdClass', 'array', 'string' ], $json, '$json' );
        Assert::precondition(
            !$expectedClass || is_subclass_of( $expectedClass, JsonDeserializable::class ),
            '$expectedClass parameter must be subclass of JsonDeserializable, got ' . $expectedClass
Severity: Minor
Found in includes/json/JsonCodec.php - About 1 hr to fix

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

        private function detectNonSerializableDataInternal(
            $value,
            bool $expectDeserialize,
            string $accumulatedPath,
            bool $exhaustive = false
    Severity: Minor
    Found in includes/json/JsonCodec.php - About 1 hr to fix

      Method serializeOne has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function serializeOne( &$value ) {
              if ( $value instanceof JsonSerializable ) {
                  $value = $value->jsonSerialize();
                  if ( !is_array( $value ) ) {
                      // Although JsonSerializable doesn't /require/ the result to be
      Severity: Minor
      Found in includes/json/JsonCodec.php - About 1 hr to fix

        Avoid too many return statements within this method.
        Open

                return null;
        Severity: Major
        Found in includes/json/JsonCodec.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                              return $propValueNonSerializablePath;
          Severity: Major
          Found in includes/json/JsonCodec.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return $accumulatedPath . ': nonscalar ' . get_debug_type( $value );
            Severity: Major
            Found in includes/json/JsonCodec.php - About 30 mins to fix

              Function deserializeArray has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function deserializeArray( array $array ): array {
                      $deserializedExtensionData = [];
                      foreach ( $array as $key => $value ) {
                          if ( $key === JsonConstants::COMPLEX_ANNOTATION ) {
                              /* don't include this in the result */
              Severity: Minor
              Found in includes/json/JsonCodec.php - About 25 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

              There are no issues that match your filters.

              Category
              Status