Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #6756 Increase phpstan level 2 #6761

Merged
merged 64 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
41d2494
Change phpstan level + bootstrap file
Miraeld Jul 1, 2024
d95c3e8
Apply phpstan fix to templates
Miraeld Jul 2, 2024
a952ed7
apply php-stan changes
Miraeld Jul 2, 2024
b211dbf
Merge branch 'develop' into enhancement/6621-increase-phpstan-level
Miraeld Jul 2, 2024
06d1968
apply php-stan changes
Miraeld Jul 2, 2024
2c5abbf
Fix db check
Miraeld Jul 2, 2024
ec66b02
Fix linter
Miraeld Jul 2, 2024
6704936
Fix ignore
Miraeld Jul 2, 2024
ad1e211
Fix linter
Miraeld Jul 2, 2024
29933d4
Fix linter
Miraeld Jul 3, 2024
5831731
Comply feedback
Miraeld Jul 4, 2024
7cc19b5
Increase phpstan level
Miraeld Jul 4, 2024
a46b8ee
fix feedback
Miraeld Jul 4, 2024
ba37442
Merge branch 'enhancement/6621-increase-phpstan-level' into enhanceme…
Miraeld Jul 4, 2024
9b80a03
First batch
Miraeld Jul 5, 2024
3203d3f
Second batch
Miraeld Jul 5, 2024
05a7016
Third Batch
Miraeld Jul 7, 2024
9f3886d
Move stan bootstrap
Miraeld Jul 8, 2024
950e7e2
Merge branch 'enhancement/6621-increase-phpstan-level' into enhanceme…
Miraeld Jul 8, 2024
d94bedd
fixes phpstan
Miraeld Jul 8, 2024
7dab3a4
v3.16.2.1 (#6769)
Khadreal Jul 8, 2024
1e12df8
Merge branch 'develop' into enhancement/6756-increase-phpstan-level-2
Tabrisrp Jul 8, 2024
56bd40a
update classes import
Tabrisrp Jul 8, 2024
7b15377
update var
Tabrisrp Jul 8, 2024
aea9c68
update param type
Tabrisrp Jul 8, 2024
41a54cd
add clouflare plugin to require-dev
Tabrisrp Jul 9, 2024
5de0a26
update scanDirectories
Tabrisrp Jul 9, 2024
c42140b
remove ignore
Tabrisrp Jul 9, 2024
586301d
Merge branch 'trunk' into enhancement/6756-increase-phpstan-level-2
Tabrisrp Jul 9, 2024
ce2e82e
check variable is an object before trying to access properties
Tabrisrp Jul 9, 2024
18ddfab
cast int
Tabrisrp Jul 9, 2024
956fb35
remove typehint
Tabrisrp Jul 9, 2024
accfe5e
cast object
Tabrisrp Jul 9, 2024
13a8b67
check for object before accessing properties
Tabrisrp Jul 9, 2024
b6e1636
update import and type declaration
Tabrisrp Jul 10, 2024
6b59222
ignore next line
Tabrisrp Jul 10, 2024
8c8764e
add missing import
Tabrisrp Jul 10, 2024
c9ab198
update typehint
Tabrisrp Jul 10, 2024
f667b6d
check if $row is object
Tabrisrp Jul 10, 2024
ad054d0
update typehint
Tabrisrp Jul 10, 2024
3ee502e
update typehint
Tabrisrp Jul 10, 2024
388b8aa
update typehint
Tabrisrp Jul 10, 2024
5ccb800
check for property before usage
Tabrisrp Jul 10, 2024
ded6907
remove incorrect @uses
Tabrisrp Jul 10, 2024
6dafe88
update import
Tabrisrp Jul 10, 2024
9feab83
add missing namespace and update import
Tabrisrp Jul 10, 2024
5927378
update test
Tabrisrp Jul 10, 2024
bec9f7f
remove mockery from scanDirectories
Tabrisrp Jul 10, 2024
e2553b9
formatting
Tabrisrp Jul 11, 2024
578e315
formatting
Tabrisrp Jul 11, 2024
2e746d9
formatting
Tabrisrp Jul 11, 2024
cf44790
formatting
Tabrisrp Jul 11, 2024
249e46f
formatting
Tabrisrp Jul 11, 2024
93af613
formatting
Tabrisrp Jul 11, 2024
26391ac
revert unexpected change
Tabrisrp Jul 11, 2024
d3b19dc
revert unexpected change
Tabrisrp Jul 11, 2024
9ddbcfc
fix risky test
Tabrisrp Jul 11, 2024
762ebf3
update formatting
Tabrisrp Jul 11, 2024
97968c4
remove annotation
Tabrisrp Jul 11, 2024
8693b4b
update tests
Tabrisrp Jul 12, 2024
7b1377b
mock rocket_bypass()
Tabrisrp Jul 12, 2024
38def17
remove annotation
Tabrisrp Jul 12, 2024
745d780
skip tests not performing assertions
Tabrisrp Jul 12, 2024
0a26436
remove skipped
Tabrisrp Jul 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"php-stubs/wordpress-tests-stubs": "^6.5",
"phpcompatibility/phpcompatibility-wp": "^2.0",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-phpunit": "^1.4",
"phpunit/phpunit": "^7.5 || ^8 || ^9",
"psr/container": "1.1.1",
Expand All @@ -69,6 +70,7 @@
"wp-media/phpunit": "^3",
"wp-media/rocket-lazyload-common": "^3.0.11",
"wp-media/wp-imagify-partner": "^1.0",
"wpackagist-plugin/cloudflare":"4.12.7",
"wpackagist-plugin/amp": "^1.1.4",
"wpackagist-plugin/hummingbird-performance": "2.0.1",
"wpackagist-plugin/jetpack": "9.3.2",
Expand Down
4 changes: 4 additions & 0 deletions inc/Engine/Admin/Settings/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ public function customer_data() {

$data['license_type'] = rocket_get_license_type( $user );

if ( ! is_object( $user ) ) {
return $data;
}

if ( ! empty( $user->licence_expiration ) ) {
$data['license_class'] = time() < $user->licence_expiration ? 'wpr-isValid' : 'wpr-isInvalid';
}
Expand Down
3 changes: 2 additions & 1 deletion inc/Engine/Cache/AdminSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use WP_Filesystem_Direct;
use WP_Rocket\Event_Management\Event_Manager;
use WP_Rocket\Event_Management\Event_Manager_Aware_Subscriber_Interface;
use WP_Term;

/**
* Subscriber for the cache admin events
Expand All @@ -15,7 +16,7 @@ class AdminSubscriber implements Event_Manager_Aware_Subscriber_Interface {
/**
* Event Manager instance
*
* @var Event_Manager;
* @var Event_Manager
*/
protected $event_manager;

Expand Down
1 change: 1 addition & 0 deletions inc/Engine/Cache/Purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use WP_Rocket\Engine\Preload\Database\Queries\Cache;
use DirectoryIterator;
use Exception;
use WP_Filesystem_Direct;
use WP_Term;
use WP_Post;

Expand Down
1 change: 1 addition & 0 deletions inc/Engine/Cache/WPCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace WP_Rocket\Engine\Cache;

use WP_Filesystem_Direct;
use WP_Rocket\Engine\Activation\ActivationInterface;
use WP_Rocket\Engine\Deactivation\DeactivationInterface;

Expand Down
1 change: 1 addition & 0 deletions inc/Engine/Capabilities/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use WP_Rocket\Engine\Activation\ActivationInterface;
use WP_Rocket\Engine\Deactivation\DeactivationInterface;
use WP_Role;

class Manager implements ActivationInterface, DeactivationInterface {
/**
Expand Down
6 changes: 3 additions & 3 deletions inc/Engine/Common/Database/Queries/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ public function get_on_submit_jobs( int $count = 100 ) {
return [];
}

$in_progress_count = $this->query(
$in_progress_count = (int) $this->query(
[
'count' => true,
'status' => [ 'in-progress' ],
]
);
$pending_count = $this->query(
$pending_count = (int) $this->query(
[
'count' => true,
'status' => [ 'pending' ],
Expand Down Expand Up @@ -188,7 +188,7 @@ public function get_pending_jobs( int $count = 100 ) {
return [];
}

$inprogress_count = $this->query(
$inprogress_count = (int) $this->query(
[
'count' => true,
'status' => 'in-progress',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ private function send_request( $method, $params = [], $safe = false ) {
private function set_timeout_transients( $previous_expiration ) {
$transient_key = $this->get_transient_key();

$expiration = ( 0 === $previous_expiration )
$expiration = ( 0 === (int) $previous_expiration )
? 300
: ( 2 * $previous_expiration <= DAY_IN_SECONDS
? 2 * $previous_expiration
: ( 2 * (int) $previous_expiration <= DAY_IN_SECONDS
? 2 * (int) $previous_expiration
: DAY_IN_SECONDS
);

Expand Down
10 changes: 5 additions & 5 deletions inc/Engine/Common/JobManager/JobProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use WP_Rocket\Logger\LoggerAware;
use WP_Rocket\Logger\LoggerAwareInterface;
use WP_Rocket\Engine\Common\Queue\QueueInterface;
use WP_Rocket\Engine\Common\JobManager\Queue\Queue;
use WP_Rocket\Engine\Common\JobManager\Strategy\Factory\StrategyFactory;
use WP_Rocket\Engine\Common\JobManager\APIHandler\APIClient;
use WP_Rocket\Engine\Common\Clock\WPRClock;
Expand All @@ -23,7 +23,7 @@ class JobProcessor implements LoggerAwareInterface {
/**
* Queue instance.
*
* @var QueueInterface
* @var Queue
*/
private $queue;

Expand Down Expand Up @@ -52,14 +52,14 @@ class JobProcessor implements LoggerAwareInterface {
* Instantiate the class.
*
* @param array $factories Array of factories.
* @param QueueInterface $queue Queue instance.
* @param Queue $queue Queue instance.
* @param StrategyFactory $strategy_factory Strategy Factory.
* @param APIClient $api APIClient instance.
* @param WPRClock $clock Clock object instance.
*/
public function __construct(
array $factories,
QueueInterface $queue,
Queue $queue,
StrategyFactory $strategy_factory,
APIClient $api,
WPRClock $clock
Expand Down Expand Up @@ -174,7 +174,7 @@ public function process_pending_jobs() {
public function check_job_status( string $url, bool $is_mobile, string $optimization_type ) {

$row_details = $this->get_single_job( $url, $is_mobile, $optimization_type );
if ( ! $row_details ) {
if ( ! is_object( $row_details ) ) {
$this->logger::debug( 'Url - ' . $url . ' not found for is_mobile - ' . (int) $is_mobile );
// Nothing in DB, bailout.
return;
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Common/JobManager/Managers/AbstractManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function get_single_job( string $url, bool $is_mobile ) {
* @param integer $num_rows Number of rows to grab with each CRON iteration.
* @return array|int
*/
public function get_on_submit_jobs( int $num_rows ): array {
public function get_on_submit_jobs( int $num_rows ) {
return $this->query->get_on_submit_jobs( $num_rows );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class RetryContext {
/**
* Strategy Interface.
*
* @var StrategyInterface;
* @var StrategyInterface
*/
protected $strategy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace WP_Rocket\Engine\Common\JobManager\Strategy\Strategies;

use WP_Rocket\Engine\Common\Clock\WPRClock;
use WP_Rocket\Engine\Common\JobManager\Managers\ManagerInterface;
use WP_Rocket\Engine\Optimization\RUCSS\Jobs\Manager;

/**
* Class managing the default error for retry process
Expand All @@ -13,7 +13,7 @@ class DefaultProcess implements StrategyInterface {
/**
* Job Manager.
*
* @var ManagerInterface
* @var Manager
*/
private $manager;

Expand Down Expand Up @@ -48,10 +48,10 @@ class DefaultProcess implements StrategyInterface {
/**
* Strategy Constructor.
*
* @param ManagerInterface $manager Job Manager.
* @param WPRClock $clock Clock object.
* @param Manager $manager Job Manager.
* @param WPRClock $clock Clock object.
*/
public function __construct( ManagerInterface $manager, WPRClock $clock ) {
public function __construct( Manager $manager, WPRClock $clock ) {
$this->manager = $manager;
$this->clock = $clock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace WP_Rocket\Engine\Common\JobManager\Strategy\Strategies;

use WP_Rocket\Engine\Common\JobManager\Managers\ManagerInterface;
use WP_Rocket\Engine\Optimization\RUCSS\Jobs\Manager;

/**
* Class managing the retry process whenever a job isn't found in the SaaS.
Expand All @@ -11,16 +11,16 @@ class JobSetFail implements StrategyInterface {
/**
* Job Manager.
*
* @var ManagerInterface
* @var Manager
*/
private $manager;

/**
* Strategy Constructor.
*
* @param ManagerInterface $manager Job Manager.
* @param Manager $manager Job Manager.
*/
public function __construct( ManagerInterface $manager ) {
public function __construct( Manager $manager ) {
$this->manager = $manager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace WP_Rocket\Engine\Common\JobManager\Strategy\Strategies;

use WP_Rocket\Engine\Common\JobManager\Managers\ManagerInterface;
use WP_Rocket\Engine\Optimization\RUCSS\Jobs\Manager;

/**
* Class managing the retry process whenever a job isn't found in the SaaS.
Expand All @@ -11,16 +11,16 @@ class ResetRetryProcess implements StrategyInterface {
/**
* Job Manager.
*
* @var ManagerInterface
* @var Manager
*/
private $manager;

/**
* Strategy Constructor.
*
* @param ManagerInterface $manager Job Manager.
* @param Manager $manager Job Manager.
*/
public function __construct( ManagerInterface $manager ) {
public function __construct( Manager $manager ) {
$this->manager = $manager;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/CriticalPath/APIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class APIClient {
* @param string $url The URL to send a CPCSS generation request for.
* @param array $params Optional. Parameters needed to be sent in the body. Default: [].
* @param string $item_type Optional. Type for this item if it's custom or specific type. Default: custom.
* @return array|WP_Error
* @return object|array|WP_Error
*/
public function send_generation_request( $url, $params = [], $item_type = 'custom' ) {
$params['url'] = $url;
Expand Down
1 change: 1 addition & 0 deletions inc/Engine/CriticalPath/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace WP_Rocket\Engine\CriticalPath\Admin;

use WP_Admin_Bar;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\CriticalPath\ProcessorService;
use WP_Rocket\Engine\CriticalPath\TransientTrait;
Expand Down
1 change: 1 addition & 0 deletions inc/Engine/CriticalPath/Admin/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace WP_Rocket\Engine\CriticalPath\Admin;

use WP_Admin_Bar;
use WP_Rocket\Event_Management\Subscriber_Interface;

class Subscriber implements Subscriber_Interface {
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/CriticalPath/CriticalCSSSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CriticalCSSSubscriber implements Subscriber_Interface {
/**
* Instance of Critical CSS.
*
* @var Critical_CSS
* @var CriticalCSS
*/
protected $critical_css;

Expand Down
4 changes: 2 additions & 2 deletions inc/Engine/CriticalPath/ProcessorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private function send_generation_request( $item_url, $item_path, $is_mobile = fa
$generated_job = $this->api_client->send_generation_request( $item_url, $params, $item_type );

// validate generate response.
if ( is_wp_error( $generated_job ) ) {
if ( is_wp_error( $generated_job ) || ! is_object( $generated_job ) ) {
// Failed so return back the data.
return $generated_job;
}
Expand Down Expand Up @@ -172,7 +172,7 @@ private function check_cpcss_job_status( $job_id, $item_path, $item_url, $is_mob
*
* @since 3.6
*
* @param array $job_details Job details array.
* @param object $job_details Job details object.
* @param string $item_url Url for web page to be processed, used for error messages.
* @param bool $is_mobile Bool identifier for is_mobile CPCSS generation.
* @param string $item_type Optional. Type for this item if it's custom or specific type. Default: custom.
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/CriticalPath/TransientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait TransientTrait {
* @param string $item_path Path for processed item.
* @param bool $mobile If this request is for mobile cpcss.
* @param string $message CPCSS reply message.
* @param bool/string $success CPCSS success or failure.
* @param bool|string $success CPCSS success or failure.
* @return void
*/
private function update_running_transient( $transient, $item_path, $mobile, $message, $success ) {
Expand Down
4 changes: 2 additions & 2 deletions inc/Engine/Media/AboveTheFold/AJAX/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ public function add_lcp_data() {
continue;
}

if ( 'lcp' === $image->label ) {
if ( isset( $image->label ) && 'lcp' === $image->label ) {
$lcp = $image_object;
continue;
}

if ( 'above-the-fold' === $image->label && 0 < $max_atf_images_number ) {
if ( isset( $image->label ) && 'above-the-fold' === $image->label && 0 < $max_atf_images_number ) {
$viewport[] = $image_object;

--$max_atf_images_number;
Expand Down
4 changes: 4 additions & 0 deletions inc/Engine/Media/AboveTheFold/Frontend/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ private function set_fetchpriority( $lcp, string $html ): string {
return $html;
}

if ( empty( $lcp->src ) ) {
return $html;
}

$html = $this->replace_html_comments( $html );
$url = urldecode( preg_quote( $lcp->src, '/' ) );
$pattern = '#<img(?:[^>]*?\s+)?src=["\']' . $url . '["\'](?:\s+[^>]*?)?>#';
Expand Down
8 changes: 4 additions & 4 deletions inc/Engine/Optimization/DelayJS/Admin/SiteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

use WP_Rocket\Admin\Options;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\Optimization\DynamicLists\DelayJSLists\DataManager;
use WP_Rocket\Engine\Optimization\DynamicLists\DynamicLists;
use WP_Theme;

class SiteList {
/**
* Delay JS data manager.
*
* @var DataManager
* @var DynamicLists
*/
protected $dynamic_lists;

Expand Down Expand Up @@ -246,14 +245,15 @@ public function prepare_delayjs_ui_list() {

return $full_list;
}

/**
* Fetch the icon.
*
* @param array $item item from the list.
* @param object $item item from the list.
* @return string
*/
private function get_icon( $item ) {
if ( empty( $item ) || empty( $item->icon_url ) ) {
if ( empty( $item->icon_url ) ) {
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Optimization/DynamicLists/DynamicLists.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function get_preload_exclusions(): array {
/**
* Get Delay JS dynamic list.
*
* @return array
* @return object
*/
public function get_delayjs_list() {
return $this->providers['delayjslists']->data_manager->get_lists();
Expand Down
Loading
Loading