kai-jacobsen/kontentblocks

View on GitHub
core/Fields/Field.php

Summary

Maintainability
D
1 day
Test Coverage

Field has 41 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class Field implements ExportableFieldInterface
{

    /**
     * Unique id generated on run time
Severity: Minor
Found in core/Fields/Field.php - About 5 hrs to fix

    File Field.php has 371 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    
    namespace Kontentblocks\Fields;
    
    Severity: Minor
    Found in core/Fields/Field.php - About 4 hrs to fix

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

      abstract class Field implements ExportableFieldInterface
      {
      
          /**
           * Unique id generated on run time
      Severity: Minor
      Found in core/Fields/Field.php by phpmd

      The class Field has 15 public methods. Consider refactoring Field to keep number of public methods under 10.
      Open

      abstract class Field implements ExportableFieldInterface
      {
      
          /**
           * Unique id generated on run time
      Severity: Minor
      Found in core/Fields/Field.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

      Function getFrontendValue has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getFrontendValue($salt = null)
          {
      
              if (!is_null($this->userValue)) {
                  return $this->userValue;
      Severity: Minor
      Found in core/Fields/Field.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 getFrontendValue has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getFrontendValue($salt = null)
          {
      
              if (!is_null($this->userValue)) {
                  return $this->userValue;
      Severity: Minor
      Found in core/Fields/Field.php - About 1 hr to fix

        Avoid using undefined variables such as '::$settings' which will lead to PHP notices.
        Open

                    return static::$settings[$key];
        Severity: Minor
        Found in core/Fields/Field.php by phpmd

        UndefinedVariable

        Since: 2.8.0

        Detects when a variable is used that has not been defined before.

        Example

        class Foo
        {
            private function bar()
            {
                // $message is undefined
                echo $message;
            }
        }

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

        Avoid using undefined variables such as '::$settings' which will lead to PHP notices.
        Open

                if (isset(static::$settings[$key])) {
        Severity: Minor
        Found in core/Fields/Field.php by phpmd

        UndefinedVariable

        Since: 2.8.0

        Detects when a variable is used that has not been defined before.

        Example

        class Foo
        {
            private function bar()
            {
                // $message is undefined
                echo $message;
            }
        }

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

        Avoid using undefined variables such as '::$settings' which will lead to PHP notices.
        Open

                $this->type = static::$settings['type'];
        Severity: Minor
        Found in core/Fields/Field.php by phpmd

        UndefinedVariable

        Since: 2.8.0

        Detects when a variable is used that has not been defined before.

        Example

        class Foo
        {
            private function bar()
            {
                // $message is undefined
                echo $message;
            }
        }

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

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

        abstract class Field implements ExportableFieldInterface
        {
        
            /**
             * Unique id generated on run time
        Severity: Minor
        Found in core/Fields/Field.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

        Missing class import via use statement (line '606', column '27').
        Open

                        throw new \Exception('requested Return Object does not exist');
        Severity: Minor
        Found in core/Fields/Field.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 getArg has a boolean flag argument $default, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function getArg($arg, $default = false)
        Severity: Minor
        Found in core/Fields/Field.php by phpmd

        BooleanArgumentFlag

        Since: 1.4.0

        A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

        Example

        class Foo {
            public function bar($flag = true) {
            }
        }

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

        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 {
                    return $new;
                }
        Severity: Minor
        Found in core/Fields/Field.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 getArg uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    return $default;
                }
        Severity: Minor
        Found in core/Fields/Field.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 prepareFrontend uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                else {
                    return $this->prepareFrontendValue($value);
                }
        Severity: Minor
        Found in core/Fields/Field.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 getFrontendValue uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $this->returnObj = $this->getStandardReturnObject($value, $salt);
                    $this->userValue = $this->returnObj;
                    return $this->userValue;
                }
        Severity: Minor
        Found in core/Fields/Field.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 cleanedArgs uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $args = $this->args;
                    unset($args['callbacks']);
                    return $args;
                }
        Severity: Minor
        Found in core/Fields/Field.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 '\Kontentblocks\Language\I18n' in method 'form'.
        Open

                    'i18n' => I18n::getPackages('Refields.common', "Refields.{$type}")
        Severity: Minor
        Found in core/Fields/Field.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 setBaseId uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $this->baseId = $baseId . '[' . $subkey . ']';
                }
        Severity: Minor
        Found in core/Fields/Field.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 getSetting uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    return null;
                }
        Severity: Minor
        Found in core/Fields/Field.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 '$old'.
        Open

            public function save($new, $old)
        Severity: Minor
        Found in core/Fields/Field.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

        Avoid unused parameters such as '$renderer'.
        Open

            public function renderHidden(FieldFormRenderer $renderer)
        Severity: Minor
        Found in core/Fields/Field.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

        TODO found
        Open

             * @TODO this method is used on several occasions
        Severity: Minor
        Found in core/Fields/Field.php by fixme

        TODO found
        Open

             * @TODO hacky
        Severity: Minor
        Found in core/Fields/Field.php by fixme

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

            public function export(FieldExport $exporter)
            {
                $kpath = $this->createKPath();
                $exporter->addField($kpath, array(
                    'key' => $this->getKey(),
        Severity: Major
        Found in core/Fields/Field.php and 1 other location - About 1 hr to fix
        core/Fields/Definitions/Context.php on lines 90..103

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

        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

        The method _save is not named in camelCase.
        Open

            public function _save($new, $old = null)
            {
                $data = $this->save($new, $old);
                if ($this->getCallback('save.value')) {
                    $data = call_user_func($this->getCallback('save.value'), $new, $old, $data);
        Severity: Minor
        Found in core/Fields/Field.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        There are no issues that match your filters.

        Category
        Status