luyadev/luya-module-cms

View on GitHub
src/admin/helpers/MenuHelper.php

Summary

Maintainability
C
1 day
Test Coverage
C
78%

Function getItems has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

    public static function getItems()
    {
        if (self::$items === null) {
            $items = Nav::find()
                ->select(['cms_nav.id', 'nav_item_id' => 'cms_nav_item.id', 'nav_container_id', 'parent_nav_id', 'is_hidden', 'layout_file', 'is_offline', 'is_draft', 'is_home', 'cms_nav_item.title'])
Severity: Minor
Found in src/admin/helpers/MenuHelper.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 getItems has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function getItems()
    {
        if (self::$items === null) {
            $items = Nav::find()
                ->select(['cms_nav.id', 'nav_item_id' => 'cms_nav_item.id', 'nav_container_id', 'parent_nav_id', 'is_hidden', 'layout_file', 'is_offline', 'is_draft', 'is_home', 'cms_nav_item.title'])
Severity: Minor
Found in src/admin/helpers/MenuHelper.php - About 1 hr to fix

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

        private static function loadInheritanceData($parentNavId = 0, $fromInheritNode = false)
        {
            // get items from singleton object
            $items = self::getNavItems()[$parentNavId] ?? [];
            foreach ($items as $item) {
    Severity: Minor
    Found in src/admin/helpers/MenuHelper.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 checkUserWebsitePermissions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function checkUserWebsitePermissions(array $website)
        {
            /** @var User $user */
            $user = Yii::$app->adminuser->identity;
            $userGroupIds = ArrayHelper::getColumn($user->groups, 'id');
    Severity: Minor
    Found in src/admin/helpers/MenuHelper.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 navGroupInheritanceNode has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function navGroupInheritanceNode($navId, Group $group)
        {
            // default defintion is false
            $definition = false;
            // see if permission data for group exists, foreach items and set if match
    Severity: Minor
    Found in src/admin/helpers/MenuHelper.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 getWebsites has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function getWebsites()
        {
            if (self::$websites === null) {
                $websites = (new Query())
                    ->select([
    Severity: Minor
    Found in src/admin/helpers/MenuHelper.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