wikimedia/mediawiki-core

View on GitHub
includes/jobqueue/JobQueueDB.php

Summary

Maintainability
F
4 days
Test Coverage

File JobQueueDB.php has 640 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: Major
Found in includes/jobqueue/JobQueueDB.php - About 1 day to fix

    JobQueueDB has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class JobQueueDB extends JobQueue {
        /* seconds to cache info without re-validating */
        private const CACHE_TTL_SHORT = 30;
        /* seconds a job can live once claimed */
        private const MAX_AGE_PRUNE = 7 * 24 * 3600;
    Severity: Minor
    Found in includes/jobqueue/JobQueueDB.php - About 4 hrs to fix

      Method recycleAndDeleteStaleJobs has 78 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function recycleAndDeleteStaleJobs() {
              $now = time();
              $count = 0; // affected rows
              $dbw = $this->getPrimaryDB();
              /** @noinspection PhpUnusedLocalVariableInspection */
      Severity: Major
      Found in includes/jobqueue/JobQueueDB.php - About 3 hrs to fix

        Method claimRandom has 65 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function claimRandom( $uuid, $rand, $gte ) {
                $dbw = $this->getPrimaryDB();
                /** @noinspection PhpUnusedLocalVariableInspection */
                $scope = $this->getScopedNoTrxFlag( $dbw );
                // Check cache to see if the queue has <= OFFSET items
        Severity: Major
        Found in includes/jobqueue/JobQueueDB.php - About 2 hrs to fix

          Method doBatchPushInternal has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function doBatchPushInternal( IDatabase $dbw, array $jobs, $flags, $method ) {
                  if ( $jobs === [] ) {
                      return;
                  }
          
          
          Severity: Minor
          Found in includes/jobqueue/JobQueueDB.php - About 2 hrs to fix

            Method claimOldest has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function claimOldest( $uuid ) {
                    $dbw = $this->getPrimaryDB();
                    /** @noinspection PhpUnusedLocalVariableInspection */
                    $scope = $this->getScopedNoTrxFlag( $dbw );
            
            
            Severity: Minor
            Found in includes/jobqueue/JobQueueDB.php - About 1 hr to fix

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

                  public function doBatchPushInternal( IDatabase $dbw, array $jobs, $flags, $method ) {
                      if ( $jobs === [] ) {
                          return;
                      }
              
              
              Severity: Minor
              Found in includes/jobqueue/JobQueueDB.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 claimRandom has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function claimRandom( $uuid, $rand, $gte ) {
                      $dbw = $this->getPrimaryDB();
                      /** @noinspection PhpUnusedLocalVariableInspection */
                      $scope = $this->getScopedNoTrxFlag( $dbw );
                      // Check cache to see if the queue has <= OFFSET items
              Severity: Minor
              Found in includes/jobqueue/JobQueueDB.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 getDB has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function getDB( $index ) {
                      if ( $this->server ) {
                          if ( $this->conn instanceof IDatabase ) {
                              return $this->conn;
                          } elseif ( $this->conn instanceof DBError ) {
              Severity: Minor
              Found in includes/jobqueue/JobQueueDB.php - About 1 hr to fix

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

                    protected function getDB( $index ) {
                        if ( $this->server ) {
                            if ( $this->conn instanceof IDatabase ) {
                                return $this->conn;
                            } elseif ( $this->conn instanceof DBError ) {
                Severity: Minor
                Found in includes/jobqueue/JobQueueDB.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 doPop has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function doPop() {
                        $dbw = $this->getPrimaryDB();
                        /** @noinspection PhpUnusedLocalVariableInspection */
                        $scope = $this->getScopedNoTrxFlag( $dbw );
                
                
                Severity: Minor
                Found in includes/jobqueue/JobQueueDB.php - About 1 hr to fix

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

                      protected function doGetAbandonedCount() {
                          if ( $this->claimTTL <= 0 ) {
                              return 0; // no acknowledgements
                          }
                  
                  
                  Severity: Minor
                  Found in includes/jobqueue/JobQueueDB.php - About 1 hr to fix

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

                        protected function doPop() {
                            $dbw = $this->getPrimaryDB();
                            /** @noinspection PhpUnusedLocalVariableInspection */
                            $scope = $this->getScopedNoTrxFlag( $dbw );
                    
                    
                    Severity: Minor
                    Found in includes/jobqueue/JobQueueDB.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 recycleAndDeleteStaleJobs has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function recycleAndDeleteStaleJobs() {
                            $now = time();
                            $count = 0; // affected rows
                            $dbw = $this->getPrimaryDB();
                            /** @noinspection PhpUnusedLocalVariableInspection */
                    Severity: Minor
                    Found in includes/jobqueue/JobQueueDB.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

                    There are no issues that match your filters.

                    Category
                    Status