File HTMLFormFieldCloner.php
has 376 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace MediaWiki\HTMLForm\Field;
use InvalidArgumentException;
Function loadDataFromRequest
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
public function loadDataFromRequest( $request ) {
// It's possible that this might be posted with no fields. Detect that
// by looking for an edit token.
if ( !$request->getCheck( 'wpEditToken' ) && $request->getArray( $this->mName ) === null ) {
return $this->getDefault();
- Read upRead up
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 createFieldsForKey
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
protected function createFieldsForKey( $key ) {
$fields = [];
foreach ( $this->mParams['fields'] as $fieldname => $info ) {
$name = "{$this->mName}[$key][$fieldname]";
if ( isset( $info['name'] ) ) {
- Read upRead up
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 getInputHTMLForKey
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
protected function getInputHTMLForKey( $key, array $values ) {
$displayFormat = $this->mParams['format'] ?? $this->mParent->getDisplayFormat();
// Conveniently, PHP method names are case-insensitive.
$getFieldHtmlMethod = $displayFormat == 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
- Read upRead up
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 getInputHTMLForKey
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getInputHTMLForKey( $key, array $values ) {
$displayFormat = $this->mParams['format'] ?? $this->mParent->getDisplayFormat();
// Conveniently, PHP method names are case-insensitive.
$getFieldHtmlMethod = $displayFormat == 'table' ? 'getTableRow' : ( 'get' . $displayFormat );
Function validate
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function validate( $values, $alldata ) {
if ( isset( $this->mParams['required'] )
&& $this->mParams['required'] !== false
&& !$values
) {
- Read upRead up
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 loadDataFromRequest
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function loadDataFromRequest( $request ) {
// It's possible that this might be posted with no fields. Detect that
// by looking for an edit token.
if ( !$request->getCheck( 'wpEditToken' ) && $request->getArray( $this->mName ) === null ) {
return $this->getDefault();
Method createFieldsForKey
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function createFieldsForKey( $key ) {
$fields = [];
foreach ( $this->mParams['fields'] as $fieldname => $info ) {
$name = "{$this->mName}[$key][$fieldname]";
if ( isset( $info['name'] ) ) {
Function cancelSubmit
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function cancelSubmit( $values, $alldata ) {
if ( isset( $values['nonjs'] ) ) {
return true;
}
- Read upRead up
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 getInputOOUIForKey
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getInputOOUIForKey( $key, array $values ) {
$html = '';
$hidden = '';
$fields = $this->getFieldsForKey( $key );
Function __construct
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function __construct( $params ) {
$this->uniqueId = $this->getClassName() . ++self::$counter . 'x';
parent::__construct( $params );
if ( empty( $this->mParams['fields'] ) || !is_array( $this->mParams['fields'] ) ) {
- Read upRead up
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 getDefault
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getDefault() {
$ret = parent::getDefault();
// The default is one entry with all subfields at their defaults.
if ( $ret === null ) {
- Read upRead up
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 getInputOOUIForKey
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function getInputOOUIForKey( $key, array $values ) {
$html = '';
$hidden = '';
$fields = $this->getFieldsForKey( $key );
- Read upRead up
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"