wikimedia/mediawiki-core

View on GitHub
includes/page/MovePage.php

Summary

Maintainability
F
5 days
Test Coverage

File MovePage.php has 655 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
Severity: Major
Found in includes/page/MovePage.php - About 1 day to fix

    Method moveToInternal has 135 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function moveToInternal(
            UserIdentity $user,
            &$nt,
            $reason = '',
            $createRedirect = true,
    Severity: Major
    Found in includes/page/MovePage.php - About 5 hrs to fix

      Method moveUnsafe has 108 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function moveUnsafe( UserIdentity $user, $reason, $createRedirect, array $changeTags ) {
              $status = Status::newGood();
      
              // TODO: make hooks accept UserIdentity
              $userObj = $this->userFactory->newFromUserIdentity( $user );
      Severity: Major
      Found in includes/page/MovePage.php - About 4 hrs to fix

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

                Title $oldTitle,
                Title $newTitle,
                ServiceOptions $options,
                IConnectionProvider $dbProvider,
                NamespaceInfo $nsInfo,
        Severity: Major
        Found in includes/page/MovePage.php - About 2 hrs to fix

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

              public function isValidMove() {
                  $status = new Status();
          
                  if ( $this->oldTitle->equals( $this->newTitle ) ) {
                      $status->fatal( 'selfmove' );
          Severity: Minor
          Found in includes/page/MovePage.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 moveSubpagesInternal has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              private function moveSubpagesInternal( callable $subpageMoveCallback ) {
                  // Do the source and target namespaces support subpages?
                  if ( !$this->nsInfo->hasSubpages( $this->oldTitle->getNamespace() ) ) {
                      return Status::newFatal( 'namespace-nosubpages',
                          $this->nsInfo->getCanonicalName( $this->oldTitle->getNamespace() ) );
          Severity: Minor
          Found in includes/page/MovePage.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 isValidMove has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function isValidMove() {
                  $status = new Status();
          
                  if ( $this->oldTitle->equals( $this->newTitle ) ) {
                      $status->fatal( 'selfmove' );
          Severity: Major
          Found in includes/page/MovePage.php - About 2 hrs to fix

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

                private function moveToInternal(
                    UserIdentity $user,
                    &$nt,
                    $reason = '',
                    $createRedirect = true,
            Severity: Minor
            Found in includes/page/MovePage.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 moveSubpagesInternal has 47 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function moveSubpagesInternal( callable $subpageMoveCallback ) {
                    // Do the source and target namespaces support subpages?
                    if ( !$this->nsInfo->hasSubpages( $this->oldTitle->getNamespace() ) ) {
                        return Status::newFatal( 'namespace-nosubpages',
                            $this->nsInfo->getCanonicalName( $this->oldTitle->getNamespace() ) );
            Severity: Minor
            Found in includes/page/MovePage.php - About 1 hr to fix

              Method isValidMoveTarget has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function isValidMoveTarget() {
                      # Is it an existing file?
                      if ( $this->newTitle->inNamespace( NS_FILE ) ) {
                          $file = $this->repoGroup->getLocalRepo()->newFile( $this->newTitle );
                          $file->load( IDBAccessObject::READ_LATEST );
              Severity: Minor
              Found in includes/page/MovePage.php - About 1 hr to fix

                Function isValidFileMove has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function isValidFileMove() {
                        $status = new Status();
                
                        if ( !$this->newTitle->inNamespace( NS_FILE ) ) {
                            // No need for further errors about the target filename being wrong
                Severity: Minor
                Found in includes/page/MovePage.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 moveUnsafe has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function moveUnsafe( UserIdentity $user, $reason, $createRedirect, array $changeTags ) {
                        $status = Status::newGood();
                
                        // TODO: make hooks accept UserIdentity
                        $userObj = $this->userFactory->newFromUserIdentity( $user );
                Severity: Minor
                Found in includes/page/MovePage.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 isValidMoveTarget has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function isValidMoveTarget() {
                        # Is it an existing file?
                        if ( $this->newTitle->inNamespace( NS_FILE ) ) {
                            $file = $this->repoGroup->getLocalRepo()->newFile( $this->newTitle );
                            $file->load( IDBAccessObject::READ_LATEST );
                Severity: Minor
                Found in includes/page/MovePage.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 isValidFileMove has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function isValidFileMove() {
                        $status = new Status();
                
                        if ( !$this->newTitle->inNamespace( NS_FILE ) ) {
                            // No need for further errors about the target filename being wrong
                Severity: Minor
                Found in includes/page/MovePage.php - About 1 hr to fix

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

                          UserIdentity $user,
                          &$nt,
                          $reason = '',
                          $createRedirect = true,
                          array $changeTags = []
                  Severity: Minor
                  Found in includes/page/MovePage.php - About 35 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return false;
                    Severity: Major
                    Found in includes/page/MovePage.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return true;
                      Severity: Major
                      Found in includes/page/MovePage.php - About 30 mins to fix

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

                            public function __construct(
                                Title $oldTitle,
                                Title $newTitle,
                                ServiceOptions $options,
                                IConnectionProvider $dbProvider,
                        Severity: Major
                        Found in includes/page/MovePage.php and 1 other location - About 2 hrs to fix
                        includes/actions/InfoAction.php on lines 80..117

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

                        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

                        There are no issues that match your filters.

                        Category
                        Status