Upgrade PHPStan to 2.x and raise analysis level from 6 to 10
CI / No Debug Code (pull_request) Successful in 3s
CI / Tests (PHP 8.2) (pull_request) Successful in 48s
CI / Tests (PHP 8.3) (pull_request) Successful in 52s
CI / Coding Standards (pull_request) Successful in 57s
CI / Tests (PHP 8.1) (pull_request) Successful in 1m1s
CI / PHPStan (pull_request) Successful in 1m11s
CI / Build Plugin Zip (pull_request) Has been skipped
CI / No Debug Code (pull_request) Successful in 3s
CI / Tests (PHP 8.2) (pull_request) Successful in 48s
CI / Tests (PHP 8.3) (pull_request) Successful in 52s
CI / Coding Standards (pull_request) Successful in 57s
CI / Tests (PHP 8.1) (pull_request) Successful in 1m1s
CI / PHPStan (pull_request) Successful in 1m11s
CI / Build Plugin Zip (pull_request) Has been skipped
- Bump phpstan/phpstan ^2.0 and szepeviktor/phpstan-wordpress ^2.0 - Move the analysis level into phpstan.neon (single source) and raise it to 10 - Add Val, a runtime coercion helper that narrows untyped WordPress boundary values (wpdb rows, REST params, superglobals, options) with explicit checks instead of blind casts, plus unit tests - Type value-object fromRow() params as stdClass (what wpdb returns) and map columns through Val so unexpected shapes degrade safely - Use %i identifier placeholders for table names in all wpdb::prepare() calls so every query string is a literal and identifiers are escaped by WordPress; raises the minimum WordPress version to 6.2 where %i was introduced - Guard wpdb::prepare() null result before wpdb::query() in updateTax() - Fix nullable get_permalink()/strtotime() handling, list types at REST and capability call sites, dead null-coalescing on checked superglobals, and narrow get_users() results before mapping - Register Val method names with the ValidatedSanitizedInput sniff so it validates the real sanitizer around each superglobal read - Update repository unit tests for the %i placeholder arguments Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace Unsupervised\Schedular\Payment;
|
||||
|
||||
use Unsupervised\Schedular\Auth\RoleManager;
|
||||
use Unsupervised\Schedular\Val;
|
||||
|
||||
class StudioSettings {
|
||||
|
||||
@@ -16,11 +17,11 @@ class StudioSettings {
|
||||
public const OPT_HST_RATE = 'us_hst_rate';
|
||||
|
||||
public function publishableKey(): string {
|
||||
return (string) get_option( self::OPT_PUBLISHABLE, '' );
|
||||
return Val::string( get_option( self::OPT_PUBLISHABLE, '' ) );
|
||||
}
|
||||
|
||||
public function secretKey(): string {
|
||||
return (string) get_option( self::OPT_SECRET, '' );
|
||||
return Val::string( get_option( self::OPT_SECRET, '' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,7 @@ class StudioSettings {
|
||||
* webhook requests genuinely came from Stripe. Empty until configured.
|
||||
*/
|
||||
public function webhookSecret(): string {
|
||||
return (string) get_option( self::OPT_WEBHOOK_SECRET, '' );
|
||||
return Val::string( get_option( self::OPT_WEBHOOK_SECRET, '' ) );
|
||||
}
|
||||
|
||||
public function mode(): string {
|
||||
@@ -36,7 +37,7 @@ class StudioSettings {
|
||||
}
|
||||
|
||||
public function currency(): string {
|
||||
$currency = (string) get_option( self::OPT_CURRENCY, 'CAD' );
|
||||
$currency = Val::string( get_option( self::OPT_CURRENCY, 'CAD' ) );
|
||||
|
||||
return '' !== $currency ? strtoupper( $currency ) : 'CAD';
|
||||
}
|
||||
@@ -46,14 +47,14 @@ class StudioSettings {
|
||||
* no override).
|
||||
*/
|
||||
public function etransferEmail(): string {
|
||||
return (string) get_option( self::OPT_ETRANSFER_EMAIL, '' );
|
||||
return Val::string( get_option( self::OPT_ETRANSFER_EMAIL, '' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Default HST/tax rate as a percentage (e.g. 13.0). 0 means no tax.
|
||||
*/
|
||||
public function hstRate(): float {
|
||||
return max( 0.0, (float) get_option( self::OPT_HST_RATE, 0 ) );
|
||||
return max( 0.0, Val::float( get_option( self::OPT_HST_RATE, 0 ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,22 +93,23 @@ class StudioSettings {
|
||||
private function save(): void {
|
||||
// Nonce is verified by the caller (renderPage) before this method runs.
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
$mode = sanitize_key( wp_unslash( $_POST['mode'] ?? 'test' ) );
|
||||
update_option( self::OPT_PUBLISHABLE, sanitize_text_field( wp_unslash( $_POST['publishable_key'] ?? '' ) ) );
|
||||
$mode = sanitize_key( Val::string( wp_unslash( $_POST['mode'] ?? 'test' ) ) );
|
||||
update_option( self::OPT_PUBLISHABLE, sanitize_text_field( Val::string( wp_unslash( $_POST['publishable_key'] ?? '' ) ) ) );
|
||||
// Secret fields are write-only: a blank submission keeps the stored secret,
|
||||
// so an admin saving other settings never wipes the keys.
|
||||
$secretKey = sanitize_text_field( wp_unslash( $_POST['secret_key'] ?? '' ) );
|
||||
$secretKey = sanitize_text_field( Val::string( wp_unslash( $_POST['secret_key'] ?? '' ) ) );
|
||||
if ( '' !== $secretKey ) {
|
||||
update_option( self::OPT_SECRET, $secretKey );
|
||||
}
|
||||
$webhookSecret = sanitize_text_field( wp_unslash( $_POST['webhook_secret'] ?? '' ) );
|
||||
$webhookSecret = sanitize_text_field( Val::string( wp_unslash( $_POST['webhook_secret'] ?? '' ) ) );
|
||||
if ( '' !== $webhookSecret ) {
|
||||
update_option( self::OPT_WEBHOOK_SECRET, $webhookSecret );
|
||||
}
|
||||
update_option( self::OPT_MODE, 'live' === $mode ? 'live' : 'test' );
|
||||
update_option( self::OPT_CURRENCY, strtoupper( sanitize_text_field( wp_unslash( $_POST['currency'] ?? 'CAD' ) ) ) );
|
||||
update_option( self::OPT_ETRANSFER_EMAIL, sanitize_email( wp_unslash( $_POST['etransfer_email'] ?? '' ) ) );
|
||||
$hstRate = isset( $_POST['hst_rate'] ) ? (float) $_POST['hst_rate'] : 0.0;
|
||||
update_option( self::OPT_CURRENCY, strtoupper( sanitize_text_field( Val::string( wp_unslash( $_POST['currency'] ?? 'CAD' ) ) ) ) );
|
||||
update_option( self::OPT_ETRANSFER_EMAIL, sanitize_email( Val::string( wp_unslash( $_POST['etransfer_email'] ?? '' ) ) ) );
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Val::float() coerces to float; slashes cannot survive numeric coercion.
|
||||
$hstRate = isset( $_POST['hst_rate'] ) ? Val::float( $_POST['hst_rate'] ) : 0.0;
|
||||
update_option( self::OPT_HST_RATE, max( 0.0, $hstRate ) );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user