wikimedia/mediawiki-core

View on GitHub
maintenance/copyFileBackend.php

Summary

Maintainability
D
2 days
Test Coverage

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

    public function execute() {
        $backendGroup = $this->getServiceContainer()->getFileBackendGroup();
        $src = $backendGroup->get( $this->getOption( 'src' ) );
        $dst = $backendGroup->get( $this->getOption( 'dst' ) );
        $containers = explode( '|', $this->getOption( 'containers' ) );
Severity: Minor
Found in maintenance/copyFileBackend.php - About 1 day 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 execute has 93 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function execute() {
        $backendGroup = $this->getServiceContainer()->getFileBackendGroup();
        $src = $backendGroup->get( $this->getOption( 'src' ) );
        $dst = $backendGroup->get( $this->getOption( 'dst' ) );
        $containers = explode( '|', $this->getOption( 'containers' ) );
Severity: Major
Found in maintenance/copyFileBackend.php - About 3 hrs to fix

    Function copyFileBatch has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function copyFileBatch(
            array $srcPathsRel, $backendRel, FileBackend $src, FileBackend $dst
        ) {
            $ops = [];
            $fsFiles = [];
    Severity: Minor
    Found in maintenance/copyFileBackend.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 copyFileBatch has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function copyFileBatch(
            array $srcPathsRel, $backendRel, FileBackend $src, FileBackend $dst
        ) {
            $ops = [];
            $fsFiles = [];
    Severity: Major
    Found in maintenance/copyFileBackend.php - About 2 hrs to fix

      File copyFileBackend.php has 265 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      /**
       * Copy all files in some containers of one backend to another.
       *
       * This program is free software; you can redistribute it and/or modify
      Severity: Minor
      Found in maintenance/copyFileBackend.php - About 2 hrs to fix

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

            protected function filesAreSame( FileBackend $src, FileBackend $dst, $sPath, $dPath ) {
                $skipHash = $this->hasOption( 'skiphash' );
                $srcStat = $src->getFileStat( [ 'src' => $sPath ] );
                $dPathSha1 = sha1( $dPath );
                if ( $this->statCache !== null ) {
        Severity: Minor
        Found in maintenance/copyFileBackend.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 getListingDiffRel has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function getListingDiffRel( FileBackend $src, FileBackend $dst, $backendRel ) {
                $srcPathsRel = $src->getFileList( [
                    'dir' => $src->getRootStoragePath() . "/$backendRel" ] );
                if ( $srcPathsRel === null ) {
                    $this->fatalError( "Could not list files in source container." );
        Severity: Minor
        Found in maintenance/copyFileBackend.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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                if ( !$status->isOK() ) {
                    $this->error( Status::wrap( $status )->getMessage( false, false, 'en' )->text() );
                    $this->fatalError( "$domainId: Could not delete file batch." );
                } elseif ( count( $deletedRel ) ) {
                    $this->output( "\n\tDeleted these file(s) [{$elapsed_ms}ms]:\n\t" .
        Severity: Major
        Found in maintenance/copyFileBackend.php and 1 other location - About 1 hr to fix
        maintenance/copyFileBackend.php on lines 282..288

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 101.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                if ( !$status->isOK() ) {
                    $this->error( Status::wrap( $status )->getMessage( false, false, 'en' )->text() );
                    $this->fatalError( "$domainId: Could not copy file batch." );
                } elseif ( count( $copiedRel ) ) {
                    $this->output( "\n\tCopied these file(s) [{$elapsed_ms}ms]:\n\t" .
        Severity: Major
        Found in maintenance/copyFileBackend.php and 1 other location - About 1 hr to fix
        maintenance/copyFileBackend.php on lines 319..325

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 101.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        There are no issues that match your filters.

        Category
        Status