gboudreau/Greyhole

View on GitHub
web-app/views/trash.php

Summary

Maintainability
D
2 days
Test Coverage

File trash.php has 304 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/*
Copyright 2020 Guillaume Boudreau

This file is part of Greyhole.
Severity: Minor
Found in web-app/views/trash.php - About 3 hrs to fix

    Function xcopy has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    function xcopy($src,$dest) {
        // recursive copy
        if (!is_dir($dest)) {
            mkdir($dest);
        }
    Severity: Minor
    Found in web-app/views/trash.php - About 2 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

    Function getSambaShares has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    function getSambaShares() {
        exec("/usr/bin/testparm -sl 2>/dev/null | grep '\[' | grep -vi '\[global]'", $output);
        $all_samba_shares = [];
        foreach ($output as $line) {
            if (preg_match('/\s*\[(.+)]\s*$/', $line, $re)) {
    Severity: Minor
    Found in web-app/views/trash.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 rrmdir has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    function rrmdir($dir) {
        // recursive remove directory
        if (is_dir($dir)) {
            $objects = scandir($dir);
            foreach ($objects as $object) {
    Severity: Minor
    Found in web-app/views/trash.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

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

        foreach ($output as $line) {
            if (preg_match('/\s*\[(.+)]\s*$/', $line, $re)) {
                $share_name = $re[1];
                if (array_contains(ConfigHelper::$trash_share_names, $share_name)) {
                    $share_options = SharesConfig::getConfigForShare(CONFIG_TRASH_SHARE);
    Severity: Major
    Found in web-app/views/trash.php and 1 other location - About 6 hrs to fix
    web-app/views/samba_shares.php on lines 46..65

    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 215.

    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 ($confirm != "Yes") {
                echo "<h2 class=\"mt-8\">Removing ".$ext."</h2>\n";
                if (is_dir($ext)) {
                    echo "Are you sure you want to recursively destroy all copies of this directory, and the files within it?<br />\n";
                } else {
    Severity: Major
    Found in web-app/views/trash.php and 1 other location - About 3 hrs to fix
    web-app/views/trash.php on lines 172..255

    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 155.

    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 ($confirm != "Yes") {
                echo "<h2 class=\"mt-8\">Restoring ".$ext."</h2>\n";
                if (is_dir($ext)) {
                    echo "A directory already exists in the share with this name. Any files within with the same name will be overwritten with the copy from the trash.<br />Would you like to continue?<br />\n";
                } else {
    Severity: Major
    Found in web-app/views/trash.php and 1 other location - About 3 hrs to fix
    web-app/views/trash.php on lines 102..159

    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 155.

    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