Skip to content

Commit

Permalink
refactor(src) is_file over file_exists
Browse files Browse the repository at this point in the history
Replace uses of `file_exists` with `is_file`. While there is
functionally no difference between the two in this context, the
`is_file` function will use a cached check for a small performance
boost.
  • Loading branch information
lucatume committed Dec 16, 2024
1 parent 493bdc8 commit b7a1e1d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,13 +622,13 @@ protected function build_min_asset_url( $original_url ): string {

$script_debug = defined( 'SCRIPT_DEBUG' ) && Utils::is_truthy( SCRIPT_DEBUG );

if ( $script_debug && file_exists( wp_normalize_path( $root_path . $resource_path . $resource ) ) ) {
if ( $script_debug && is_file( wp_normalize_path( $root_path . $resource_path . $resource ) ) ) {
return $original_url;
}

$minified_abs_file_path = wp_normalize_path( $root_path . $minified_file_path );

if ( ! file_exists( $minified_abs_file_path ) ) {
if ( ! is_file( $minified_abs_file_path ) ) {
return $original_url;
}

Expand Down Expand Up @@ -1140,7 +1140,7 @@ public function has_asset_file(): bool {
return false;
}

return file_exists( $asset_file_path );
return is_file( $asset_file_path );
}

/**
Expand Down Expand Up @@ -1381,7 +1381,7 @@ public function maybe_get_min_file( $url ) {
$file_path = wp_normalize_path( "{$base_dir}/{$partial_path}" );
$file_url = "{$base_url}/{$partial_path}";

if ( file_exists( $file_path ) ) {
if ( is_file( $file_path ) ) {
return $file_url;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/wpunit/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ protected function assert_minified_found( $slug_prefix, $is_js = true, $has_min
$plugins_path = str_replace( constant( 'WP_CONTENT_DIR' ), '', constant( 'WP_PLUGIN_DIR' ) );

if ( constant( 'WP_PLUGIN_DIR' ) !== constant( 'WP_CONTENT_DIR' ) . $plugins_path || strpos( constant( 'ABSPATH' ), 'C:') === 0 || $wont_figure_out_min_vs_unmin ) {
// If we are testing outside of the actual plugin directory, the file_exists will always fail.
// If we are testing outside of the actual plugin directory, the `is_file` check will always fail.
// In installations where this set up is the actual, the file should exist.
// In this case it will always fail to locate mins.
$urls = array_map(
Expand Down

0 comments on commit b7a1e1d

Please sign in to comment.