inc/fields/file.php
File file.php
has 305 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
<?php
defined( 'ABSPATH' ) || die;
/**
* The file upload file which allows users to upload files via the default HTML <input type="file">.
Method file_html
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
protected static function file_html( $file, $index, $field ) {
$i18n_delete = apply_filters( 'rwmb_file_delete_string', _x( 'Delete', 'file upload', 'meta-box' ) );
$i18n_edit = apply_filters( 'rwmb_file_edit_string', _x( 'Edit', 'file upload', 'meta-box' ) );
$attributes = self::get_attributes( $field, $file );
Method html
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public static function html( $meta, $field ) {
$meta = array_filter( (array) $meta );
$i18n_more = apply_filters( 'rwmb_file_add_string', _x( '+ Add new file', 'file upload', 'meta-box' ), $field );
$html = self::get_uploaded_files( $meta, $field );
Method ajax_delete_file
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public static function ajax_delete_file() {
$request = rwmb_request();
$field_id = (string) $request->filter_post( 'field_id' );
$type = str_contains( $request->filter_post( 'field_name' ), '[' ) ? 'child' : 'top';
check_ajax_referer( "rwmb-delete-file_{$field_id}" );
Method clone_value
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
public static function clone_value( $new, $old, $object_id, $field, $data_source = null ) {
Function transform
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
protected static function transform( $input_name ) {
// @codingStandardsIgnoreStart
foreach ( $_FILES[ $input_name ] as $key => $list ) {
foreach ( $list as $index => $value ) {
$file_key = "{$input_name}_{$index}";
- 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 value
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
public static function value( $new, $old, $post_id, $field ) {
$input = $field['index'] ?? $field['input_name'];
// @codingStandardsIgnoreLine
if ( empty( $input ) || empty( $_FILES[ $input ] ) ) {
- 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"