Skip to content

Commit 3f001f2

Browse files
tbradshamatticbot
authored andcommitted
Phan: Clean up PhanRedundantCondition violations (excluding jetpack and crm) (#44033)
* packages/connection: PhanRedundantCondition * packages/device-detection: PhanRedundantCondition * packages/forms: PhanRedundantCondition * packages/jetpack-mu-wpcom: PhanRedundantCondition * packages/my-jetpack: PhanRedundantCondition * packages/search: PhanRedundantCondition * packages/status: PhanRedundantCondition * packages/sync: PhanRedundantCondition * packages/videopress: PhanRedundantCondition * packages/wp-js-data-sync: PhanRedundantCondition * plugins/boost: PhanRedundantCondition * plugins/super-cache: PhanRedundantCondition * plugins/vaultpress: PhanRedundantCondition * plugins/wpcomsh: PhanRedundantCondition * Add changelog * Trade a few Phan violations back for some compliant PHPCS * Update Phan baselines * Remove errant code * Update PHPDoc * Update projects/plugins/super-cache/wp-cache-phase2.php Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com> * Explicitly initialize $cached_direct_pages early * Ensure we have what we need * Make Phan happier * Update condition to use int instead of bool * Update Phan baseline --------- Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com> Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/15881245606 Upstream-Ref: Automattic/jetpack@7f361d9
1 parent 6b8c221 commit 3f001f2

File tree

13 files changed

+78
-91
lines changed

13 files changed

+78
-91
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "wordpress-plugin",
55
"license": "GPL-2.0-or-later",
66
"require": {
7-
"automattic/jetpack-device-detection": "^3.0.8"
7+
"automattic/jetpack-device-detection": "^3.0.9-alpha"
88
},
99
"require-dev": {
1010
"yoast/phpunit-polyfills": "^4.0.0",

composer.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inc/delete-cache-button.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function wpsc_delete_cache_directory() {
155155
return false;
156156
}
157157

158-
$path = $valid_nonce ? realpath( trailingslashit( get_supercache_dir() . str_replace( '..', '', preg_replace( '/:.*$/', '', $req_path ) ) ) ) : false;
158+
$path = realpath( trailingslashit( get_supercache_dir() . str_replace( '..', '', preg_replace( '/:.*$/', '', $req_path ) ) ) );
159159

160160
if ( $path ) {
161161
if ( isset( $_POST['admin'] ) && (int) $_POST['admin'] === 1 ) {

plugins/badbehaviour.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,15 @@ function wp_supercache_badbehaviour_admin() {
4242
$cache_badbehaviour = 0;
4343
}
4444

45-
$err = false;
45+
$err = false;
46+
$changed = false;
4647

4748
if ( isset( $_POST['cache_badbehaviour'] ) && $valid_nonce ) {
4849
$bbfile = get_bb_file_loc();
4950
if ( ! $bbfile ) {
5051
$_POST['cache_badbehaviour'] = 0;
5152
$err = __( 'Bad Behaviour not found. Please check your install.', 'wp-super-cache' );
5253
}
53-
if ( $cache_badbehaviour === (int) $_POST['cache_badbehaviour'] ) {
54-
$changed = false;
55-
} else {
56-
$changed = true;
57-
}
5854
$cache_badbehaviour = (int) $_POST['cache_badbehaviour'];
5955
wp_cache_replace_line( '^ *\$cache_compression', "\$cache_compression = 0;", $wp_cache_config_file );
6056
wp_cache_replace_line( '^ *\$cache_badbehaviour', "\$cache_badbehaviour = $cache_badbehaviour;", $wp_cache_config_file );
@@ -70,7 +66,7 @@ function wp_supercache_badbehaviour_admin() {
7066
<label><input type="radio" name="cache_badbehaviour" value="0" <?php if ( ! $cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
7167
<p><?php _e( '', 'wp-super-cache' ); ?></p><?php
7268
echo '<p>' . sprintf( __( '(Only WPCache caching supported, disabled compression and requires <a href="http://www.bad-behavior.ioerror.us/">Bad Behavior</a> in "%s/plugins/bad-behavior/") ', 'wp-super-cache' ), WP_CONTENT_DIR ) . '</p>';
73-
if ( isset( $changed ) && $changed ) {
69+
if ( $changed ) {
7470
if ( $cache_badbehaviour ) {
7571
$status = __( 'enabled', 'wp-super-cache' );
7672
} else {

plugins/domain-mapping.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function wp_supercache_domain_mapping_admin() {
6868
if ( null !== $requested_state && $valid_nonce ) {
6969
$cache_domain_mapping = $requested_state;
7070

71-
wp_cache_replace_line( '^\s*\$cache_domain_mapping\s*=', '$cache_domain_mapping = ' . intval( $cache_domain_mapping ) . ';', $wp_cache_config_file );
71+
wp_cache_replace_line( '^\s*\$cache_domain_mapping\s*=', '$cache_domain_mapping = ' . $cache_domain_mapping . ';', $wp_cache_config_file );
7272
$changed = true;
7373
}
7474

vendor/automattic/jetpack-device-detection/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.0.9-alpha] - unreleased
9+
10+
This is an alpha version! The changes listed here are not final.
11+
812
## [3.0.8] - 2025-06-09
913
### Fixed
1014
- Tests: Ensure method param count matches PHPUnit data providers. [#43828]
@@ -244,6 +248,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
244248

245249
- Moving jetpack_is_mobile into a package
246250

251+
[3.0.9-alpha]: https://github.com/Automattic/jetpack-device-detection/compare/v3.0.8...v3.0.9-alpha
247252
[3.0.8]: https://github.com/Automattic/jetpack-device-detection/compare/v3.0.7...v3.0.8
248253
[3.0.7]: https://github.com/Automattic/jetpack-device-detection/compare/v3.0.6...v3.0.7
249254
[3.0.6]: https://github.com/Automattic/jetpack-device-detection/compare/v3.0.5...v3.0.6

vendor/automattic/jetpack-device-detection/src/class-device-detection.php

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ private static function is_mobile( $kind, $return_matched_agent, $ua_info ) {
177177
'dumb' => false,
178178
'any' => false,
179179
);
180-
$first_run = true;
181180
$matched_agent = '';
182181

183182
// If an invalid kind is passed in, reset it to default.
@@ -207,42 +206,38 @@ private static function is_mobile( $kind, $return_matched_agent, $ua_info ) {
207206
return false;
208207
}
209208

210-
if ( $first_run ) {
211-
$first_run = false;
212-
213-
// checks for iPhoneTier devices & RichCSS devices.
214-
if ( $ua_info->isTierIphone() || $ua_info->isTierRichCSS() ) {
215-
$kinds['smart'] = true;
216-
$matched_agent = $ua_info->matched_agent;
217-
}
209+
// checks for iPhoneTier devices & RichCSS devices.
210+
if ( $ua_info->isTierIphone() || $ua_info->isTierRichCSS() ) {
211+
$kinds['smart'] = true;
212+
$matched_agent = $ua_info->matched_agent;
213+
}
218214

219-
if ( ! $kinds['smart'] ) {
220-
// if smart, we are not dumb so no need to check.
221-
$dumb_agents = $ua_info->dumb_agents;
215+
if ( ! $kinds['smart'] ) {
216+
// if smart, we are not dumb so no need to check.
217+
$dumb_agents = $ua_info->dumb_agents;
222218

223-
foreach ( $dumb_agents as $dumb_agent ) {
224-
if ( false !== strpos( $agent, $dumb_agent ) ) {
225-
$kinds['dumb'] = true;
226-
$matched_agent = $dumb_agent;
219+
foreach ( $dumb_agents as $dumb_agent ) {
220+
if ( false !== strpos( $agent, $dumb_agent ) ) {
221+
$kinds['dumb'] = true;
222+
$matched_agent = $dumb_agent;
227223

228-
break;
229-
}
224+
break;
230225
}
226+
}
231227

232-
if ( ! $kinds['dumb'] ) {
233-
if ( isset( $_SERVER['HTTP_X_WAP_PROFILE'] ) ) {
234-
$kinds['dumb'] = true;
235-
$matched_agent = 'http_x_wap_profile';
236-
} elseif ( isset( $_SERVER['HTTP_ACCEPT'] ) && ( preg_match( '/wap\.|\.wap/i', $_SERVER['HTTP_ACCEPT'] ) || false !== strpos( strtolower( $_SERVER['HTTP_ACCEPT'] ), 'application/vnd.wap.xhtml+xml' ) ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is doing the validating.
237-
$kinds['dumb'] = true;
238-
$matched_agent = 'vnd.wap.xhtml+xml';
239-
}
228+
if ( ! $kinds['dumb'] ) {
229+
if ( isset( $_SERVER['HTTP_X_WAP_PROFILE'] ) ) {
230+
$kinds['dumb'] = true;
231+
$matched_agent = 'http_x_wap_profile';
232+
} elseif ( isset( $_SERVER['HTTP_ACCEPT'] ) && ( preg_match( '/wap\.|\.wap/i', $_SERVER['HTTP_ACCEPT'] ) || false !== strpos( strtolower( $_SERVER['HTTP_ACCEPT'] ), 'application/vnd.wap.xhtml+xml' ) ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is doing the validating.
233+
$kinds['dumb'] = true;
234+
$matched_agent = 'vnd.wap.xhtml+xml';
240235
}
241236
}
237+
}
242238

243-
if ( $kinds['dumb'] || $kinds['smart'] ) {
244-
$kinds['any'] = true;
245-
}
239+
if ( $kinds['dumb'] || $kinds['smart'] ) {
240+
$kinds['any'] = true;
246241
}
247242

248243
$value = $kinds[ $kind ];

vendor/automattic/jetpack-device-detection/src/class-user-agent-info.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ public static function get_blackbeberry_OS_version() {
14801480
} elseif ( preg_match( '#Version\/([\d\.]+)#i', $agent, $matches ) ) { // Detecting the BB OS version for devices running OS 6.0 or higher.
14811481
$version = $matches[1];
14821482
$version_num = explode( '.', $version );
1483-
if ( false === is_array( $version_num ) || count( $version_num ) <= 1 ) {
1483+
if ( count( $version_num ) <= 1 ) {
14841484
return 'blackberry-6'; // not a BB device that match our rule.
14851485
} else {
14861486
return 'blackberry-' . $version_num[0];
@@ -1501,7 +1501,7 @@ public static function get_blackbeberry_OS_version() {
15011501

15021502
$version_num = explode( '.', $version );
15031503

1504-
if ( is_array( $version_num ) === false || count( $version_num ) <= 1 ) {
1504+
if ( count( $version_num ) <= 1 ) {
15051505
return false;
15061506
}
15071507

@@ -1563,7 +1563,7 @@ public static function detect_blackberry_browser_version() {
15631563

15641564
$version_num = explode( '.', $matches[1] );
15651565

1566-
if ( false === is_array( $version_num ) || count( $version_num ) <= 1 ) {
1566+
if ( count( $version_num ) <= 1 ) {
15671567
return false;
15681568
}
15691569

vendor/composer/installed.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"packages": [
33
{
44
"name": "automattic/jetpack-device-detection",
5-
"version": "3.0.8",
6-
"version_normalized": "3.0.8.0",
5+
"version": "3.0.9-alpha.1750867098",
6+
"version_normalized": "3.0.9.0-alpha1750867098",
77
"dist": {
88
"type": "path",
99
"url": "/tmp/jetpack-build/Automattic/jetpack-device-detection",
10-
"reference": "d444422e699935db9737c94b2cae4ba140ae0c7b"
10+
"reference": "0261a4b754129b72c47526e651dcaeee55553fb8"
1111
},
1212
"require": {
1313
"php": ">=7.2"

vendor/composer/installed.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
),
1212
'versions' => array(
1313
'automattic/jetpack-device-detection' => array(
14-
'pretty_version' => '3.0.8',
15-
'version' => '3.0.8.0',
16-
'reference' => 'd444422e699935db9737c94b2cae4ba140ae0c7b',
14+
'pretty_version' => '3.0.9-alpha.1750867098',
15+
'version' => '3.0.9.0-alpha1750867098',
16+
'reference' => '0261a4b754129b72c47526e651dcaeee55553fb8',
1717
'type' => 'jetpack-library',
1818
'install_path' => __DIR__ . '/../automattic/jetpack-device-detection',
1919
'aliases' => array(),

0 commit comments

Comments
 (0)