wikimedia/mediawiki-core

View on GitHub
includes/htmlform/HTMLFormField.php

Summary

Maintainability
F
5 days
Test Coverage

File HTMLFormField.php has 762 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace MediaWiki\HTMLForm;

use HtmlArmor;
Severity: Major
Found in includes/htmlform/HTMLFormField.php - About 1 day to fix

    HTMLFormField has 59 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class HTMLFormField {
        /** @var array|array[] */
        public $mParams;
    
        /** @var callable(mixed,array,HTMLForm):(Status|string|bool|Message) */
    Severity: Major
    Found in includes/htmlform/HTMLFormField.php - About 1 day to fix

      Function __construct has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          public function __construct( $params ) {
              $this->mParams = $params;
      
              if ( isset( $params['parent'] ) && $params['parent'] instanceof HTMLForm ) {
                  $this->mParent = $params['parent'];
      Severity: Minor
      Found in includes/htmlform/HTMLFormField.php - About 3 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

      Method __construct has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function __construct( $params ) {
              $this->mParams = $params;
      
              if ( isset( $params['parent'] ) && $params['parent'] instanceof HTMLForm ) {
                  $this->mParent = $params['parent'];
      Severity: Major
      Found in includes/htmlform/HTMLFormField.php - About 2 hrs to fix

        Method getOOUI has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getOOUI( $value ) {
                $inputField = $this->getInputOOUI( $value );
        
                if ( !$inputField ) {
                    // This field doesn't have an OOUI implementation yet at all. Fall back to getDiv() to
        Severity: Major
        Found in includes/htmlform/HTMLFormField.php - About 2 hrs to fix

          Method getCodex has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getCodex( $value ) {
                  $isDisabled = ( $this->mParams['disabled'] ?? false );
          
                  // Label
                  $labelDiv = '';
          Severity: Minor
          Found in includes/htmlform/HTMLFormField.php - About 1 hr to fix

            Method getTableRow has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function getTableRow( $value ) {
                    [ $errors, $errorClass ] = $this->getErrorsAndErrorClass( $value );
                    $inputHtml = $this->getInputHTML( $value );
                    $fieldType = $this->getClassName();
                    $helptext = $this->getHelpTextHtmlTable( $this->getHelpText() );
            Severity: Minor
            Found in includes/htmlform/HTMLFormField.php - About 1 hr to fix

              Method validateCondState has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function validateCondState( $params ) {
                      $origParams = $params;
                      $op = array_shift( $params );
              
                      $makeException = function ( string $details ) use ( $origParams ): InvalidArgumentException {
              Severity: Minor
              Found in includes/htmlform/HTMLFormField.php - About 1 hr to fix

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

                    public function getDiv( $value ) {
                        [ $errors, $errorClass ] = $this->getErrorsAndErrorClass( $value );
                        $inputHtml = $this->getInputHTML( $value );
                        $fieldType = $this->getClassName();
                        $helptext = $this->getHelpTextHtmlDiv( $this->getHelpText() );
                Severity: Minor
                Found in includes/htmlform/HTMLFormField.php - About 1 hr to fix

                  Function validateCondState has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                      protected function validateCondState( $params ) {
                          $origParams = $params;
                          $op = array_shift( $params );
                  
                          $makeException = function ( string $details ) use ( $origParams ): InvalidArgumentException {
                  Severity: Minor
                  Found in includes/htmlform/HTMLFormField.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 getOOUI has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function getOOUI( $value ) {
                          $inputField = $this->getInputOOUI( $value );
                  
                          if ( !$inputField ) {
                              // This field doesn't have an OOUI implementation yet at all. Fall back to getDiv() to
                  Severity: Minor
                  Found in includes/htmlform/HTMLFormField.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 checkStateRecurse has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function checkStateRecurse( array $alldata, array $params ) {
                          $op = array_shift( $params );
                          $valueChk = [ 'AND' => false, 'OR' => true, 'NAND' => false, 'NOR' => true ];
                          $valueRet = [ 'AND' => true, 'OR' => false, 'NAND' => false, 'NOR' => true ];
                  
                  
                  Severity: Minor
                  Found in includes/htmlform/HTMLFormField.php - About 1 hr to fix

                    Function getOptions has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getOptions() {
                            if ( $this->mOptions === false ) {
                                if ( array_key_exists( 'options-messages', $this->mParams ) ) {
                                    $needsParse = $this->mParams['options-messages-parse'] ?? false;
                                    if ( $needsParse ) {
                    Severity: Minor
                    Found in includes/htmlform/HTMLFormField.php - About 55 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 getCodex has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getCodex( $value ) {
                            $isDisabled = ( $this->mParams['disabled'] ?? false );
                    
                            // Label
                            $labelDiv = '';
                    Severity: Minor
                    Found in includes/htmlform/HTMLFormField.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 getLabelHtml has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getLabelHtml( $cellAttributes = [] ) {
                            # Don't output a for= attribute for labels with no associated input.
                            # Kind of hacky here, possibly we don't want these to be <label>s at all.
                            $for = $this->needsLabel() ? [ 'for' => $this->mID ] : [];
                    
                    
                    Severity: Minor
                    Found in includes/htmlform/HTMLFormField.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 getHelpText has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getHelpText() {
                            $html = [];
                    
                            foreach ( $this->getHelpMessages() as $msg ) {
                                if ( $msg instanceof HtmlArmor ) {
                    Severity: Minor
                    Found in includes/htmlform/HTMLFormField.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

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

                        public function getAttributes( array $list ) {
                            static $boolAttribs = [ 'disabled', 'required', 'autofocus', 'multiple', 'readonly' ];
                    
                            $ret = [];
                            foreach ( $list as $key ) {
                    Severity: Minor
                    Found in includes/htmlform/HTMLFormField.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 $p;
                    Severity: Major
                    Found in includes/htmlform/HTMLFormField.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                              return ( $value !== $testValue );
                      Severity: Major
                      Found in includes/htmlform/HTMLFormField.php - About 30 mins to fix

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

                            protected static function formatErrors( $errors ) {
                                if ( is_array( $errors ) && count( $errors ) === 1 ) {
                                    $errors = array_shift( $errors );
                                }
                        
                        
                        Severity: Minor
                        Found in includes/htmlform/HTMLFormField.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 validate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function validate( $value, $alldata ) {
                                if ( $this->isHidden( $alldata ) ) {
                                    return true;
                                }
                        
                        
                        Severity: Minor
                        Found in includes/htmlform/HTMLFormField.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 getErrorsRaw has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function getErrorsRaw( $value ) {
                                $errors = $this->validate( $value, $this->mParent->mFieldData );
                        
                                if ( is_bool( $errors ) || !$this->mParent->wasSubmitted() ) {
                                    return [];
                        Severity: Minor
                        Found in includes/htmlform/HTMLFormField.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

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

                                if ( isset( $params['label-message'] ) ) {
                                    $this->mLabel = $this->getMessage( $params['label-message'] )->parse();
                                } elseif ( isset( $params['label'] ) ) {
                                    if ( $params['label'] === '&#160;' || $params['label'] === "\u{00A0}" ) {
                                        // Apparently some things set &nbsp directly and in an odd format
                        Severity: Major
                        Found in includes/htmlform/HTMLFormField.php and 1 other location - About 2 hrs to fix
                        includes/htmlform/fields/HTMLButtonField.php on lines 59..70

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

                        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