Skip to content

Commit

Permalink
Closes #6621 Increase phpstan level to level 1 (#6754)
Browse files Browse the repository at this point in the history
  • Loading branch information
Miraeld committed Jul 8, 2024
1 parent 075f2bb commit d70151f
Show file tree
Hide file tree
Showing 37 changed files with 85 additions and 49 deletions.
17 changes: 10 additions & 7 deletions inc/Engine/CDN/RocketCDN/AdminPageSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,21 @@ public function display_rocketcdn_status() {

$subscription_data = $this->api_client->get_subscription_data();

$container_class = '';
$status_class = '';
$label = '';
$status_text = '';
$is_active = false;

if ( 'running' === $subscription_data['subscription_status'] ) {
$label = __( 'Next Billing Date', 'rocket' );
$status_class = ' wpr-isValid';
$container_class = '';
$status_text = date_i18n( get_option( 'date_format' ), strtotime( $subscription_data['subscription_next_date_update'] ) );
$is_active = true;
$label = __( 'Next Billing Date', 'rocket' );
$status_class = ' wpr-isValid';
$status_text = date_i18n( get_option( 'date_format' ), strtotime( $subscription_data['subscription_next_date_update'] ) );
$is_active = true;
} elseif ( 'cancelled' === $subscription_data['subscription_status'] ) {
$label = '';
$status_class = ' wpr-isInvalid';
$container_class = ' wpr-flex--egal';
$status_text = __( 'No Subscription', 'rocket' );
$is_active = false;
}

$data = [
Expand Down
2 changes: 2 additions & 0 deletions inc/Engine/CDN/RocketCDN/views/cta-big.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );

$data = isset( $data ) && is_array( $data ) ? $data : []; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
?>
<div class="wpr-rocketcdn-cta <?php echo esc_attr( $data['container_class'] ); ?>" id="wpr-rocketcdn-cta">
<?php if ( ! empty( $data['promotion_campaign'] ) ) : ?>
Expand Down
2 changes: 2 additions & 0 deletions inc/Engine/CDN/RocketCDN/views/cta-small.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/

defined( 'ABSPATH' ) || die( 'Cheatin&#8217; uh?' );

$data = isset( $data ) && is_array( $data ) ? $data : []; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
?>
<div class="wpr-rocketcdn-cta-small notice-alt notice-warning <?php echo esc_attr( $data['container_class'] ); ?>" id="wpr-rocketcdn-cta-small">
<div class="wpr-flex">
Expand Down
1 change: 1 addition & 0 deletions inc/Engine/CDN/RocketCDN/views/dashboard-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* }
*/

$data = isset( $data ) && is_array( $data ) ? $data : []; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
?>
<div class="wpr-optionHeader">
<h3 class="wpr-title2">RocketCDN</h3>
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Common/Database/Queries/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ protected function table_exists(): bool {
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions inc/Engine/Common/Database/Tables/AbstractTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function delete_old_rows() {
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return false;
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public function get_old_rows(): array {
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return false;
}

Expand All @@ -113,7 +113,7 @@ public function remove_all_completed_rows() {
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return false;
}

Expand Down
6 changes: 5 additions & 1 deletion inc/Engine/CriticalPath/APIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ private function get_response_success( $response_code, $response_data ) {
return (
200 === $response_code
&&
! empty( $response_data )
(
$response_data instanceof stdClass
&&
! empty( (array) $response_data )
)
&&
(
(
Expand Down
2 changes: 2 additions & 0 deletions inc/Engine/License/views/promo-banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

defined( 'ABSPATH' ) || exit;

$data = isset( $data ) ? $data : []; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
?>
<div class="rocket-promo-banner" id="rocket-promo-banner">
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

defined( 'ABSPATH' ) || exit;

$data = isset( $data ) ? $data : []; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
?>
<section class="rocket-renewal-expired-banner" id="rocket-renewal-banner">
<h3 class="rocket-expired-title"><?php esc_html_e( 'The Optimize CSS Delivery feature is disabled.', 'rocket' ); ?></h3>
Expand Down
2 changes: 2 additions & 0 deletions inc/Engine/License/views/renewal-expired-banner-ocd.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

defined( 'ABSPATH' ) || exit;

$data = isset( $data ) ? $data : []; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
?>
<section class="rocket-renewal-expired-banner" id="rocket-renewal-banner">
<h3 class="rocket-expired-title"><?php esc_html_e( 'You will soon lose access to some features.', 'rocket' ); ?></h3>
Expand Down
2 changes: 2 additions & 0 deletions inc/Engine/License/views/renewal-expired-banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

defined( 'ABSPATH' ) || exit;

$data = isset( $data ) ? $data : []; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
?>
<section class="rocket-renewal-expired-banner" id="rocket-renewal-banner">
<h3 class="rocket-expired-title"><?php esc_html_e( 'Your WP Rocket license is expired!', 'rocket' ); ?></h3>
Expand Down
2 changes: 2 additions & 0 deletions inc/Engine/License/views/renewal-soon-banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

defined( 'ABSPATH' ) || exit;

$data = isset( $data ) ? $data : []; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
?>
<div class="rocket-renewal-banner">
<ul class="rocket-promo-countdown" id="rocket-renew-countdown">
Expand Down
2 changes: 2 additions & 0 deletions inc/Engine/License/views/upgrade-popin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

defined( 'ABSPATH' ) || exit;

$data = isset( $data ) ? $data : []; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
?>
<div class="wpr-Popin wpr-Popin-Upgrade">
<div class="wpr-Popin-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function make_job_completed( string $url, bool $is_mobile, array $data )
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return false;
}

Expand Down Expand Up @@ -115,7 +115,7 @@ public function delete_old_rows() {
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions inc/Engine/Media/AboveTheFold/Frontend/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private function set_fetchpriority( $lcp, string $html ): string {
'picture',
];

if ( empty( $lcp ) || empty( $lcp->type ) || ! in_array( $lcp->type, $allowed_types, true ) ) {
if ( empty( (array) $lcp ) || empty( $lcp->type ) || ! in_array( $lcp->type, $allowed_types, true ) ) {
return $html;
}

Expand Down Expand Up @@ -488,7 +488,7 @@ private function generate_source_tags( $lcp, $start_tag, $end_tag ) {
$link_attribute = ( substr_count( $source->srcset, ',' ) > 0 ) ? 'imagesrcset' : 'href';

// Append the source and media query to the tag string.
$tag .= $start_tag . $link_attribute . '="' . $source->srcset . '"' . ( $media ?? '' ) . $sizes . $end_tag;
$tag .= $start_tag . $link_attribute . '="' . $source->srcset . '"' . ( $media ) . $sizes . $end_tag;

// If a max-width is found in the source's media attribute, update the previous max-width.
if ( preg_match( '/\(max-width: (\d+(\.\d+)?)px\)/', $source->media, $matches ) ) {
Expand Down
4 changes: 0 additions & 4 deletions inc/Engine/Media/ImageDimensions/ImageDimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ private function is_external_file( $url ) {

$hosts = array_unique( $hosts );

if ( empty( $hosts ) ) {
return true;
}

// URL has domain and domain is part of the internal domains.
if ( ! empty( $file['host'] ) ) {
foreach ( $hosts as $host ) {
Expand Down
4 changes: 0 additions & 4 deletions inc/Engine/Optimization/CSSTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,6 @@ protected function is_external_path( $url ) {

$hosts = array_unique( $hosts );

if ( empty( $hosts ) ) {
return true;
}

// URL has domain and domain is part of the internal domains.
if ( ! empty( $file['host'] ) ) {
foreach ( $hosts as $host ) {
Expand Down
2 changes: 2 additions & 0 deletions inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ private function add_used_fonts_preload( string $html, string $used_css ): strin

// Making sure the excluded fonts array isn't empty to avoid excluding all fonts.
if ( ! empty( $exclude_fonts_preload ) ) {
$exclude_fonts_preload = array_filter( $exclude_fonts_preload );

// Combine the array elements into a single string with | as a separator and returning a pattern.
$exclude_fonts_preload_pattern = implode(
'|',
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Optimization/RUCSS/Database/Queries/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function make_status_completed( string $url, bool $is_mobile, string $has
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return false;
}

Expand Down
4 changes: 0 additions & 4 deletions inc/Engine/Optimization/UrlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ private function is_external_file( $url ) {

$hosts = array_unique( $hosts );

if ( empty( $hosts ) ) {
return true;
}

// URL has domain and domain is part of the internal domains.
if ( ! empty( $file['host'] ) ) {
foreach ( $hosts as $host ) {
Expand Down
3 changes: 3 additions & 0 deletions inc/Engine/Preload/Controller/PreloadUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public function __construct( Options_Data $options, Queue $queue, Cache $rocket_
* @return void
*/
public function preload_url( string $url ) {
$start = 0;
$duration = 0;

$is_mobile = $this->options->get( 'do_caching_mobile_files', false );

if ( $this->is_already_cached( $url ) && ( ! $is_mobile || $this->is_already_cached( $url, true ) ) ) {
Expand Down
12 changes: 6 additions & 6 deletions inc/Engine/Preload/Database/Queries/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public function get_old_cache( float $delay = 1, string $unit = 'month' ): array
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return [];
}

Expand Down Expand Up @@ -473,7 +473,7 @@ public function revert_old_in_progress() {
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return false;
}

Expand All @@ -489,7 +489,7 @@ public function revert_old_failed() {
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return false;
}

Expand All @@ -505,7 +505,7 @@ public function set_all_to_pending() {
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return false;
}

Expand Down Expand Up @@ -568,7 +568,7 @@ public function remove_all() {
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return false;
}

Expand Down Expand Up @@ -603,7 +603,7 @@ public function unlock_all() {
$db = $this->get_db();

// Bail if no database interface is available.
if ( empty( $db ) ) {
if ( ! $db ) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/ThirdParty/Plugins/Optimization/AMP.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function disable_options_on_amp() {

global $wp_filter;

remove_filter( 'wp_resource_hints', 'rocket_dns_prefetch', 10, 2 );
remove_filter( 'wp_resource_hints', 'rocket_dns_prefetch', 10 );
add_filter( 'do_rocket_lazyload', '__return_false' );
add_filter( 'do_rocket_lazyload_iframes', '__return_false' );
add_filter( 'pre_get_rocket_option_async_css', '__return_false' );
Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
includes:
- phar://phpstan.phar/conf/bleedingEdge.neon
parameters:
level: 0
level: 1
inferPrivatePropertyTypeFromConstructor: true
paths:
# Test only the new architecture for now.
Expand All @@ -13,6 +13,8 @@ parameters:
bootstrapFiles:
# Must be first
- %currentWorkingDirectory%/inc/functions/options.php
# PHPStan bootstrap
- %currentWorkingDirectory%/tests/phpstan/phpstan-bootstrap.php
# Procedural code
- %currentWorkingDirectory%/inc/constants.php
- %currentWorkingDirectory%/inc/common/purge.php
Expand Down Expand Up @@ -41,6 +43,7 @@ parameters:
- %currentWorkingDirectory%/inc/admin/options.php
- %currentWorkingDirectory%/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
- %currentWorkingDirectory%/vendor/php-stubs/wordpress-tests-stubs/wordpress-tests-stubs.php
- %currentWorkingDirectory%/wp-rocket.php
excludePaths:
- %currentWorkingDirectory%/inc/vendors/
# These need plugin stubs!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function headers_sent()
return false;
}

function header($string)
function header($string, $replace)
{
if ( in_array( $string , HeaderCollector::$headers, true ) ) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
if(! function_exists('seopress_get_toggle_option')) {
function seopress_get_toggle_option() {
function seopress_get_toggle_option( $name ) {
return '1';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public function testShouldDoExpected( $config, $expected ) {
$this->filesystem->put_contents( $item_path, '.cpcss { color: red; }');
$this->assertTrue( $this->filesystem->exists( $item_path ) );

$mobile_item_path = '';

if ( $this->async_css_mobile ) {
$mobile_item_path = 'wp-content/cache/critical-css/1/posts' . DIRECTORY_SEPARATOR . "{$post_type}-" . self::$post_id . "-mobile.css";
$this->filesystem->put_contents( $mobile_item_path, '.cpcss-mobile { color: red; }');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function testShouldDoExpected( $config, $expected ) {
}
}

if ( isset( $save_cpcss ) && is_wp_error( $save_cpcss ) ) {
if ( is_wp_error( $save_cpcss ) ) {
$this->filesystem->chmod( 'wp-content/cache/critical-css/1/', 0444 );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function tear_down() {
remove_filter( 'rocket_specify_image_dimensions', [$this, 'filter_rocket_specify_image_dimensions'] );
}

if ( isset( $config['rocket_specify_dimension_skip_pictures_filter'] ) ){
if ( isset( $this->config_data['rocket_specify_dimension_skip_pictures_filter'] ) ){
remove_filter( 'rocket_specify_dimension_skip_pictures', [$this, 'filter_rocket_specify_dimension_skip_pictures'] );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function tear_down() {
delete_transient( 'wpr_dynamic_lists' );

if ( isset( $this->post->ID ) ) {
delete_post_meta( $this->post->ID, '_rocket_exclude_delay_js', 1, true );
delete_post_meta( $this->post->ID, '_rocket_exclude_delay_js', 1 );
}

$this->restoreWpHook( 'rocket_buffer' );
Expand Down
Loading

0 comments on commit d70151f

Please sign in to comment.