wikimedia/mediawiki-core

View on GitHub
includes/block/BlockUser.php

Summary

Maintainability
F
3 days
Test Coverage

File BlockUser.php has 433 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
Severity: Minor
Found in includes/block/BlockUser.php - About 6 hrs to fix

    Method __construct has 59 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function __construct(
            ServiceOptions $options,
            BlockRestrictionStore $blockRestrictionStore,
            BlockPermissionCheckerFactory $blockPermissionCheckerFactory,
            BlockUtils $blockUtils,
    Severity: Major
    Found in includes/block/BlockUser.php - About 2 hrs to fix

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

              ServiceOptions $options,
              BlockRestrictionStore $blockRestrictionStore,
              BlockPermissionCheckerFactory $blockPermissionCheckerFactory,
              BlockUtils $blockUtils,
              BlockActionInfo $blockActionInfo,
      Severity: Major
      Found in includes/block/BlockUser.php - About 2 hrs to fix

        Function placeBlockUnsafe has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            public function placeBlockUnsafe( bool $reblock = false ): Status {
                $status = $this->blockUtils->validateTarget( $this->target );
        
                if ( !$status->isOK() ) {
                    $this->logger->debug( 'placeBlockUnsafe: invalid target' );
        Severity: Minor
        Found in includes/block/BlockUser.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 __construct has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            public function __construct(
                ServiceOptions $options,
                BlockRestrictionStore $blockRestrictionStore,
                BlockPermissionCheckerFactory $blockPermissionCheckerFactory,
                BlockUtils $blockUtils,
        Severity: Minor
        Found in includes/block/BlockUser.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 placeBlockInternal has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function placeBlockInternal( bool $reblock = true ): Status {
                $block = $this->configureBlock();
        
                $denyReason = [ 'hookaborted' ];
                $legacyUser = $this->userFactory->newFromAuthority( $this->performer );
        Severity: Major
        Found in includes/block/BlockUser.php - About 2 hrs to fix

          Method placeBlockUnsafe has 51 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function placeBlockUnsafe( bool $reblock = false ): Status {
                  $status = $this->blockUtils->validateTarget( $this->target );
          
                  if ( !$status->isOK() ) {
                      $this->logger->debug( 'placeBlockUnsafe: invalid target' );
          Severity: Major
          Found in includes/block/BlockUser.php - About 2 hrs to fix

            Method placeBlock has 49 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function placeBlock( bool $reblock = false ): Status {
                    $priorBlock = $this->blockStore
                        ->newFromTarget( $this->target, null, /*fromPrimary=*/true );
                    $priorHideUser = $priorBlock instanceof DatabaseBlock && $priorBlock->getHideName();
                    if (
            Severity: Minor
            Found in includes/block/BlockUser.php - About 1 hr to fix

              Function placeBlockInternal has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function placeBlockInternal( bool $reblock = true ): Status {
                      $block = $this->configureBlock();
              
                      $denyReason = [ 'hookaborted' ];
                      $legacyUser = $this->userFactory->newFromAuthority( $this->performer );
              Severity: Minor
              Found in includes/block/BlockUser.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 placeBlock has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function placeBlock( bool $reblock = false ): Status {
                      $priorBlock = $this->blockStore
                          ->newFromTarget( $this->target, null, /*fromPrimary=*/true );
                      $priorHideUser = $priorBlock instanceof DatabaseBlock && $priorBlock->getHideName();
                      if (
              Severity: Minor
              Found in includes/block/BlockUser.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 configureBlock has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function configureBlock( $sourceBlock = null ): DatabaseBlock {
                      if ( $sourceBlock === null ) {
                          $block = new DatabaseBlock();
                      } else {
                          $block = clone $sourceBlock;
              Severity: Minor
              Found in includes/block/BlockUser.php - About 1 hr to fix

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

                    private function constructLogParams(): array {
                        $logExpiry = wfIsInfinity( $this->rawExpiry ) ? 'infinity' : $this->rawExpiry;
                        $logParams = [
                            '5::duration' => $logExpiry,
                            '6::flags' => $this->blockLogFlags(),
                Severity: Minor
                Found in includes/block/BlockUser.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 blockLogFlags has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function blockLogFlags(): string {
                        $flags = [];
                
                        if ( $this->targetType != AbstractBlock::TYPE_USER && !$this->isHardBlock ) {
                            // For grepping: message block-log-flags-anononly
                Severity: Minor
                Found in includes/block/BlockUser.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 $this->placeBlockInternal( $reblock );
                Severity: Major
                Found in includes/block/BlockUser.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                  return Status::newFatal( 'ipb_hide_partial' );
                  Severity: Major
                  Found in includes/block/BlockUser.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return Status::newFatal( 'ipb_expiry_temp' );
                    Severity: Major
                    Found in includes/block/BlockUser.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return $this->placeBlockUnsafe( $reblock );
                      Severity: Major
                      Found in includes/block/BlockUser.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return Status::newFatal( 'ipb-empty-block' );
                        Severity: Major
                        Found in includes/block/BlockUser.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return Status::newGood( $block );
                          Severity: Major
                          Found in includes/block/BlockUser.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return Status::newFatal( 'ipb_hide_invalid', Message::numParam( $hideUserContribLimit ) );
                            Severity: Major
                            Found in includes/block/BlockUser.php - About 30 mins to fix

                              There are no issues that match your filters.

                              Category
                              Status