Skip to content

Commit fb97bd0

Browse files
authored
Merge pull request elementor#886 from WP2Static/feature/fix-typing
improve typing
2 parents 3248037 + 1e25ec8 commit fb97bd0

22 files changed

+194
-56
lines changed

composer.lock

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

phpstan.neon

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ parameters:
1919
# https://gist.github.com/nicolas-grekas/1028251#improving-native-php-interface
2020
- message: '#^In method "WP2Static\\\S+::\S+", you should not use the \$_(COOKIE|GET|POST) superglobal#'
2121
path: src/Controller.php
22-
count: 6
22+
count: 1
2323
- message: '#^In method "WP2Static\\\S+::\S+", you should not use the \$_(GET|POST) superglobal#'
2424
path: src/CoreOptions.php
25-
count: 25
25+
count: 16
2626
- message: '#^In method "WP2Static\\\S+::\S+", you should not use the \$_(GET|POST) superglobal#'
2727
path: src/ViewRenderer.php
2828
count: 10
@@ -44,4 +44,16 @@ parameters:
4444
- message: "#^Cannot access property \\$\\S+ on mixed\\.$#"
4545
path: views/addons-page.php
4646
count: 7
47+
- message: "#^Cannot access offset \\S+ on mixed\\.$#"
48+
path: src/SitemapParser.php
49+
count: 3
50+
- message: "#^Cannot access property \\S+ on mixed\\.$#"
51+
path: src/Controller.php
52+
count: 6
53+
- message: "#^Cannot access property \\S+ on mixed\\.$#"
54+
path: src/CLI.php
55+
count: 9
56+
- message: "#^Cannot access property \\S+ on mixed\\.$#"
57+
path: src/Addons.php
58+
count: 1
4759
- '/^Parameter #2 \$callable of static method WP_CLI::add_command\(\) expects callable\(\): mixed, \S+ given\.$/'

src/CLI.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ public function diagnostics() : void {
6666
[ 'key', 'value' ]
6767
);
6868

69-
$active_plugins = get_option( 'active_plugins' );
69+
$active_plugins = (array) get_option( 'active_plugins' );
7070

7171
WP_CLI::line( PHP_EOL . 'Active plugins:' . PHP_EOL );
7272

7373
foreach ( $active_plugins as $active_plugin ) {
74+
/**
75+
* @var string $active_plugin
76+
*/
7477
WP_CLI::line( $active_plugin );
7578
}
7679

src/Controller.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,9 @@ public static function wp2staticProcessJobsQueue() : void {
364364
public static function wp2staticDeployCacheDelete() : void {
365365
check_admin_referer( 'wp2static-caches-page' );
366366

367-
if ( isset( $_POST['deploy_namespace'] ) ) {
368-
DeployCache::truncate( $_POST['deploy_namespace'] );
367+
$deploy_namespace = strval( filter_input( INPUT_POST, 'deploy_namespace' ) );
368+
if ( $deploy_namespace !== '' ) {
369+
DeployCache::truncate( $deploy_namespace );
369370
} else {
370371
DeployCache::truncate();
371372
}
@@ -377,11 +378,12 @@ public static function wp2staticDeployCacheDelete() : void {
377378
public static function wp2staticDeployCacheShow() : void {
378379
check_admin_referer( 'wp2static-caches-page' );
379380

380-
if ( isset( $_POST['deploy_namespace'] ) ) {
381+
$deploy_namespace = strval( filter_input( INPUT_POST, 'deploy_namespace' ) );
382+
if ( $deploy_namespace !== '' ) {
381383
wp_safe_redirect(
382384
admin_url(
383385
'admin.php?page=wp2static-deploy-cache&deploy_namespace=' .
384-
urlencode( $_POST['deploy_namespace'] )
386+
urlencode( $deploy_namespace )
385387
)
386388
);
387389
} else {
@@ -515,7 +517,7 @@ public static function wp2staticToggleAddon( string $addon_slug = null ) : void
515517
} else {
516518
check_admin_referer( 'wp2static-addons-page' );
517519

518-
$addon_slug = sanitize_text_field( $_POST['addon_slug'] );
520+
$addon_slug = sanitize_text_field( strval( filter_input( INPUT_POST, 'addon_slug' ) ) );
519521
}
520522

521523
global $wpdb;

src/CoreOptions.php

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ public static function get( string $name ) {
524524
if ( $option ) {
525525
$option->unfiltered_value = $option->value;
526526
$option->value = apply_filters( (string) $opt_spec['filter_name'], $option->value );
527+
/** @phpstan-ignore-next-line */
527528
} elseif ( $opt_spec ) {
528529
$opt = array_merge( $opt_spec ); // Make a copy so we don't modify $cached_option_specs
529530
$opt['unfiltered_value'] = $opt_spec['default_value'];
@@ -599,11 +600,16 @@ public static function getAll() {
599600
public static function encrypt_decrypt( string $action, string $string ) : string {
600601
$encrypt_method = 'AES-256-CBC';
601602

603+
/**
604+
* @var string $secret_key
605+
*/
602606
$secret_key =
603607
defined( 'AUTH_KEY' ) ?
604608
constant( 'AUTH_KEY' ) :
605609
'LC>_cVZv34+W.P&_8d|ejfr]d31h)J?z5n(LB6iY=;P@?5/qzJSyB3qctr,.D$[L';
606-
610+
/**
611+
* @var string $secret_iv
612+
*/
607613
$secret_iv =
608614
defined( 'AUTH_SALT' ) ?
609615
constant( 'AUTH_SALT' ) :
@@ -665,13 +671,21 @@ public static function savePosted( string $screen = 'core' ) : void {
665671

666672
$wpdb->update(
667673
$table_name,
668-
[ 'value' => esc_url_raw( $_POST['deploymentURL'] ) ],
674+
[
675+
'value' =>
676+
esc_url_raw( strval( filter_input( INPUT_POST, 'deploymentURL' ) ) ),
677+
],
669678
[ 'name' => 'deploymentURL' ]
670679
);
671680

672681
$wpdb->update(
673682
$table_name,
674-
[ 'value' => sanitize_text_field( $_POST['basicAuthUser'] ) ],
683+
[
684+
'value' =>
685+
sanitize_text_field(
686+
strval( filter_input( INPUT_POST, 'basicAuthUser' ) )
687+
),
688+
],
675689
[ 'name' => 'basicAuthUser' ]
676690
);
677691

@@ -681,7 +695,9 @@ public static function savePosted( string $screen = 'core' ) : void {
681695
'value' =>
682696
self::encrypt_decrypt(
683697
'encrypt',
684-
sanitize_text_field( $_POST['basicAuthPassword'] )
698+
sanitize_text_field(
699+
strval( filter_input( INPUT_POST, 'basicAuthPassword' ) )
700+
)
685701
),
686702
],
687703
[ 'name' => 'basicAuthPassword' ]
@@ -695,19 +711,32 @@ public static function savePosted( string $screen = 'core' ) : void {
695711

696712
$wpdb->update(
697713
$table_name,
698-
[ 'value' => sanitize_email( $_POST['completionEmail'] ) ],
714+
[
715+
'value' =>
716+
sanitize_text_field(
717+
strval( filter_input( INPUT_POST, 'completionEmail' ) )
718+
),
719+
],
699720
[ 'name' => 'completionEmail' ]
700721
);
701722

702723
$wpdb->update(
703724
$table_name,
704-
[ 'value' => esc_url_raw( $_POST['completionWebhook'] ) ],
725+
[
726+
'value' =>
727+
esc_url_raw( strval( filter_input( INPUT_POST, 'completionWebhook' ) ) ),
728+
],
705729
[ 'name' => 'completionWebhook' ]
706730
);
707731

708732
$wpdb->update(
709733
$table_name,
710-
[ 'value' => sanitize_text_field( $_POST['completionWebhookMethod'] ) ],
734+
[
735+
'value' =>
736+
sanitize_text_field(
737+
strval( filter_input( INPUT_POST, 'completionWebhookMethod' ) )
738+
),
739+
],
711740
[ 'name' => 'completionWebhookMethod' ]
712741
);
713742

@@ -735,6 +764,9 @@ public static function savePosted( string $screen = 'core' ) : void {
735764
[ 'name' => 'processQueueImmediately' ]
736765
);
737766

767+
/**
768+
* @var int $process_queue_interval
769+
*/
738770
$process_queue_interval =
739771
isset( $_POST['processQueueInterval'] ) ?
740772
$_POST['processQueueInterval'] : 0;
@@ -783,7 +815,7 @@ public static function savePosted( string $screen = 'core' ) : void {
783815
$file_extensions_to_ignore = preg_replace(
784816
'/^\s+|\s+$/m',
785817
'',
786-
$_POST['fileExtensionsToIgnore']
818+
strval( filter_input( INPUT_POST, 'fileExtensionsToIgnore' ) )
787819
);
788820
$wpdb->update(
789821
$table_name,
@@ -794,7 +826,7 @@ public static function savePosted( string $screen = 'core' ) : void {
794826
$filenames_to_ignore = preg_replace(
795827
'/^\s+|\s+$/m',
796828
'',
797-
$_POST['filenamesToIgnore']
829+
strval( filter_input( INPUT_POST, 'filenamesToIgnore' ) )
798830
);
799831
$wpdb->update(
800832
$table_name,
@@ -805,7 +837,7 @@ public static function savePosted( string $screen = 'core' ) : void {
805837
$hosts_to_rewrite = preg_replace(
806838
'/^\s+|\s+$/m',
807839
'',
808-
$_POST['hostsToRewrite']
840+
strval( filter_input( INPUT_POST, 'hostsToRewrite' ) )
809841
);
810842
$wpdb->update(
811843
$table_name,

src/DetectAuthorPaginationURLs.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public static function detect( string $wp_site_url ) : array {
1717
$urls_to_include = [];
1818
$users = get_users();
1919
$pagination_base = $wp_rewrite->pagination_base;
20+
21+
/**
22+
* @var int $default_posts_per_page
23+
*/
2024
$default_posts_per_page = get_option( 'posts_per_page' );
2125

2226
foreach ( $users as $author ) {
@@ -40,6 +44,10 @@ public static function detect( string $wp_site_url ) : array {
4044
}
4145

4246
foreach ( $authors_urls as $author => $total_posts ) {
47+
/**
48+
* @var int $total_posts
49+
*/
50+
4351
$total_pages = ceil( $total_posts / $default_posts_per_page );
4452

4553
for ( $page = 1; $page <= $total_pages; $page++ ) {

src/DetectCategoryPaginationURLs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static function detect() : array {
2626
foreach ( $taxonomies as $taxonomy ) {
2727
/** @var list<\WP_Term> $terms */
2828
$terms = get_terms(
29+
// @phpstan-ignore-next-line
2930
$taxonomy->name,
3031
[ 'hide_empty' => true ]
3132
);

src/DetectCategoryURLs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static function detect() : array {
2121
foreach ( $taxonomies as $taxonomy ) {
2222
/** @var list<\WP_Term> $terms */
2323
$terms = get_terms(
24+
// @phpstan-ignore-next-line
2425
$taxonomy->name,
2526
[ 'hide_empty' => true ]
2627
);

0 commit comments

Comments
 (0)