kai-jacobsen/kontentblocks

View on GitHub
core/Backend/Dynamic/GlobalModulesMenu.php

Summary

Maintainability
F
3 days
Test Coverage

postTypeMessages accesses the super-global variable $_GET.
Open

    public function postTypeMessages($messages)
    {
        $post = get_post();

        $messages['kb-gmd'] = array(

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

auth accesses the super-global variable $_POST.
Open

    private function auth($postId)
    {
        // verify if this is an auto save routine.
        // If it is our form has not been submitted, so we dont want to do anything
        if (empty($_POST)) {

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

globalModule accesses the super-global variable $_GET.
Open

    protected function globalModule($gmodule)
    {
        global $post;
        if (empty($gmodule)) {
            wp_die('no template arg provided');

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

globalModule accesses the super-global variable $_GET.
Open

    protected function globalModule($gmodule)
    {
        global $post;
        if (empty($gmodule)) {
            wp_die('no template arg provided');

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

postTypeMessages accesses the super-global variable $_GET.
Open

    public function postTypeMessages($messages)
    {
        $post = get_post();

        $messages['kb-gmd'] = array(

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

File GlobalModulesMenu.php has 347 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Kontentblocks\Backend\Dynamic;

use Kontentblocks\Backend\Environment\PostEnvironment;
Severity: Minor
Found in core/Backend/Dynamic/GlobalModulesMenu.php - About 4 hrs to fix

    The class GlobalModulesMenu has an overall complexity of 52 which is very high. The configured complexity threshold is 50.
    Open

    class GlobalModulesMenu
    {
    
    
        /**

    Method createGlobalModule has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function createGlobalModule($postId, \WP_Post $post, PostEnvironment $environment)
        {
    
            $value = Utilities::getRequest();
    
    
    Severity: Minor
    Found in core/Backend/Dynamic/GlobalModulesMenu.php - About 1 hr to fix

      Method registerPostType has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function registerPostType()
          {
      
              $labels = array(
                  'name' => _x('Global Module', 'post type general name', 'Kontentblocks'),
      Severity: Minor
      Found in core/Backend/Dynamic/GlobalModulesMenu.php - About 1 hr to fix

        Method globalModule has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function globalModule($gmodule)
            {
                global $post;
                if (empty($gmodule)) {
                    wp_die('no template arg provided');
        Severity: Minor
        Found in core/Backend/Dynamic/GlobalModulesMenu.php - About 1 hr to fix

          Method save has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function save($postId, \WP_Post $postObj)
              {
                  // auth request
                  if (!$this->auth($postId)) {
                      return false;
          Severity: Minor
          Found in core/Backend/Dynamic/GlobalModulesMenu.php - About 1 hr to fix

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

                private function auth($postId)
                {
                    // verify if this is an auto save routine.
                    // If it is our form has not been submitted, so we dont want to do anything
                    if (empty($_POST)) {
            Severity: Minor
            Found in core/Backend/Dynamic/GlobalModulesMenu.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 save has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function save($postId, \WP_Post $postObj)
                {
                    // auth request
                    if (!$this->auth($postId)) {
                        return false;
            Severity: Minor
            Found in core/Backend/Dynamic/GlobalModulesMenu.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

            Avoid too many return statements within this method.
            Open

                        return false;
            Severity: Major
            Found in core/Backend/Dynamic/GlobalModulesMenu.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return true;
              Severity: Major
              Found in core/Backend/Dynamic/GlobalModulesMenu.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return false;
                Severity: Major
                Found in core/Backend/Dynamic/GlobalModulesMenu.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return $data;
                  Severity: Major
                  Found in core/Backend/Dynamic/GlobalModulesMenu.php - About 30 mins to fix

                    Avoid using static access to class '\Kontentblocks\Utils\Utilities' in method 'createGlobalModule'.
                    Open

                            $value = Utilities::getRequest();

                    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

                    Avoid using static access to class '\Kontentblocks\Utils\Utilities' in method 'auth'.
                    Open

                            if (get_post_type($postId) == 'revision' && !Utilities::isPreview()) {

                    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 save uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                    Open

                            } else {
                                if (!wp_verify_nonce($value->request->filter('_nonce', '', FILTER_SANITIZE_STRING), 'update-gmodule')) {
                                    wp_die('Nonce verification failed');
                                }
                                // update existing

                    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 '\Kontentblocks\Utils\Utilities' in method 'addAdminMenu'.
                    Open

                            if (!Utilities::adminMenuExists('Kontentblocks')) {

                    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

                    Avoid using static access to class '\Kontentblocks\Utils\Utilities' in method 'save'.
                    Open

                            $value = Utilities::getRequest();

                    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

                    Avoid using static access to class '\Kontentblocks\Language\I18n' in method 'addAdminMenu'.
                    Open

                            $i18n = I18n::getPackage('Modules');

                    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

                    Avoid using static access to class '\Kontentblocks\Language\I18n' in method 'createForm'.
                    Open

                                'strings' => I18n::getPackages('Common', 'Modules')

                    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

                    Avoid using static access to class '\Kontentblocks\Language\I18n' in method 'globalModule'.
                    Open

                                'strings' => I18n::getPackages('Common', 'Menus')

                    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

                    Avoid using static access to class '\Kontentblocks\Utils\Utilities' in method 'save'.
                    Open

                            $environment = Utilities::getPostEnvironment($postId);

                    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

                    Avoid using static access to class '\Kontentblocks\Utils\Utilities' in method 'postData'.
                    Open

                            $request = Utilities::getRequest();

                    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

                    Avoid using static access to class '\Kontentblocks\Utils\Utilities' in method 'globalModule'.
                    Open

                            Utilities::hiddenEditor();

                    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

                    Avoid using static access to class '\Kontentblocks\Language\I18n' in method 'globalModule'.
                    Open

                                    'i18n' => I18n::getPackages('Common', 'Menus'),

                    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

                    Avoid using static access to class '\Kontentblocks\Backend\EditScreens\ScreenManager' in method 'globalModule'.
                    Open

                                'contexts' => ScreenManager::getDefaultContextLayout(),

                    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

                    Avoid using static access to class '\Kontentblocks\Utils\Utilities' in method 'save'.
                    Open

                                $toSave = Utilities::arrayMergeRecursive($new, $old);

                    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

                    Avoid using static access to class '\Kontentblocks\Utils\Utilities' in method 'globalModule'.
                    Open

                            $environment = Utilities::getPostEnvironment($post->ID);

                    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

                    Avoid using static access to class '\Kontentblocks\Utils\Utilities' in method 'createForm'.
                    Open

                            $request = Utilities::getRequest();

                    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

                    Avoid using static access to class '\Kontentblocks\Kontentblocks' in method 'getGloballyAllowed'.
                    Open

                            $registry = Kontentblocks::getService('registry.modules');

                    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 addForm uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                    Open

                            } else {
                                $this->globalModule($template);
                            }

                    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 save() contains an exit expression.
                    Open

                                    exit;

                    ExitExpression

                    Since: 0.2

                    An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                    Example

                    class Foo {
                        public function bar($param)  {
                            if ($param === 42) {
                                exit(23);
                            }
                        }
                    }

                    Source https://phpmd.org/rules/design.html#exitexpression

                    TODO found
                    Open

                            // TODO Explanation text for non-developers on page

                    TODO found
                    Open

                            // TODO Include a public context switch

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

                        public function postTypeMessages($messages)
                        {
                            $post = get_post();
                    
                            $messages['kb-gmd'] = array(
                    Severity: Major
                    Found in core/Backend/Dynamic/GlobalModulesMenu.php and 1 other location - About 1 day to fix
                    core/Backend/Dynamic/DynamicAreas.php on lines 425..452

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

                    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

                            $labels = array(
                                'name' => _x('Global Module', 'post type general name', 'Kontentblocks'),
                                'singular_name' => _x('Global Module', 'post type singular name', 'Kontentblocks'),
                                'menu_name' => _x('Global Modules', 'admin menu', 'Kontentblocks'),
                                'name_admin_bar' => _x('Global Modules', 'add new on admin bar', 'Kontentblocks'),
                    Severity: Major
                    Found in core/Backend/Dynamic/GlobalModulesMenu.php and 1 other location - About 7 hrs to fix
                    core/Backend/Dynamic/DynamicAreas.php on lines 381..396

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

                    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