File form-edit-page-handler.php
has 751 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Form edit page handler class
*
* @package TorroForms
Method print_templates
has 134 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function print_templates() {
?>
<script type="text/html" id="tmpl-torro-failure">
<div class="torro-notice notice-error">
<p>
Form_Edit_Page_Handler
has 32 functions (exceeds 20 allowed). Consider refactoring. Open
class Form_Edit_Page_Handler {
/**
* Form manager instance.
*
Function handle_save_request
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
private function handle_save_request( $form ) {
$this->current_form = $form;
$mappings = array(
'forms' => 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
Method handle_save_request
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handle_save_request( $form ) {
$this->current_form = $form;
$mappings = array(
'forms' => array(
Function save_elements
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
private function save_elements( $elements, $mappings, $errors ) {
$element_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' );
foreach ( $elements as $id => $data ) {
if ( empty( $data['container_id'] ) || ! isset( $mappings['containers'][ $data['container_id'] ] ) ) {
- 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 save_element_settings
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
private function save_element_settings( $element_settings, $mappings, $errors ) {
$element_setting_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' )->get_child_manager( 'element_settings' );
foreach ( $element_settings as $id => $data ) {
if ( empty( $data['element_id'] ) || ! isset( $mappings['elements'][ $data['element_id'] ] ) ) {
- 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 save_element_choices
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
private function save_element_choices( $element_choices, $mappings, $errors ) {
$element_choice_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' )->get_child_manager( 'element_choices' );
foreach ( $element_choices as $id => $data ) {
if ( empty( $data['element_id'] ) || ! isset( $mappings['elements'][ $data['element_id'] ] ) ) {
- 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 add_meta_boxes
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function add_meta_boxes( $form ) {
$this->current_form = $form;
if ( ! did_action( "{$this->form_manager->get_prefix()}add_form_meta_content" ) ) {
/**
Function save_containers
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private function save_containers( $containers, $mappings, $errors ) {
$container_manager = $this->form_manager->get_child_manager( 'containers' );
foreach ( $containers as $id => $data ) {
$data['form_id'] = key( $mappings['forms'] );
- 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 save_elements
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function save_elements( $elements, $mappings, $errors ) {
$element_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' );
foreach ( $elements as $id => $data ) {
if ( empty( $data['container_id'] ) || ! isset( $mappings['containers'][ $data['container_id'] ] ) ) {
Method save_element_settings
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function save_element_settings( $element_settings, $mappings, $errors ) {
$element_setting_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' )->get_child_manager( 'element_settings' );
foreach ( $element_settings as $id => $data ) {
if ( empty( $data['element_id'] ) || ! isset( $mappings['elements'][ $data['element_id'] ] ) ) {
Method save_element_choices
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function save_element_choices( $element_choices, $mappings, $errors ) {
$element_choice_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' )->get_child_manager( 'element_choices' );
foreach ( $element_choices as $id => $data ) {
if ( empty( $data['element_id'] ) || ! isset( $mappings['elements'][ $data['element_id'] ] ) ) {
Method action_duplicate_form
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function action_duplicate_form() {
$nonce = filter_input( INPUT_GET, '_wpnonce' );
$form_id = filter_input( INPUT_GET, 'form_id', FILTER_VALIDATE_INT );
if ( empty( $form_id ) ) {
Method add_meta_box
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function add_meta_box( $id, $args ) {
$prefix = $this->form_manager->get_prefix();
if ( 0 !== strpos( $id, $prefix ) ) {
$id = $prefix . $id;
Method save_containers
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function save_containers( $containers, $mappings, $errors ) {
$container_manager = $this->form_manager->get_child_manager( 'containers' );
foreach ( $containers as $id => $data ) {
$data['form_id'] = key( $mappings['forms'] );
Method maybe_show_duplicate_form_feedback
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function maybe_show_duplicate_form_feedback() {
$meta_key = $this->form_manager->get_prefix() . 'duplicate_feedback';
$form_id = filter_input( INPUT_GET, $meta_key, FILTER_VALIDATE_INT );
if ( empty( $form_id ) ) {
Method maybe_add_duplicate_button
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function maybe_add_duplicate_button( $output, $post_id, $new_title, $new_slug, $post ) {
Method maybe_add_submissions_button
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function maybe_add_submissions_button( $output, $post_id, $new_title, $new_slug, $post ) {
Function add_meta_boxes
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function add_meta_boxes( $form ) {
$this->current_form = $form;
if ( ! did_action( "{$this->form_manager->get_prefix()}add_form_meta_content" ) ) {
/**
- 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 action_duplicate_form
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function action_duplicate_form() {
$nonce = filter_input( INPUT_GET, '_wpnonce' );
$form_id = filter_input( INPUT_GET, 'form_id', FILTER_VALIDATE_INT );
if ( empty( $form_id ) ) {
- 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 maybe_enqueue_assets
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function maybe_enqueue_assets( $hook_suffix ) {
if ( 'post-new.php' !== $hook_suffix && 'post.php' !== $hook_suffix ) {
return;
}
- 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
private function save_element_choices( $element_choices, $mappings, $errors ) {
$element_choice_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' )->get_child_manager( 'element_choices' );
foreach ( $element_choices as $id => $data ) {
if ( empty( $data['element_id'] ) || ! isset( $mappings['elements'][ $data['element_id'] ] ) ) {
- 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 256.
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
private function save_element_settings( $element_settings, $mappings, $errors ) {
$element_setting_manager = $this->form_manager->get_child_manager( 'containers' )->get_child_manager( 'elements' )->get_child_manager( 'element_settings' );
foreach ( $element_settings as $id => $data ) {
if ( empty( $data['element_id'] ) || ! isset( $mappings['elements'][ $data['element_id'] ] ) ) {
- 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 256.
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 add_tab( $id, $args ) {
if ( ! empty( $args['meta_box'] ) ) {
$prefix = $this->form_manager->get_prefix();
if ( 0 !== strpos( $args['meta_box'], $prefix ) ) {
- 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 107.
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