Commit cd75baff102 for woocommerce

commit cd75baff1029ddf34c03863606dedbe9e299b843
Author: Faisal Ahammad <faisalahammad24@gmail.com>
Date:   Wed Jun 3 17:20:50 2026 +0600

    fix(logging): prevent fatal error in get_log_directory_size when log directory does not exist (#65403)

    * fix(logging): prevent fatal error in get_log_directory_size when log directory does not exist

    Add early return when realpath() returns false or empty string,
    which happens when the log directory has not been created (e.g.
    logging is disabled). Prevents ValueError from wp_is_writable()
    receiving an invalid path.

    Fixes #65390

    * fix(review): remove stale phpstan baseline, add regression test, add changelog for #65390

    Remove two baselined PHPStan errors resolved by the realpath() guard.
    Add test asserting get_log_directory_size returns 0 for missing directory.
    Add changelog entry for patch fix.

    ---------

    Co-authored-by: Faisal Ahammad <faisalahammad@users.noreply.github.com>

diff --git a/plugins/woocommerce/changelog/65390-fix-log-dir-size-fatal b/plugins/woocommerce/changelog/65390-fix-log-dir-size-fatal
new file mode 100644
index 00000000000..ec04cfa8344
--- /dev/null
+++ b/plugins/woocommerce/changelog/65390-fix-log-dir-size-fatal
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Prevent fatal error on System Status page when log directory does not exist (e.g. when logging is disabled).
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 3f7037432e5..2b07f1bd869 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -58083,12 +58083,6 @@ parameters:
 			count: 1
 			path: src/Internal/Admin/Logging/FileV2/FileController.php

-		-
-			message: '#^Parameter \#1 \$directory of class RecursiveDirectoryIterator constructor expects string, string\|false given\.$#'
-			identifier: argument.type
-			count: 1
-			path: src/Internal/Admin/Logging/FileV2/FileController.php
-
 		-
 			message: '#^Parameter \#1 \$fp of function feof expects resource, resource\|false given\.$#'
 			identifier: argument.type
@@ -58101,12 +58095,6 @@ parameters:
 			count: 1
 			path: src/Internal/Admin/Logging/FileV2/FileController.php

-		-
-			message: '#^Parameter \#1 \$path of function wp_is_writable expects string, string\|false given\.$#'
-			identifier: argument.type
-			count: 1
-			path: src/Internal/Admin/Logging/FileV2/FileController.php
-
 		-
 			message: '#^Parameter \#1 \$paths of method Automattic\\WooCommerce\\Internal\\Admin\\Logging\\FileV2\\FileController\:\:convert_paths_to_objects\(\) expects array, list\<string\>\|false given\.$#'
 			identifier: argument.type
diff --git a/plugins/woocommerce/src/Internal/Admin/Logging/FileV2/FileController.php b/plugins/woocommerce/src/Internal/Admin/Logging/FileV2/FileController.php
index 68268a80c5b..01531f71f4a 100644
--- a/plugins/woocommerce/src/Internal/Admin/Logging/FileV2/FileController.php
+++ b/plugins/woocommerce/src/Internal/Admin/Logging/FileV2/FileController.php
@@ -658,6 +658,10 @@ class FileController {
 		$bytes = 0;
 		$path  = realpath( Settings::get_log_directory( false ) );

+		if ( empty( $path ) ) {
+			return 0;
+		}
+
 		if ( wp_is_writable( $path ) ) {
 			$iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $path, \FilesystemIterator::SKIP_DOTS ), \RecursiveIteratorIterator::CATCH_GET_CHILD );

diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Logging/FileV2/FileControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Logging/FileV2/FileControllerTest.php
index ef018773d8f..f4954444612 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Logging/FileV2/FileControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Logging/FileV2/FileControllerTest.php
@@ -410,6 +410,22 @@ class FileControllerTest extends WC_Unit_Test_Case {
 		$this->assertStringContainsString( 'A trip to the food bar', $match['line'] );
 	}

+	/**
+	 * @testdox get_log_directory_size returns 0 when log directory does not exist.
+	 */
+	public function test_get_log_directory_size_missing_directory(): void {
+		$missing  = wp_upload_dir()['basedir'] . '/wc-logs-nonexistent/';
+		$callback = function () use ( $missing ) {
+			return $missing;
+		};
+		add_filter( 'woocommerce_log_directory', $callback );
+
+		$result = $this->sut->get_log_directory_size();
+		$this->assertSame( 0, $result );
+
+		remove_filter( 'woocommerce_log_directory', $callback );
+	}
+
 	/**
 	 * @testdox The get_log_directory_size method should return an accurate size of the directory in bytes.
 	 */