Skip to content

Commit 387be28

Browse files
authored
Merge pull request #951 from Codeinwp/dev/phpstan
dev: update PHPStan
2 parents 5c9258d + 5b37f23 commit 387be28

File tree

18 files changed

+3633
-150
lines changed

18 files changed

+3633
-150
lines changed

.distignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ assets/src
3838
postcss.config.js
3939
tailwind.config.js
4040
phpstan.neon
41+
phpstan-baseline.neon
4142
development.php
4243
playwright.config.ts
4344
test-results
4445
wp-scripts.config.js
4546
README.md
46-
CHANGELOG.md
47+
CHANGELOG.md

.github/workflows/test-php.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,22 @@ jobs:
5656
name: PHPStan on PHP 8.0
5757
runs-on: ubuntu-latest
5858
steps:
59+
- name: Checkout source code
60+
uses: actions/checkout@v4
5961
- name: Setup PHP version
6062
uses: shivammathur/setup-php@v2
6163
with:
6264
php-version: '8.0'
6365
extensions: simplexml, mysql
64-
- name: Checkout source code
65-
uses: actions/checkout@v4
66+
- name: Setup Node
67+
uses: actions/setup-node@v4
68+
with:
69+
node-version: 18
70+
- name: Create the build file
71+
run: |
72+
npm ci
73+
npm run build
6674
- name: Install Composer dependencies
6775
run: composer install --prefer-dist --no-progress --no-suggest
6876
- name: PHPStan Static Analysis
69-
run: composer phpstan
77+
run: composer phpstan

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@
4343
"wp-coding-standards/wpcs": "^3.1.0",
4444
"dealerdirect/phpcodesniffer-composer-installer": "^1.1.2",
4545
"yoast/phpunit-polyfills": "^4.0",
46-
"phpstan/phpstan": "^1.10",
47-
"szepeviktor/phpstan-wordpress": "^1.3",
48-
"php-stubs/wp-cli-stubs": "^2.8"
46+
"phpstan/phpstan": "^2.1",
47+
"php-stubs/wp-cli-stubs": "^2.8",
48+
"szepeviktor/phpstan-wordpress": "^2.0"
4949
},
5050
"scripts": {
5151
"format": "phpcbf --standard=phpcs.xml --report-summary --report-source",
5252
"phpcs": "phpcs --standard=phpcs.xml --extensions=php -s -d memory_limit=-1",
5353
"phpstan": "phpstan analyse --memory-limit=-1",
54+
"phpstan:generate:baseline": "phpstan analyse --memory-limit=-1 --generate-baseline",
5455
"phpunit": "phpunit --configuration=phpunit.xml",
5556
"install-wp-tests": "bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true"
5657
},

composer.lock

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

inc/admin.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,11 @@ public function inline_bootstrap_script() {
576576
/**
577577
* Add settings links in the plugin listing page.
578578
*
579-
* @param array $links Old plugin links.
579+
* @param string[] $links Old plugin links.
580580
*
581-
* @return array Altered links.
581+
* @return string[] Altered links.
582582
*/
583583
public function add_action_links( $links ) {
584-
if ( ! is_array( $links ) ) {
585-
return $links;
586-
}
587-
588584
return array_merge(
589585
$links,
590586
[
@@ -599,7 +595,7 @@ public function add_action_links( $links ) {
599595
* @return bool Should show?
600596
*/
601597
public function should_show_notice() {
602-
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
598+
if ( wp_doing_ajax() ) {
603599
return false;
604600
}
605601

@@ -676,7 +672,7 @@ public function add_notice_upgrade() {
676672
*/
677673
public function should_show_upgrade() {
678674
$current_screen = get_current_screen();
679-
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ||
675+
if ( wp_doing_ajax() ||
680676
is_network_admin() ||
681677
! current_user_can( 'manage_options' ) ||
682678
! $this->settings->is_connected() ||
@@ -1003,7 +999,7 @@ public function maybe_redirect() {
1003999
return;
10041000
}
10051001

1006-
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
1002+
if ( wp_doing_ajax() ) {
10071003
return;
10081004
}
10091005

inc/api.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ public function request( $path, $method = 'GET', $params = [], $extra_headers =
160160
if ( ! empty( $this->api_key ) ) {
161161
$headers['Authorization'] = 'Bearer ' . $this->api_key;
162162
}
163-
if ( is_array( $headers ) ) {
164-
$headers = array_merge( $headers, $extra_headers );
165-
}
163+
$headers = array_merge( $headers, $extra_headers );
166164
$url = trailingslashit( $this->api_root ) . ltrim( $path, '/' );
167165
// If there is a extra, add that as a url var.
168166
if ( 'GET' === $method && ! empty( $params ) ) {

inc/app_replacer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ public static function listen_to_sizes( $value, $orig_w, $orig_h, $dest_w, $dest
490490
/**
491491
* Extract domains and use them as keys for fast processing.
492492
*
493-
* @param array $urls Input urls.
493+
* @param array|null $urls Input urls.
494494
*
495495
* @return array Array of domains as keys.
496496
*/
@@ -529,7 +529,7 @@ function ( $value ) {
529529
/**
530530
* Check if we can replace the url.
531531
*
532-
* @param string $url Url to change.
532+
* @param string|mixed $url Url to change.
533533
*
534534
* @return bool Either we can replace this url or not.
535535
*/
@@ -668,7 +668,7 @@ protected function get_optimized_image_url( $url, $width, $height, $resize = []
668668
->width( $width )
669669
->height( $height );
670670

671-
if ( is_array( $resize ) && ! empty( $resize['type'] ) ) {
671+
if ( ! empty( $resize['type'] ) ) {
672672
$optimized_image->resize( $resize['type'], $resize['gravity'] ?? Position::CENTER, $resize['enlarge'] ?? false );
673673

674674
}

inc/compatibilities/pinterest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function should_load() {
3131
$selectors_array[] = '.heateorSssSharing.heateorSssPinterestBackground';
3232
$load = true;
3333
}
34-
$this->selectors = implode( ', ', array_filter( $selectors_array ) );
34+
$this->selectors = implode( ', ', $selectors_array );
3535
return $load;
3636
}
3737

inc/conflicts/conflicting_plugins.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function dismiss_conflicting_plugins() {
158158
* @return bool Should show?
159159
*/
160160
public function should_show_notice() {
161-
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
161+
if ( wp_doing_ajax() ) {
162162
return false;
163163
}
164164

inc/manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public function replace_content( $html, $partial = false ) {
435435
$hmac = wp_hash( $profile_id . $time, 'nonce' );
436436
$js_optimizer = str_replace(
437437
[ Profile::PLACEHOLDER, Profile::PLACEHOLDER_MISSING, Profile::PLACEHOLDER_TIME, Profile::PLACEHOLDER_HMAC ],
438-
[ $profile_id, implode( ',', $missing ), $time, $hmac ],
438+
[ $profile_id, implode( ',', $missing ), strval( $time ), $hmac ],
439439
$js_optimizer
440440
);
441441
$html = str_replace( Optml_Admin::get_optimizer_script( true ), $js_optimizer, $html );

0 commit comments

Comments
 (0)