wikimedia/mediawiki-core

View on GitHub
includes/export/XmlDumpWriter.php

Summary

Maintainability
F
3 days
Test Coverage

File XmlDumpWriter.php has 453 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * XmlDumpWriter
 *
 * Copyright © 2003, 2005, 2006 Brooke Vibber <bvibber@wikimedia.org>
Severity: Minor
Found in includes/export/XmlDumpWriter.php - About 6 hrs to fix

    Function writeSlot has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        private function writeSlot( SlotRecord $slot, $contentMode ) {
            $isMain = $slot->getRole() === SlotRecord::MAIN;
            $isV11 = $this->schemaVersion >= XML_DUMP_SCHEMA_VERSION_11;
    
            if ( !$isV11 && !$isMain ) {
    Severity: Minor
    Found in includes/export/XmlDumpWriter.php - About 3 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 writeSlot has 81 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function writeSlot( SlotRecord $slot, $contentMode ) {
            $isMain = $slot->getRole() === SlotRecord::MAIN;
            $isV11 = $this->schemaVersion >= XML_DUMP_SCHEMA_VERSION_11;
    
            if ( !$isV11 && !$isMain ) {
    Severity: Major
    Found in includes/export/XmlDumpWriter.php - About 3 hrs to fix

      Method writeRevision has 68 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function writeRevision( $row, $slotRows = null ) {
              $rev = $this->getRevisionStore()->newRevisionFromRowAndSlots(
                  $row,
                  $slotRows,
                  0,
      Severity: Major
      Found in includes/export/XmlDumpWriter.php - About 2 hrs to fix

        XmlDumpWriter has 24 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class XmlDumpWriter {
        
            /** Output serialized revision content. */
            public const WRITE_CONTENT = 0;
        
        
        Severity: Minor
        Found in includes/export/XmlDumpWriter.php - About 2 hrs to fix

          Function writeRevision has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              public function writeRevision( $row, $slotRows = null ) {
                  $rev = $this->getRevisionStore()->newRevisionFromRowAndSlots(
                      $row,
                      $slotRows,
                      0,
          Severity: Minor
          Found in includes/export/XmlDumpWriter.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 writeUpload has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function writeUpload( $file, $dumpContents = false ) {
                  if ( $file->isOld() ) {
                      /** @var OldLocalFile $file */
                      '@phan-var OldLocalFile $file';
                      $archiveName = "      " .
          Severity: Minor
          Found in includes/export/XmlDumpWriter.php - About 1 hr to fix

            Method writeLogItem has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function writeLogItem( $row ) {
                    $out = "  <logitem>\n";
                    $out .= "    " . Xml::element( 'id', null, strval( $row->log_id ) ) . "\n";
            
                    $out .= $this->writeTimestamp( $row->log_timestamp, "    " );
            Severity: Minor
            Found in includes/export/XmlDumpWriter.php - About 1 hr to fix

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

                  private function writeUpload( $file, $dumpContents = false ) {
                      if ( $file->isOld() ) {
                          /** @var OldLocalFile $file */
                          '@phan-var OldLocalFile $file';
                          $archiveName = "      " .
              Severity: Minor
              Found in includes/export/XmlDumpWriter.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 writeLogItem has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function writeLogItem( $row ) {
                      $out = "  <logitem>\n";
                      $out .= "    " . Xml::element( 'id', null, strval( $row->log_id ) ) . "\n";
              
                      $out .= $this->writeTimestamp( $row->log_timestamp, "    " );
              Severity: Minor
              Found in includes/export/XmlDumpWriter.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 writeUploads has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function writeUploads( $row, $dumpContents = false ) {
                      if ( $row->page_namespace == NS_FILE ) {
                          $img = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
                              ->newFile( $row->page_title );
                          if ( $img && $img->exists() ) {
              Severity: Minor
              Found in includes/export/XmlDumpWriter.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 $out;
              Severity: Major
              Found in includes/export/XmlDumpWriter.php - About 30 mins to fix

                There are no issues that match your filters.

                Category
                Status