wikimedia/mediawiki-core

View on GitHub
includes/utils/ZipDirectoryReader.php

Summary

Maintainability
D
2 days
Test Coverage

File ZipDirectoryReader.php has 388 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * ZIP file directories reader, for the purposes of upload verification.
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Minor
Found in includes/utils/ZipDirectoryReader.php - About 5 hrs to fix

    Method readCentralDirectory has 70 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function readCentralDirectory( $offset, $size ) {
            $block = $this->getBlock( $offset, $size );
    
            $fixedInfo = [
                'signature' => [ 'string', 4 ],
    Severity: Major
    Found in includes/utils/ZipDirectoryReader.php - About 2 hrs to fix

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

          private function readCentralDirectory( $offset, $size ) {
              $block = $this->getBlock( $offset, $size );
      
              $fixedInfo = [
                  'signature' => [ 'string', 4 ],
      Severity: Minor
      Found in includes/utils/ZipDirectoryReader.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 readEndOfCentralDirectoryRecord has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function readEndOfCentralDirectoryRecord() {
              $info = [
                  'signature' => 4,
                  'disk' => 2,
                  'CD start disk' => 2,
      Severity: Minor
      Found in includes/utils/ZipDirectoryReader.php - About 1 hr to fix

        Function unpack has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            private function unpack( $string, $struct, $offset = 0 ) {
                $size = $this->getStructSize( $struct );
                if ( $offset + $size > strlen( $string ) ) {
                    $this->error( 'zip-bad', 'unpack() would run past the end of the supplied string' );
                }
        Severity: Minor
        Found in includes/utils/ZipDirectoryReader.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 unpack has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function unpack( $string, $struct, $offset = 0 ) {
                $size = $this->getStructSize( $struct );
                if ( $offset + $size > strlen( $string ) ) {
                    $this->error( 'zip-bad', 'unpack() would run past the end of the supplied string' );
                }
        Severity: Minor
        Found in includes/utils/ZipDirectoryReader.php - About 1 hr to fix

          Method readZip64EndOfCentralDirectoryRecord has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function readZip64EndOfCentralDirectoryRecord() {
                  if ( $this->eocdr64Locator['eocdr64 start disk'] != 0
                      || $this->eocdr64Locator['number of disks'] != 0
                  ) {
                      $this->error( 'zip-unsupported', 'more than one disk (in EOCDR64 locator)' );
          Severity: Minor
          Found in includes/utils/ZipDirectoryReader.php - About 1 hr to fix

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

                private function execute() {
                    $this->data = [];
                    if ( !$this->file ) {
                        return Status::newFatal( 'zip-file-open-error' );
                    }
            Severity: Minor
            Found in includes/utils/ZipDirectoryReader.php - About 1 hr to fix

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

                  private function getBlock( $start, $length = null ) {
                      $fileLength = $this->getFileLength();
                      if ( $start >= $fileLength ) {
                          $this->error( 'zip-bad', "getBlock() requested position $start, " .
                              "file length is $fileLength" );
              Severity: Minor
              Found in includes/utils/ZipDirectoryReader.php - About 1 hr to fix

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

                    private function findZip64CentralDirectory() {
                        // The spec is ambiguous about the exact rules of precedence between the
                        // ZIP64 headers and the original headers. Here we follow zip_util.c
                        // from OpenJDK 7.
                        $size = $this->eocdr['CD size'];
                Severity: Minor
                Found in includes/utils/ZipDirectoryReader.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 getSegment has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function getSegment( $segIndex ) {
                        if ( !isset( $this->buffer[$segIndex] ) ) {
                            $bytePos = $segIndex * self::SEGSIZE;
                            if ( $bytePos >= $this->getFileLength() ) {
                                $this->buffer[$segIndex] = '';
                Severity: Minor
                Found in includes/utils/ZipDirectoryReader.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

                Function execute has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function execute() {
                        $this->data = [];
                        if ( !$this->file ) {
                            return Status::newFatal( 'zip-file-open-error' );
                        }
                Severity: Minor
                Found in includes/utils/ZipDirectoryReader.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

                Function readEndOfCentralDirectoryRecord has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function readEndOfCentralDirectoryRecord() {
                        $info = [
                            'signature' => 4,
                            'disk' => 2,
                            'CD start disk' => 2,
                Severity: Minor
                Found in includes/utils/ZipDirectoryReader.php - About 25 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