File CFPHPFormularios.php
has 438 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
CFPHPFormularios
has 25 functions (exceeds 20 allowed). Consider refactoring. Open
class CFPHPFormularios
{
/*
* Form configuration. It don't need description
*/
Method validateInput
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function validateInput($data) {
// Obtaining value send by user
$readValue = $this->getData($data['name']);
// Empty/not send and required?
Function validateInput
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
private function validateInput($data) {
// Obtaining value send by user
$readValue = $this->getData($data['name']);
// Empty/not send and required?
- 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 log
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function log($message, $data = array()) {
if ($this->logErrors) {
// Try to get a name (label or name)
if (class_exists('kw')) {
if (isset($data['label'])) $this->errors .= 'Found an error in field' . ': "' . $data['label'] . '": ';
- 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 showForm
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function showForm() {
// Loading all arrays
$toShow = $this->content;
// Showing form
- 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 showForm
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function showForm() {
// Loading all arrays
$toShow = $this->content;
// Showing form
Method addNumber
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
public function addNumber($label = '', $name = '', $value = '', $range = false, $required = false, $min = '', $max = '', $step = '', $placeholder = '', $attributes = array()) {
Method addDate
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
public function addDate($label = '', $name = '', $value = '', $required = false, $min = '', $max = '', $step = '', $placeholder = '', $attributes = array()) {
Function showSelect
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function showSelect($data, $values, $selected = null) {
$r = '<select ';
// Convert array to input string
foreach ($data as $attr=>$value) {
$r .= $attr.'="'.$value.'" ';
- 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 validateArray
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function validateArray($values, $value, $data = array()) {
if (is_array($values)) {
// Is array (serach all "$value" in "$values"
if (!array_key_exists($value, $values)) {
if (is_array($value)) {
- 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 validate
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function validate() {
$this->error_list = ''; // Clean error list
$total = 0; // Total counted params
$success = 0; // Total correct
Function validate
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function validate() {
$this->error_list = ''; // Clean error list
$total = 0; // Total counted params
$success = 0; // Total correct
- 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 addInput
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
public function addInput($label = '', $type = 'text', $name = '', $value = '', $required = false, $placeholder = '', $attributes = array()) {
Method addSelect
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
public function addSelect($label = '', $name = '', $values = '', $selected = null, $required = false, $multiple = false, $attributes = array()) {
Method addRadio
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public function addRadio($label = '', $name = '', $values = array(), $selected = null, $required = false, $attributes = array()) {
Method addCheck
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function addCheck($label = '', $name = '', $value = '', $required = false, $attributes = array()) {
Method addTextArea
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function addTextArea($label = '', $name = '', $value = '', $required = false, $attributes = array()) {
Function addDate
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function addDate($label = '', $name = '', $value = '', $required = false, $min = '', $max = '', $step = '', $placeholder = '', $attributes = array()) {
// Creating main data
$data = array(
'type' => 'date',
'name' => $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 showRadio
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function showRadio($data, $values, $selected) {
// Primero generamos un esquema
$base = '<label><input type="radio"';
// Asignamos las claves conviritiendo el array
- 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 addNumber
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function addNumber($label = '', $name = '', $value = '', $range = false, $required = false, $min = '', $max = '', $step = '', $placeholder = '', $attributes = array()) {
// Creating main data
$data = array(
'type' => (! $range) ? 'number' : 'range',
'name' => $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
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return false;
Function showStartForm
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function showStartForm() {
$r = '<form ';
if ($this->action!= '') $r .= 'action="'.$this->action.'" ';
if ($this->method != '') $r .= 'method="'.$this->method .'" ';
if ($this->name != '') $r .= 'name="'.$this->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
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function addSubmit($name = '', $value = '', $attributes = array()) {
$data = array(
'type' => 'submit',
'name' => $name,
'value' => $value
- Read upRead up
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 90.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function addButton($value = '', $onClick = '', $attributes = array()) {
$data = array(
'type' => 'button',
'value' => $value,
'onClick' => $onClick
- Read upRead up
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 90.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76