kai-jacobsen/kontentblocks

View on GitHub
kontentblocks.php

Summary

Maintainability
D
1 day
Test Coverage

The class Kontentblocks has 11 public methods. Consider refactoring Kontentblocks to keep number of public methods under 10.
Open

Class Kontentblocks
{

    const VERSION = '0.12.3';
    const DEVMODE = true;
Severity: Minor
Found in kontentblocks.php by phpmd

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

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

Class Kontentblocks
{

    const VERSION = '0.12.3';
    const DEVMODE = true;
Severity: Minor
Found in kontentblocks.php by phpmd

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

<?php
/*
  Plugin Name: Kontentblocks
  Plugin URI: https://github.com/kai-jacobsen/kontentblocks
  Description: Content modularization framework
Severity: Minor
Found in kontentblocks.php - About 3 hrs to fix

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

        public function loadPanels()
        {
    
            /** @var \Kontentblocks\Modules\ModuleRegistry $registry */
            $registry = $this->services['registry.panels'];
    Severity: Minor
    Found in kontentblocks.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

    Kontentblocks has 21 functions (exceeds 20 allowed). Consider refactoring.
    Open

    Class Kontentblocks
    {
    
        const VERSION = '0.12.3';
        const DEVMODE = true;
    Severity: Minor
    Found in kontentblocks.php - About 2 hrs to fix

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

          public function loadModules()
          {
      
              /** @var \Kontentblocks\Modules\ModuleRegistry $registry */
              $registry = $this->services['registry.modules'];
      Severity: Minor
      Found in kontentblocks.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

      Method setupUtilities has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function setupUtilities()
          {
      
      
              $this->services['utility.logger'] = function ($container) {
      Severity: Minor
      Found in kontentblocks.php - About 1 hr to fix

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

            private function setupUtilities()
            {
        
        
                $this->services['utility.logger'] = function ($container) {
        Severity: Minor
        Found in kontentblocks.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 new PanelRegistry();
        Severity: Major
        Found in kontentblocks.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                      return new EditScreenLayoutsRegistry();
          Severity: Major
          Found in kontentblocks.php - About 30 mins to fix

            Function setup has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public function setup()
                {
                    require_once dirname(__FILE__) . '/core/Hooks/setup.php';
                    Capabilities::setup();
                    add_theme_support('kontentblocks:clipboard');
            Severity: Minor
            Found in kontentblocks.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

            The class Kontentblocks has a coupling between objects value of 27. Consider to reduce the number of dependencies under 13.
            Open

            Class Kontentblocks
            {
            
                const VERSION = '0.12.3';
                const DEVMODE = true;
            Severity: Minor
            Found in kontentblocks.php by phpmd

            CouplingBetweenObjects

            Since: 1.1.0

            A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

            Example

            class Foo {
                /**
                 * @var \foo\bar\X
                 */
                private $x = null;
            
                /**
                 * @var \foo\bar\Y
                 */
                private $y = null;
            
                /**
                 * @var \foo\bar\Z
                 */
                private $z = null;
            
                public function setFoo(\Foo $foo) {}
                public function setBar(\Bar $bar) {}
                public function setBaz(\Baz $baz) {}
            
                /**
                 * @return \SplObjectStorage
                 * @throws \OutOfRangeException
                 * @throws \InvalidArgumentException
                 * @throws \ErrorException
                 */
                public function process(\Iterator $it) {}
            
                // ...
            }

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

            Avoid using static access to class '\Kontentblocks\Utils\CommonTwig\SimpleTwig' in method 'setupTemplating'.
            Open

                        return SimpleTwig::init();
            Severity: Minor
            Found in kontentblocks.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

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

                            _K::info('kontentblocks.php loaded from main theme');
            Severity: Minor
            Found in kontentblocks.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

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

                    _K::info('kb.init action fired. We\'re good to go.');
            Severity: Minor
            Found in kontentblocks.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

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

                        _K::info('kontentblocks.php loaded from childtheme');
            Severity: Minor
            Found in kontentblocks.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

            Avoid using static access to class '\Kontentblocks\Templating\Twig' in method 'setupTemplating'.
            Open

                        return Twig::setupEnvironment($container);
            Severity: Minor
            Found in kontentblocks.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

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

                    _K::info('Modules loaded');
            Severity: Minor
            Found in kontentblocks.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

            Avoid using static access to class '\Kontentblocks\Templating\Twig' in method 'setupTemplating'.
            Open

                        return Twig::setupLoader();
            Severity: Minor
            Found in kontentblocks.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

            Avoid using static access to class '\Kontentblocks\Hooks\Capabilities' in method 'onActivation'.
            Open

                    Capabilities::setup();
            Severity: Minor
            Found in kontentblocks.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

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

                    $this->request = Utilities::getRequest();
            Severity: Minor
            Found in kontentblocks.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

            Avoid using static access to class '\Kontentblocks\Templating\Twig' in method 'setupTemplating'.
            Open

                        return Twig::setupEnvironment($container, false);
            Severity: Minor
            Found in kontentblocks.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

            Avoid using static access to class '\Kontentblocks\Hooks\Enqueues' in method 'setup'.
            Open

                        Enqueues::setup();
            Severity: Minor
            Found in kontentblocks.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

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

                    _K::info('Fields loaded');
            Severity: Minor
            Found in kontentblocks.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

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

                    _K::info('Panels loaded');
            Severity: Minor
            Found in kontentblocks.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

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

                    Language\I18n::getInstance();
            Severity: Minor
            Found in kontentblocks.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

            Avoid using static access to class '\Kontentblocks\Hooks\Capabilities' in method 'setup'.
            Open

                    Capabilities::setup();
            Severity: Minor
            Found in kontentblocks.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 setupUtilities uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                        } else {
            //                $logger->pushHandler(new NullHandler());
                        }
            Severity: Minor
            Found in kontentblocks.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 unused parameters such as '$container'.
            Open

                    $this->services['utility.ajaxhandler'] = function ($container) {
            Severity: Minor
            Found in kontentblocks.php by phpmd

            UnusedFormalParameter

            Since: 0.2

            Avoid passing parameters to methods or constructors and then not using those parameters.

            Example

            class Foo
            {
                private function bar($howdy)
                {
                    // $howdy is not used
                }
            }

            Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

            There are no issues that match your filters.

            Category
            Status