Skip to content

Commit 5aaa1da

Browse files
committed
fix(quality): clear the phpstan finding and phpcs errors before release
- class-webdecoy-updater.php: narrow the update-transient parameter to stdClass before writing $transient->response, which both types the dynamic property write for phpstan (level 3) and guards the non-object case WordPress can pass on a request's first run. Also initialise ->response as an array before the indexed assignment. - phpcs.xml.dist: exclude the output-escaping sniff for tests/ only. The test harness is CLI: its echo output reaches a terminal, never a browser, so the sniff was a false positive (escaping would corrupt the terminal output). Every other security rule still applies to tests.
1 parent 0c32d70 commit 5aaa1da

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

includes/class-webdecoy-updater.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ public function __construct()
3737
*/
3838
public function check_for_updates($transient)
3939
{
40+
// WordPress passes the update transient (a stdClass) here, but on the
41+
// first run of a request it can be a non-object (false). Narrowing to
42+
// stdClass makes the dynamic ->response write below well-typed and
43+
// guards the non-object case in one step.
44+
if (!$transient instanceof \stdClass) {
45+
return $transient;
46+
}
47+
4048
if (empty($transient->checked)) {
4149
return $transient;
4250
}
@@ -73,6 +81,10 @@ public function check_for_updates($transient)
7381
return $transient;
7482
}
7583

84+
if (!isset($transient->response) || !is_array($transient->response)) {
85+
$transient->response = [];
86+
}
87+
7688
$transient->response[WEBDECOY_PLUGIN_BASENAME] = (object) [
7789
'slug' => 'webdecoy',
7890
'plugin' => WEBDECOY_PLUGIN_BASENAME,

phpcs.xml.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
<!-- Escaping, sanitization, nonces, validated input -->
2626
<rule ref="WordPress.Security"/>
2727

28+
<!--
29+
The test harness under tests/ is CLI-only: its echo output goes to a
30+
terminal, never to a browser, so the output-escaping sniff is a false
31+
positive there (escaping would corrupt the terminal output). Every
32+
other security rule still applies to test code.
33+
-->
34+
<rule ref="WordPress.Security.EscapeOutput">
35+
<exclude-pattern>tests/</exclude-pattern>
36+
</rule>
37+
2838
<!-- Proper use of $wpdb->prepare() -->
2939
<rule ref="WordPress.DB"/>
3040

0 commit comments

Comments
 (0)