wikimedia/mediawiki-core

View on GitHub
includes/Category/Category.php

Summary

Maintainability
D
1 day
Test Coverage

File Category.php has 336 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Representation for a category.
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Minor
Found in includes/Category/Category.php - About 4 hrs to fix

    Method refreshCounts has 101 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function refreshCounts() {
            if ( $this->readOnlyMode->isReadOnly() ) {
                return false;
            }
    
    
    Severity: Major
    Found in includes/Category/Category.php - About 4 hrs to fix

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

          protected function initialize( $mode = self::LOAD_ONLY ) {
              if ( $this->mName === null && $this->mID === null ) {
                  throw new RuntimeException( __METHOD__ . ' has both names and IDs null' );
              } elseif ( $this->mID === null ) {
                  $where = [ 'cat_title' => $this->mName ];
      Severity: Minor
      Found in includes/Category/Category.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 initialize has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function initialize( $mode = self::LOAD_ONLY ) {
              if ( $this->mName === null && $this->mID === null ) {
                  throw new RuntimeException( __METHOD__ . ' has both names and IDs null' );
              } elseif ( $this->mID === null ) {
                  $where = [ 'cat_title' => $this->mName ];
      Severity: Major
      Found in includes/Category/Category.php - About 2 hrs to fix

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

            public function refreshCountsIfSmall( $maxSize = self::ROW_COUNT_SMALL ) {
                $dbw = $this->dbProvider->getPrimaryDatabase();
                $dbw->startAtomic( __METHOD__ );
        
                $typeOccurances = $dbw->newSelectQueryBuilder()
        Severity: Minor
        Found in includes/Category/Category.php - About 1 hr to fix

          Function refreshCounts has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public function refreshCounts() {
                  if ( $this->readOnlyMode->isReadOnly() ) {
                      return false;
                  }
          
          
          Severity: Minor
          Found in includes/Category/Category.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 newFromRow has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function newFromRow( stdClass $row, ?PageIdentity $page = null ) {
                  $cat = new self();
                  $cat->mPage = $page;
          
                  # NOTE: the row often results from a LEFT JOIN on categorylinks. This may result in
          Severity: Minor
          Found in includes/Category/Category.php - About 1 hr to fix

            There are no issues that match your filters.

            Category
            Status