From e088ef3d4a7b6d99a5423b731026b508324ad79c Mon Sep 17 00:00:00 2001
From: Marian <42134098+IanDelMar@users.noreply.github.com>
Date: Mon, 7 Jul 2025 13:24:26 +0200
Subject: [PATCH 1/5] Fix handling of dynamic constants
---
bootstrap.php | 20 ++++++++------------
extension.neon | 19 +++++++++++++++++--
2 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/bootstrap.php b/bootstrap.php
index 9831110..aedb7a3 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -5,16 +5,16 @@
// phpcs:disable Generic.PHP.ForbiddenFunctions.Found
// There are no core functions to read these constants.
-define('ABSPATH', './');
+define('ABSPATH', '/');
+define('WP_CONTENT_DIR', sprintf('%swp-content', ABSPATH));
+define('WP_PLUGIN_DIR', sprintf('%s/plugins', WP_CONTENT_DIR));
+define('WPMU_PLUGIN_DIR', sprintf('%s/mu-plugins', WP_CONTENT_DIR));
define('WP_DEBUG', true);
-define('WP_DEBUG_LOG', true);
-define('WP_DEBUG_DISPLAY', true);
-define('WP_PLUGIN_DIR', './');
-define('WPMU_PLUGIN_DIR', './');
-define('EMPTY_TRASH_DAYS', 30 * 86400);
+define('WP_DEBUG_DISPLAY', false);
+define('EMPTY_TRASH_DAYS', 30);
define('SCRIPT_DEBUG', false);
-define('WP_LANG_DIR', './');
-define('WP_CONTENT_DIR', './');
+define('WP_LANG_DIR', sprintf('%s/languages', WP_CONTENT_DIR));
+define('COOKIE_DOMAIN', '');
// Constants for expressing human-readable intervals.
define('MINUTE_IN_SECONDS', 60);
@@ -65,8 +65,4 @@
define('EP_ALL', EP_PERMALINK | EP_ATTACHMENT | EP_ROOT | EP_COMMENTS | EP_SEARCH | EP_PAGES | EP_ALL_ARCHIVES);
// Templating-related WordPress constants.
-// phpcs:ignore WordPress.WP.DiscouragedConstants.STYLESHEETPATHDeclarationFound
-define('STYLESHEETPATH', '/app/wp-content/themes/child/');
-// phpcs:ignore WordPress.WP.DiscouragedConstants.TEMPLATEPATHDeclarationFound
-define('TEMPLATEPATH', '/app/wp-content/themes/parent/');
define('WP_DEFAULT_THEME', 'twentytwentythree');
diff --git a/extension.neon b/extension.neon
index 56205ee..fe87b88 100644
--- a/extension.neon
+++ b/extension.neon
@@ -38,14 +38,29 @@ parameters:
- ../../php-stubs/wordpress-stubs/wordpress-stubs.php
- bootstrap.php
dynamicConstantNames:
+ # Debug constants
- WP_DEBUG
- WP_DEBUG_LOG
- WP_DEBUG_DISPLAY
- - EMPTY_TRASH_DAYS
- - WP_CLI
+ # Directory constants
+ - ABSPATH
+ - WP_PLUGIN_DIR
+ - WP_LANG_DIR
+ - WP_CONTENT_DIR
+ - WPMU_PLUGIN_DIR
+ # Templating constants
+ - WP_DEFAULT_THEME
+ # Filesystem constants
+ - FS_CONNECT_TIMEOUT
+ - FS_TIMEOUT
+ - FS_CHMOD_DIR
+ - FS_CHMOD_FILE
+ # Other constants
- COOKIE_DOMAIN
+ - EMPTY_TRASH_DAYS
- SAVEQUERIES
- SCRIPT_DEBUG
+ - WP_CLI
earlyTerminatingFunctionCalls:
- wp_send_json
- wp_nonce_ays
From 96deab847d420ae3a35121eb3b027a3e02c1f492 Mon Sep 17 00:00:00 2001
From: Marian <42134098+IanDelMar@users.noreply.github.com>
Date: Mon, 7 Jul 2025 15:31:29 +0200
Subject: [PATCH 2/5] Remove SAVEQUERIES from dynamicConstantNames
---
extension.neon | 1 -
1 file changed, 1 deletion(-)
diff --git a/extension.neon b/extension.neon
index fe87b88..7d5f751 100644
--- a/extension.neon
+++ b/extension.neon
@@ -58,7 +58,6 @@ parameters:
# Other constants
- COOKIE_DOMAIN
- EMPTY_TRASH_DAYS
- - SAVEQUERIES
- SCRIPT_DEBUG
- WP_CLI
earlyTerminatingFunctionCalls:
From c7aec98f2b94c82e9f159b088b0e379ea612ba6c Mon Sep 17 00:00:00 2001
From: Marian <42134098+IanDelMar@users.noreply.github.com>
Date: Mon, 7 Jul 2025 20:31:15 +0200
Subject: [PATCH 3/5] Revert "Remove SAVEQUERIES from dynamicConstantNames"
This reverts commit 96deab847d420ae3a35121eb3b027a3e02c1f492. It is handled separately in #287.
---
extension.neon | 1 +
1 file changed, 1 insertion(+)
diff --git a/extension.neon b/extension.neon
index 7d5f751..fe87b88 100644
--- a/extension.neon
+++ b/extension.neon
@@ -58,6 +58,7 @@ parameters:
# Other constants
- COOKIE_DOMAIN
- EMPTY_TRASH_DAYS
+ - SAVEQUERIES
- SCRIPT_DEBUG
- WP_CLI
earlyTerminatingFunctionCalls:
From 0d3fcf98506bfdda358137646928af4bebc2593a Mon Sep 17 00:00:00 2001
From: Marian <42134098+IanDelMar@users.noreply.github.com>
Date: Mon, 7 Jul 2025 21:51:58 +0200
Subject: [PATCH 4/5] Readd WP_DEBUG_LOG to bootstrap.php
---
bootstrap.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/bootstrap.php b/bootstrap.php
index aedb7a3..8970f8f 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -10,6 +10,7 @@
define('WP_PLUGIN_DIR', sprintf('%s/plugins', WP_CONTENT_DIR));
define('WPMU_PLUGIN_DIR', sprintf('%s/mu-plugins', WP_CONTENT_DIR));
define('WP_DEBUG', true);
+define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
define('EMPTY_TRASH_DAYS', 30);
define('SCRIPT_DEBUG', false);
From dbbd2064bd3741ad617efd5b9da364882cd01344 Mon Sep 17 00:00:00 2001
From: Marian <42134098+IanDelMar@users.noreply.github.com>
Date: Tue, 8 Jul 2025 03:07:20 +0200
Subject: [PATCH 5/5] Add tests for dynamic constants
---
phpcs.xml.dist | 2 +
phpstan.neon.dist | 1 +
tests/DynamicConstantTypeTest.php | 30 ++++++
tests/data/dynamic-constants.php | 128 +++++++++++++++++++++++
tests/phpstan-data/dynamic-constants.php | 112 ++++++++++++++++++++
5 files changed, 273 insertions(+)
create mode 100644 tests/DynamicConstantTypeTest.php
create mode 100644 tests/data/dynamic-constants.php
create mode 100644 tests/phpstan-data/dynamic-constants.php
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 3eef46a..4c951c7 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -5,6 +5,7 @@
tests/
tests/data/*
+ tests/phpstan-data/*
tests/functions.php
tests/WP_UnitTestCase_Base.php
@@ -19,6 +20,7 @@
tests/AssertMethodTypeSpecifyingExtensionTest.php
tests/DynamicReturnTypeExtensionTest.php
+ tests/DynamicConstantTypeTest.php
diff --git a/phpstan.neon.dist b/phpstan.neon.dist
index fd23039..ef3b54b 100644
--- a/phpstan.neon.dist
+++ b/phpstan.neon.dist
@@ -1,6 +1,7 @@
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
+ - vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
level: 9
scanFiles:
diff --git a/tests/DynamicConstantTypeTest.php b/tests/DynamicConstantTypeTest.php
new file mode 100644
index 0000000..b42e57e
--- /dev/null
+++ b/tests/DynamicConstantTypeTest.php
@@ -0,0 +1,30 @@
+
+ */
+ public function dataFileAsserts(): iterable
+ {
+ yield from self::gatherAssertTypes(__DIR__ . '/data/dynamic-constants.php');
+ }
+
+ /**
+ * @dataProvider dataFileAsserts
+ * @param array ...$args
+ */
+ public function testFileAsserts(string $assertType, string $file, ...$args): void
+ {
+ $this->assertFileAsserts($assertType, $file, ...$args);
+ }
+
+ public static function getAdditionalConfigFiles(): array
+ {
+ return [dirname(__DIR__) . '/vendor/szepeviktor/phpstan-wordpress/extension.neon'];
+ }
+}
diff --git a/tests/data/dynamic-constants.php b/tests/data/dynamic-constants.php
new file mode 100644
index 0000000..70bb2aa
--- /dev/null
+++ b/tests/data/dynamic-constants.php
@@ -0,0 +1,128 @@
+