administrcms/form

View on GitHub

Showing 43 of 43 total issues

Form has 31 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class Form implements ValidatesWhenSubmitted
{
    use RenderAttributesTrait;

    protected $options = [];
Severity: Minor
Found in src/Form.php - About 3 hrs to fix

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

    abstract class Field
    {
        use RenderAttributesTrait;
    
        protected $name;
    Severity: Minor
    Found in src/Field/Field.php - About 3 hrs to fix

      The class Form has 25 public methods. Consider refactoring Form to keep number of public methods under 10.
      Open

      abstract class Form implements ValidatesWhenSubmitted
      {
          use RenderAttributesTrait;
      
          protected $options = [];
      Severity: Minor
      Found in src/Form.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 Form has an overall complexity of 60 which is very high. The configured complexity threshold is 50.
      Open

      abstract class Form implements ValidatesWhenSubmitted
      {
          use RenderAttributesTrait;
      
          protected $options = [];
      Severity: Minor
      Found in src/Form.php by phpmd

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

      <?php
      
      namespace Administr\Form\Field;
      
      class Radio extends Field
      Severity: Major
      Found in src/Field/Radio.php and 1 other location - About 2 hrs to fix
      src/Field/Checkbox.php on lines 1..20

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

      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

      <?php
      
      namespace Administr\Form\Field;
      
      class Checkbox extends Field
      Severity: Major
      Found in src/Field/Checkbox.php and 1 other location - About 2 hrs to fix
      src/Field/Radio.php on lines 1..20

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

      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

      File Form.php has 256 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      namespace Administr\Form;
      
      use Administr\Form\Contracts\ValidatesWhenSubmitted;
      Severity: Minor
      Found in src/Form.php - About 2 hrs to fix

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

            public function setEnctype()
            {
                if(array_key_exists('enctype', $this->options)) {
                    return $this;
                }
        Severity: Minor
        Found in src/Form.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

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

        <?php
        
        namespace Administr\Form\Field;
        
        class RadioGroup extends Field
        Severity: Major
        Found in src/Field/RadioGroup.php and 1 other location - About 1 hr to fix
        src/Field/CheckboxGroup.php on lines 1..29

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

        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

        <?php
        
        namespace Administr\Form\Field;
        
        class CheckboxGroup extends Field
        Severity: Major
        Found in src/Field/CheckboxGroup.php and 1 other location - About 1 hr to fix
        src/Field/RadioGroup.php on lines 1..28

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

        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

        Avoid using short method names like Field::is(). The configured minimum method name length is 3.
        Open

            public function is($types)
            {
                if(!is_array($types)) {
                    $types = (array)$types;
                }
        Severity: Minor
        Found in src/Field/Field.php by phpmd

        ShortMethodName

        Since: 0.2

        Detects when very short method names are used.

        Example

        class ShortMethod {
            public function a( $index ) { // Violation
            }
        }

        Source https://phpmd.org/rules/naming.html#shortmethodname

        The parameter $language_id is not named in camelCase.
        Open

            public function getValue($field, $language_id = 0)
            {
                $dataSource = $this->dataSource;
        
                if ($dataSource instanceof Translatable && $language_id > 0) {
        Severity: Minor
        Found in src/FormBuilder.php by phpmd

        CamelCaseParameterName

        Since: 0.2

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

        Example

        class ClassName {
            public function doSomething($user_name) {
            }
        }

        Source

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

            public function translated()
            {
                $languages = Language::pluck('id');
        
                $this->form($this->builder);
        Severity: Minor
        Found in src/Form.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

        Missing class import via use statement (line '341', column '26').
        Open

                $reflector = new \ReflectionClass($class);
        Severity: Minor
        Found in src/FormBuilder.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

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

            protected function optionsToMethods(array $options)
            {
                foreach($options as $name => $value)
                {
                    if(! method_exists($this, $name) ) {
        Severity: Minor
        Found in src/Field/Field.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

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

            public function getParsedRules()
            {
                $transformedRules = $this->validator->make([], $this->rules())->getRules();
        
                foreach($transformedRules as $field => $rules) {
        Severity: Minor
        Found in src/Form.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

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

            public function getValue($field, $language_id = 0)
            {
                $dataSource = $this->dataSource;
        
                if ($dataSource instanceof Translatable && $language_id > 0) {
        Severity: Minor
        Found in src/FormBuilder.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

        Avoid using static access to class '\Asset' in method 'execute'.
        Open

                Asset::addJs(
                    '/vendor/administr/form/tinymce/tinymce.min.js',
                    10
                );

        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 unused parameters such as '$tab'.
        Open

            public function builder($tab = null)
        Severity: Minor
        Found in src/Field/Translated.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 using static access to class '\Illuminate\Support\Arr' in method 'getOption'.
        Open

                return Arr::get($this->options, $option, $default);
        Severity: Minor
        Found in src/Field/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

        Severity
        Category
        Status
        Source
        Language