wikimedia/mediawiki-core

View on GitHub
includes/block/BlockManager.php

Summary

Maintainability
F
3 days
Test Coverage

File BlockManager.php has 463 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: Minor
Found in includes/block/BlockManager.php - About 7 hrs to fix

    BlockManager has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class BlockManager {
        /** @var UserFactory */
        private $userFactory;
    
        /** @var UserIdentityUtils */
    Severity: Minor
    Found in includes/block/BlockManager.php - About 3 hrs to fix

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

          private function inDnsBlacklist( $ip, array $bases ) {
              $found = false;
              // @todo FIXME: IPv6 ???  (https://bugs.php.net/bug.php?id=33170)
              if ( IPUtils::isIPv4( $ip ) ) {
                  // Reverse IP, T23255
      Severity: Minor
      Found in includes/block/BlockManager.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 filter has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          public function filter( ?Block $block, $callback ) {
              if ( !$block ) {
                  return null;
              } elseif ( $block instanceof CompositeBlock ) {
                  $blocks = $block->getOriginalBlocks();
      Severity: Minor
      Found in includes/block/BlockManager.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 trackBlockWithCookie has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          public function trackBlockWithCookie( User $user, WebResponse $response ) {
              $request = $user->getRequest();
      
              if ( $request->getCookie( 'BlockID' ) !== null ) {
                  $cookieBlock = $this->getBlockFromCookieValue( $user, $request );
      Severity: Minor
      Found in includes/block/BlockManager.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 inDnsBlacklist has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function inDnsBlacklist( $ip, array $bases ) {
              $found = false;
              // @todo FIXME: IPv6 ???  (https://bugs.php.net/bug.php?id=33170)
              if ( IPUtils::isIPv4( $ip ) ) {
                  // Reverse IP, T23255
      Severity: Minor
      Found in includes/block/BlockManager.php - About 1 hr to fix

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

            public function getBlock(
                UserIdentity $user,
                ?WebRequest $request,
                $fromReplica = true
            ): ?AbstractBlock {
        Severity: Minor
        Found in includes/block/BlockManager.php - About 1 hr to fix

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

              public function getCreateAccountBlock(
                  UserIdentity $user,
                  ?WebRequest $request,
                  $fromReplica
              ) {
          Severity: Minor
          Found in includes/block/BlockManager.php - About 1 hr to fix

            Method getSystemIpBlocks has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function getSystemIpBlocks( string $ip, bool $applySoftBlocks ): array {
                    $blocks = [];
            
                    // Proxy blocking
                    if ( !in_array( $ip, $this->options->get( MainConfigNames::ProxyWhitelist ) ) ) {
            Severity: Minor
            Found in includes/block/BlockManager.php - About 1 hr to fix

              Method trackBlockWithCookie has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function trackBlockWithCookie( User $user, WebResponse $response ) {
                      $request = $user->getRequest();
              
                      if ( $request->getCookie( 'BlockID' ) !== null ) {
                          $cookieBlock = $this->getBlockFromCookieValue( $user, $request );
              Severity: Minor
              Found in includes/block/BlockManager.php - About 1 hr to fix

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

                        ServiceOptions $options,
                        UserFactory $userFactory,
                        UserIdentityUtils $userIdentityUtils,
                        LoggerInterface $logger,
                        HookContainer $hookContainer,
                Severity: Major
                Found in includes/block/BlockManager.php - About 50 mins to fix

                  Function getUniqueBlocks has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private function getUniqueBlocks( array $blocks ) {
                          $systemBlocks = [];
                          $databaseBlocks = [];
                  
                          foreach ( $blocks as $block ) {
                  Severity: Minor
                  Found in includes/block/BlockManager.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 getBlocksForIPList has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function getBlocksForIPList( array $ipChain, bool $applySoftBlocks, bool $fromPrimary ) {
                          if ( $ipChain === [] ) {
                              return [];
                          }
                  
                  
                  Severity: Minor
                  Found in includes/block/BlockManager.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 getCreateAccountBlock has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function getCreateAccountBlock(
                          UserIdentity $user,
                          ?WebRequest $request,
                          $fromReplica
                      ) {
                  Severity: Minor
                  Found in includes/block/BlockManager.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

                  Avoid too many return statements within this method.
                  Open

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

                    Avoid too many return statements within this method.
                    Open

                                return $block;
                    Severity: Major
                    Found in includes/block/BlockManager.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return $block->withOriginalBlocks( array_values( $blocks ) );
                      Severity: Major
                      Found in includes/block/BlockManager.php - About 30 mins to fix

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

                            private function getSystemIpBlocks( string $ip, bool $applySoftBlocks ): array {
                                $blocks = [];
                        
                                // Proxy blocking
                                if ( !in_array( $ip, $this->options->get( MainConfigNames::ProxyWhitelist ) ) ) {
                        Severity: Minor
                        Found in includes/block/BlockManager.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