mambax7/publisher

View on GitHub
blocks/items_random_item.php

Summary

Maintainability
B
5 hrs
Test Coverage

Method publisher_items_random_item_show has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function publisher_items_random_item_show($options)
{
    $block = [];

    $helper = Helper::getInstance();
Severity: Major
Found in blocks/items_random_item.php - About 2 hrs to fix

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

    function publisher_items_random_item_show($options)
    {
        $block = [];
    
        $helper = Helper::getInstance();
    Severity: Minor
    Found in blocks/items_random_item.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

    Missing class import via use statement (line '119', column '25').
    Open

        $showSummary  = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_SUMMARY, 'options[0]', $options[0]);
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '125', column '25').
    Open

        $showComment  = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_COMMENT, 'options[6]', $options[6]);
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '120', column '25').
    Open

        $showImage    = new \XoopsFormRadioYN(_MB_PUBLISHER_IMGDISPLAY, 'options[1]', $options[1]);
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '127', column '25').
    Open

        $countItems   = new \XoopsFormText(_MB_PUBLISHER_RANDOM_ITEMS, 'options[8]', 10, 255, $options[8]);
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '124', column '25').
    Open

        $showHits     = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_READ, 'options[5]', $options[5]);
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '123', column '25').
    Open

        $showCategory = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_TOPICLINK, 'options[4]', $options[4]);
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '122', column '25').
    Open

        $showDate     = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_POSTTIME, 'options[3]', $options[3]);
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '126', column '25').
    Open

        $dispMoreEle  = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_READ_FULLITEM, 'options[7]', $options[7]);
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '121', column '25').
    Open

        $showPoster   = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_POSTEDBY, 'options[2]', $options[2]);
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    The method publisher_items_random_item_show uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    $item['comment'] = ' ' . $comments . ' ' . _MB_PUBLISHER_COMMENTS . ' ';
                }
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    Avoid using static access to class '\XoopsModules\Publisher\Helper' in method 'publisher_items_random_item_show'.
    Open

        $helper = Helper::getInstance();
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    The method publisher_items_random_item_show uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $item['comment'] = ' ' . _MB_PUBLISHER_NO_COMMENTS . ' ';
            }
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    The method publisher_items_random_item_show uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $item['item_image'] = $mainImage['image_path'];
            }
    Severity: Minor
    Found in blocks/items_random_item.php by phpmd

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

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

            if ($comments > 0) {
                //shows 1 comment instead of 1 comm. if comments ==1
                //langugage file modified accordingly
                if (1 == $comments) {
                    $item['comment'] = ' ' . _MB_PUBLISHER_ONECOMMENT . ' ';
    Severity: Major
    Found in blocks/items_random_item.php and 4 other locations - About 55 mins to fix
    blocks/items_new.php on lines 97..107
    blocks/items_recent.php on lines 102..112
    blocks/latest_news.php on lines 212..222
    item.php on lines 188..198

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

    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

    A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 33 and the first side effect is on line 25.
    Open

    <?php declare(strict_types=1);
    Severity: Minor
    Found in blocks/items_random_item.php by phpcodesniffer

    There are no issues that match your filters.

    Category
    Status