administrcms/form

View on GitHub
src/Form.php

Summary

Maintainability
C
1 day
Test Coverage
C
76%

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

    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

    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

      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

      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

      Avoid using static access to class '\Illuminate\Support\Arr' in method 'open'.
      Open

              if (Arr::get($this->options, 'method') == 'put') {
      Severity: Minor
      Found in src/Form.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 '\Illuminate\Support\Arr' in method 'addTokenField'.
      Open

              if (array_key_exists('_token', $this->fields()) || Arr::get($this->options, 'method') == 'get') {
      Severity: Minor
      Found in src/Form.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 '\Illuminate\Support\Arr' in method 'open'.
      Open

              $this->builder()->hidden('_method', Arr::get($this->options, 'method'));
      Severity: Minor
      Found in src/Form.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 '\Illuminate\Support\Arr' in method 'translated'.
      Open

              if($translated = Arr::get($this->fields(), 'translated')) {
      Severity: Minor
      Found in src/Form.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 '\Administr\Localization\Models\Language' in method 'translated'.
      Open

              $languages = Language::pluck('id');
      Severity: Minor
      Found in src/Form.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 assigning values to variables in if clauses and the like (line '301', column '12').
      Open

          public function translated()
          {
              $languages = Language::pluck('id');
      
              $this->form($this->builder);
      Severity: Minor
      Found in src/Form.php by phpmd

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

      Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

      The variable $language_id is not named in camelCase.
      Open

          public function translated()
          {
              $languages = Language::pluck('id');
      
              $this->form($this->builder);
      Severity: Minor
      Found in src/Form.php by phpmd

      CamelCaseVariableName

      Since: 0.2

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

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $language_id is not named in camelCase.
      Open

          public function translated()
          {
              $languages = Language::pluck('id');
      
              $this->form($this->builder);
      Severity: Minor
      Found in src/Form.php by phpmd

      CamelCaseVariableName

      Since: 0.2

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

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $language_id is not named in camelCase.
      Open

          public function translated()
          {
              $languages = Language::pluck('id');
      
              $this->form($this->builder);
      Severity: Minor
      Found in src/Form.php by phpmd

      CamelCaseVariableName

      Since: 0.2

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

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $language_id is not named in camelCase.
      Open

          public function translated()
          {
              $languages = Language::pluck('id');
      
              $this->form($this->builder);
      Severity: Minor
      Found in src/Form.php by phpmd

      CamelCaseVariableName

      Since: 0.2

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

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      There are no issues that match your filters.

      Category
      Status