Code Duplication    Length = 8-14 lines in 6 locations

core/helpers/EEH_File.helper.php 6 locations

@@ 330-337 (lines=8) @@
327
            if (! EEH_File::verify_is_writable($parent_folder)) {
328
                return false;
329
            }
330
            if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
331
                if (defined('WP_DEBUG') && WP_DEBUG) {
332
                    $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
333
                    $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
334
                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
335
                }
336
                return false;
337
            }
338
            EEH_File::add_index_file($folder);
339
        } elseif (! EEH_File::verify_is_writable($folder)) {
340
            return false;
@@ 390-397 (lines=8) @@
387
            if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
388
                return false;
389
            }
390
            if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
391
                if (defined('WP_DEBUG') && WP_DEBUG) {
392
                    $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
393
                    $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
394
                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
395
                }
396
                return false;
397
            }
398
        }
399
        if (! EEH_File::verify_is_writable($full_file_path, 'file')) {
400
            return false;
@@ 464-476 (lines=13) @@
461
        $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
462
        $file_type      = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : '';
463
        $folder         = EEH_File::remove_filename_from_filepath($full_file_path);
464
        if (! EEH_File::verify_is_writable($folder)) {
465
            if (defined('WP_DEBUG') && WP_DEBUG) {
466
                $msg =
467
                    sprintf(
468
                        esc_html__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'),
469
                        $file_type,
470
                        $full_file_path
471
                    );
472
                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
473
                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
474
            }
475
            return false;
476
        }
477
        // load WP_Filesystem and set file permissions
478
        $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
479
        // write the file
@@ 744-757 (lines=14) @@
741
            EEH_File::convert_local_filepath_to_remote_filepath($destination_file),
742
            $overwrite
743
        );
744
        if (! $copied) {
745
            if (defined('WP_DEBUG') && WP_DEBUG) {
746
                $msg = sprintf(
747
                    esc_html__(
748
                        'Attempted writing to file %1$s, but could not, probably because of permissions issues',
749
                        'event_espresso'
750
                    ),
751
                    $source_file
752
                );
753
                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($source_file, 'f');
754
                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
755
            }
756
            return false;
757
        }
758
        return true;
759
    }
760
@@ 899-911 (lines=13) @@
896
    private static function validateFileForCopyOrMove(string $source_file): string
897
    {
898
        $full_source_path = EEH_File::standardise_directory_separators($source_file);
899
        if (! EEH_File::exists($full_source_path)) {
900
            if (defined('WP_DEBUG') && WP_DEBUG) {
901
                $msg =
902
                    sprintf(
903
                        esc_html__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'),
904
                        '',
905
                        $full_source_path
906
                    );
907
                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
908
                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
909
            }
910
            return '';
911
        }
912
        return $full_source_path;
913
    }
914
@@ 925-936 (lines=12) @@
922
        $full_dest_path = EEH_File::standardise_directory_separators($destination_file);
923
        $folder         = EEH_File::remove_filename_from_filepath($full_dest_path);
924
        EEH_File::ensure_folder_exists_and_is_writable($folder);
925
        if (! EEH_File::verify_is_writable($folder)) {
926
            if (defined('WP_DEBUG') && WP_DEBUG) {
927
                $msg = sprintf(
928
                    esc_html__('The file located at "%2$s" is not writable.', 'event_espresso'),
929
                    '',
930
                    $full_dest_path
931
                );
932
                $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
933
                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
934
            }
935
            return '';
936
        }
937
        return $full_dest_path;
938
    }
939
}