wikimedia/mediawiki-core

View on GitHub
includes/Permissions/RestrictionStore.php

Summary

Maintainability
D
2 days
Test Coverage

File RestrictionStore.php has 387 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace MediaWiki\Permissions;

use DBAccessObjectUtils;
Severity: Minor
Found in includes/Permissions/RestrictionStore.php - About 5 hrs to fix

    Function loadRestrictions has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        public function loadRestrictions(
            PageIdentity $page, int $flags = IDBAccessObject::READ_NORMAL
        ): void {
            $page->assertWiki( PageIdentity::LOCAL );
    
    
    Severity: Minor
    Found in includes/Permissions/RestrictionStore.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 getCascadeProtectionSourcesInternal has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        private function getCascadeProtectionSourcesInternal(
            PageIdentity $page, bool $shortCircuit = false
        ) {
            if ( !$page->canExist() ) {
                return $shortCircuit ? false : [ [], [] ];
    Severity: Minor
    Found in includes/Permissions/RestrictionStore.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 loadRestrictions has 65 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function loadRestrictions(
            PageIdentity $page, int $flags = IDBAccessObject::READ_NORMAL
        ): void {
            $page->assertWiki( PageIdentity::LOCAL );
    
    
    Severity: Major
    Found in includes/Permissions/RestrictionStore.php - About 2 hrs to fix

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

          private function getCascadeProtectionSourcesInternal(
              PageIdentity $page, bool $shortCircuit = false
          ) {
              if ( !$page->canExist() ) {
                  return $shortCircuit ? false : [ [], [] ];
      Severity: Major
      Found in includes/Permissions/RestrictionStore.php - About 2 hrs to fix

        Function loadRestrictionsFromRows has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            public function loadRestrictionsFromRows(
                PageIdentity $page, array $rows
            ): void {
                $page->assertWiki( PageIdentity::LOCAL );
        
        
        Severity: Minor
        Found in includes/Permissions/RestrictionStore.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 getCreateProtectionInternal has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function getCreateProtectionInternal( PageIdentity $page ): ?array {
                // Can't protect pages in special namespaces
                if ( !$page->canExist() ) {
                    return null;
                }
        Severity: Minor
        Found in includes/Permissions/RestrictionStore.php - About 1 hr to fix

          Method loadRestrictionsFromRows has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function loadRestrictionsFromRows(
                  PageIdentity $page, array $rows
              ): void {
                  $page->assertWiki( PageIdentity::LOCAL );
          
          
          Severity: Minor
          Found in includes/Permissions/RestrictionStore.php - About 1 hr to fix

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

                    ServiceOptions $options,
                    WANObjectCache $wanCache,
                    ILoadBalancer $loadBalancer,
                    LinkCache $linkCache,
                    LinksMigration $linksMigration,
            Severity: Major
            Found in includes/Permissions/RestrictionStore.php - About 1 hr to fix

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

                  public function isProtected( PageIdentity $page, string $action = '' ): bool {
                      $page->assertWiki( PageIdentity::LOCAL );
              
                      // Special pages have inherent protection (TODO: remove after switch to ProperPageIdentity)
                      if ( $page->getNamespace() === NS_SPECIAL ) {
              Severity: Minor
              Found in includes/Permissions/RestrictionStore.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 getCreateProtectionInternal has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function getCreateProtectionInternal( PageIdentity $page ): ?array {
                      // Can't protect pages in special namespaces
                      if ( !$page->canExist() ) {
                          return null;
                      }
              Severity: Minor
              Found in includes/Permissions/RestrictionStore.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 [ $sources, $pageRestrictions ];
              Severity: Major
              Found in includes/Permissions/RestrictionStore.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

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

                  Avoid too many return statements within this method.
                  Open

                          return (bool)array_diff(
                              array_intersect(
                                  $this->getRestrictions( $page, $action ),
                                  $this->options->get( MainConfigNames::RestrictionLevels )
                              ),
                  Severity: Major
                  Found in includes/Permissions/RestrictionStore.php - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status