wikimedia/mediawiki-extensions-Wikibase

View on GitHub
repo/includes/Api/EntitySavingHelper.php

Summary

Maintainability
D
1 day
Test Coverage

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

    public function loadEntity( array $requestParams, ?EntityId $entityId = null, $assignFreshId = self::ASSIGN_FRESH_ID ): EntityDocument {
        if ( !in_array( $assignFreshId, [ self::ASSIGN_FRESH_ID, self::NO_FRESH_ID ] ) ) {
            throw new InvalidArgumentException(
                '$assignFreshId must be either of the EntitySavingHelper::ASSIGN_FRESH_ID/NO_FRESH_ID constants.'
            );
Severity: Minor
Found in repo/includes/Api/EntitySavingHelper.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

File EntitySavingHelper.php has 268 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare( strict_types = 1 );

namespace Wikibase\Repo\Api;
Severity: Minor
Found in repo/includes/Api/EntitySavingHelper.php - About 2 hrs to fix

    Method loadEntity has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function loadEntity( array $requestParams, ?EntityId $entityId = null, $assignFreshId = self::ASSIGN_FRESH_ID ): EntityDocument {
            if ( !in_array( $assignFreshId, [ self::ASSIGN_FRESH_ID, self::NO_FRESH_ID ] ) ) {
                throw new InvalidArgumentException(
                    '$assignFreshId must be either of the EntitySavingHelper::ASSIGN_FRESH_ID/NO_FRESH_ID constants.'
                );
    Severity: Major
    Found in repo/includes/Api/EntitySavingHelper.php - About 2 hrs to fix

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

          public function attemptSaveEntity(
              EntityDocument $entity,
              $summary,
              array $requestParams,
              IContextSource $context,
      Severity: Minor
      Found in repo/includes/Api/EntitySavingHelper.php - About 1 hr to fix

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

            private function createEntity( $entityType, EntityId $customId = null, $assignFreshId = self::ASSIGN_FRESH_ID ): EntityDocument {
                if ( $customId ) {
                    $entityType = $customId->getEntityType();
                } elseif ( !$entityType ) {
                    $this->errorReporter->dieError(
        Severity: Minor
        Found in repo/includes/Api/EntitySavingHelper.php - About 1 hr to fix

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

                  bool $isWriteMode,
                  $needsToken,
                  RevisionLookup $revisionLookup,
                  TitleFactory $titleFactory,
                  EntityIdParser $idParser,
          Severity: Major
          Found in repo/includes/Api/EntitySavingHelper.php - About 1 hr to fix

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

                private function createEntity( $entityType, EntityId $customId = null, $assignFreshId = self::ASSIGN_FRESH_ID ): EntityDocument {
                    if ( $customId ) {
                        $entityType = $customId->getEntityType();
                    } elseif ( !$entityType ) {
                        $this->errorReporter->dieError(
            Severity: Minor
            Found in repo/includes/Api/EntitySavingHelper.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

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

                    EntityDocument $entity,
                    $summary,
                    array $requestParams,
                    IContextSource $context,
                    int $flags = 0
            Severity: Minor
            Found in repo/includes/Api/EntitySavingHelper.php - About 35 mins to fix

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

                  public function attemptSaveEntity(
                      EntityDocument $entity,
                      $summary,
                      array $requestParams,
                      IContextSource $context,
              Severity: Minor
              Found in repo/includes/Api/EntitySavingHelper.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