Skip to content

Commit 26d4f57

Browse files
committed
adjust typing for CoreOptions
1 parent 2d33987 commit 26d4f57

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ parameters:
2222
count: 6
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

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,

0 commit comments

Comments
 (0)