wikimedia/mediawiki-core

View on GitHub
includes/cache/LinkCache.php

Summary

Maintainability
D
2 days
Test Coverage

File LinkCache.php has 330 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Page existence cache.
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Minor
Found in includes/cache/LinkCache.php - About 3 hrs to fix

    Method getGoodLinkRowInternal has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function getGoodLinkRowInternal(
            TitleValue $link,
            callable $fetchCallback = null,
            int $queryFlags = IDBAccessObject::READ_NORMAL
        ): array {
    Severity: Minor
    Found in includes/cache/LinkCache.php - About 1 hr to fix

      Method getCacheKey has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function getCacheKey( $page, $passThrough = false ) {
              if ( is_string( $page ) ) {
                  if ( $passThrough ) {
                      return $page;
                  } else {
      Severity: Minor
      Found in includes/cache/LinkCache.php - About 1 hr to fix

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

            private function getGoodLinkRowInternal(
                TitleValue $link,
                callable $fetchCallback = null,
                int $queryFlags = IDBAccessObject::READ_NORMAL
            ): array {
        Severity: Minor
        Found in includes/cache/LinkCache.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 getGoodLinkFieldObj has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getGoodLinkFieldObj( $page, string $field ) {
                $key = $this->getCacheKey( $page );
                if ( $key === null ) {
                    return null;
                }
        Severity: Minor
        Found in includes/cache/LinkCache.php - About 1 hr to fix

          Function getCacheKey has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              private function getCacheKey( $page, $passThrough = false ) {
                  if ( is_string( $page ) ) {
                      if ( $passThrough ) {
                          return $page;
                      } else {
          Severity: Minor
          Found in includes/cache/LinkCache.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 getGoodLinkRow has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getGoodLinkRow(
                  int $ns,
                  string $dbkey,
                  callable $fetchCallback = null,
                  int $queryFlags = IDBAccessObject::READ_NORMAL
          Severity: Minor
          Found in includes/cache/LinkCache.php - About 1 hr to fix

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

                public function getGoodLinkRow(
                    int $ns,
                    string $dbkey,
                    callable $fetchCallback = null,
                    int $queryFlags = IDBAccessObject::READ_NORMAL
            Severity: Minor
            Found in includes/cache/LinkCache.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/cache/LinkCache.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                              return (int)$row->page_len;
              Severity: Major
              Found in includes/cache/LinkCache.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return $this->titleFormatter->getPrefixedDBkey( $page );
                Severity: Major
                Found in includes/cache/LinkCache.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return [ $callerShouldAddGoodLink, $row ?: null ];
                  Severity: Major
                  Found in includes/cache/LinkCache.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return (int)$row->page_latest;
                    Severity: Major
                    Found in includes/cache/LinkCache.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return !empty( $row->page_content_model )
                                          ? (string)$row->page_content_model
                                          : null;
                      Severity: Major
                      Found in includes/cache/LinkCache.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return (int)$row->page_is_redirect;
                        Severity: Major
                        Found in includes/cache/LinkCache.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return !empty( $row->page_lang )
                                              ? (string)$row->page_lang
                                              : null;
                          Severity: Major
                          Found in includes/cache/LinkCache.php - About 30 mins to fix

                            There are no issues that match your filters.

                            Category
                            Status