Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion classes/controllers/FrmAddonsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ public static function connect_link() {

if ( ! $auth ) {
$auth = hash( 'sha512', wp_rand() );
update_option( 'frm_connect_token', $auth, 'no' );
update_option( 'frm_connect_token', $auth, false );
}

$page = FrmAppHelper::simple_get( 'page', 'sanitize_title', 'formidable-settings' );
Expand Down
2 changes: 1 addition & 1 deletion classes/controllers/FrmAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ public static function api_install() {
$running = get_option( 'frm_install_running' );

if ( false === $running || $running < strtotime( '-5 minutes' ) ) {
update_option( 'frm_install_running', time(), 'no' );
update_option( 'frm_install_running', time(), false );
self::install();
delete_option( 'frm_install_running' );
}
Expand Down
2 changes: 1 addition & 1 deletion classes/controllers/FrmDashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ private static function get_dashboard_options( $option_name = null ) {
private static function update_dashboard_options( $data, $option_name ) {
$options = self::get_dashboard_options();
$options[ $option_name ] = $data;
update_option( self::OPTION_META_NAME, $options, 'no' );
update_option( self::OPTION_META_NAME, $options, false );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions classes/controllers/FrmOnboardingWizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public static function has_onboarding_been_skipped() {
* @return void
*/
public static function mark_onboarding_as_skipped() {
update_option( self::ONBOARDING_SKIPPED_OPTION, true, 'no' );
update_option( self::ONBOARDING_SKIPPED_OPTION, true, false );
}

/**
Expand Down Expand Up @@ -507,7 +507,7 @@ private static function has_already_redirected() {
return true;
}

update_option( self::REDIRECT_STATUS_OPTION, FrmAppHelper::plugin_version(), 'no' );
update_option( self::REDIRECT_STATUS_OPTION, FrmAppHelper::plugin_version(), false );
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/controllers/FrmOverlayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private function get_options_data() {
* @return void
*/
private function update_options_data() {
update_option( $this->option_meta_name, $this->options_data, 'no' );
update_option( $this->option_meta_name, $this->options_data, false );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/controllers/FrmSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public static function settings_cta_dismiss() {
check_ajax_referer( 'frm_ajax', 'nonce' );
FrmAppHelper::permission_check( 'frm_change_settings' );

update_option( 'frm_lite_settings_upgrade', time(), 'no' );
update_option( 'frm_lite_settings_upgrade', time(), false );

wp_send_json_success();
}
Expand Down
2 changes: 1 addition & 1 deletion classes/helpers/FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4882,7 +4882,7 @@ public static function dismiss_warning_message( $option = '' ) {
check_ajax_referer( 'frm_ajax', 'nonce' );

if ( $option ) {
update_option( $option, true, 'no' );
update_option( $option, true, false );
}

wp_send_json_success();
Expand Down
2 changes: 1 addition & 1 deletion classes/helpers/FrmFormMigratorsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public static function dismiss_migrator() {
}

$dismissed[] = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
update_option( 'frm_dismissed', array_filter( $dismissed ), 'no' );
update_option( 'frm_dismissed', array_filter( $dismissed ), false );
wp_die();
}
}
2 changes: 1 addition & 1 deletion classes/models/FrmFormState.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private static function get_encryption_secret() {

// We don't have a secret, so let's generate one.
$secret_key = is_callable( 'sodium_crypto_secretbox_keygen' ) ? sodium_crypto_secretbox_keygen() : wp_generate_password( 32, true, true );
update_option( 'frm_form_state_key', base64_encode( $secret_key ), 'no' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
update_option( 'frm_form_state_key', base64_encode( $secret_key ), false ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode

return $secret_key;
}
Expand Down
2 changes: 1 addition & 1 deletion classes/models/FrmFormTemplateApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function skip_categories() {
* @return void
*/
public static function set_free_license_code( $code ) {
update_option( self::$code_option_name, $code, 'no' );
update_option( self::$code_option_name, $code, false );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/models/FrmInbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public function remove( $key ) {
* @return void
*/
private function update_list() {
update_option( $this->option, self::$messages, 'no' );
update_option( $this->option, self::$messages, false );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/models/FrmPluginSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ protected function get_dismissed_hints() {
*/
protected function add_to_dismissed_hints( $hint ) {
$hints = array_merge( $this->get_dismissed_hints(), array( $hint ) );
return update_option( self::$dismissed_opt, $hints, 'no' );
return update_option( self::$dismissed_opt, $hints, false );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/models/FrmSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private function translate_settings( $settings ) {
// If unserializing didn't work.
$settings = $this;

update_option( $this->option_name, $settings, 'yes' );
update_option( $this->option_name, $settings, true );

return $settings;
}
Expand Down
2 changes: 1 addition & 1 deletion classes/models/FrmStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public function save_settings() {
);
$create_file->create_file( $css );

update_option( 'frmpro_css', $css, 'no' );
update_option( 'frmpro_css', $css, false );
set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS );
}

Expand Down
2 changes: 1 addition & 1 deletion classes/models/FrmUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function uuid( $regenerate = false ) {
// Definitely not cryptographically secure but
// close enough to provide a unique id
$uuid = md5( uniqid() . site_url() );
update_option( $uuid_key, $uuid, 'no' );
update_option( $uuid_key, $uuid, false );
}

return $uuid;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?php
/**
* Ensure update_option autoload flag uses booleans instead of strings.
*
* @package Formidable\Sniffs\CodeAnalysis
*/

namespace Formidable\Sniffs\CodeAnalysis;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

/**
* Converts `update_option( ..., 'yes' )`/`'no'` autoload values to bool true/false.
*/
class UpdateOptionAutoloadBooleanSniff implements Sniff {

/**
* {@inheritdoc}
*/
public function register() {
return array( T_STRING );
}

/**
* {@inheritdoc}
*/
public function process( File $phpcsFile, $stackPtr ) {
$tokens = $phpcsFile->getTokens();

if ( strtolower( $tokens[ $stackPtr ]['content'] ) !== 'update_option' ) {
return;
}

$openParen = $phpcsFile->findNext( T_WHITESPACE, $stackPtr + 1, null, true );

if ( false === $openParen || $tokens[ $openParen ]['code'] !== T_OPEN_PARENTHESIS ) {
return;
}

$arguments = $this->getFunctionArguments( $phpcsFile, $openParen );

if ( count( $arguments ) < 3 ) {
return;
}

$autoloadArg = $arguments[2];
$value = $this->normalizeLiteral( $phpcsFile, $autoloadArg );

if ( null === $value ) {
return;
}

$replacement = ( $value === 'yes' ) ? 'true' : 'false';

$fix = $phpcsFile->addFixableError(
sprintf( 'update_option autoload flag should be boolean, found string \'%s\'.', $value ),
$autoloadArg['start'],
'AutoloadString'
);

if ( true === $fix ) {
$this->replaceArgumentWithBoolean( $phpcsFile, $autoloadArg, $replacement );
}
}

/**
* Convert a literal argument to yes/no string if applicable.
*
* @param File $phpcsFile File reference.
* @param array $argument Argument boundaries.
*
* @return string|null
*/
private function normalizeLiteral( File $phpcsFile, array $argument ) {
$content = trim( $phpcsFile->getTokensAsString( $argument['start'], $argument['end'] - $argument['start'] + 1 ) );

// Only match quoted strings.
if ( strlen( $content ) < 2 || $content[0] !== $content[ strlen( $content ) - 1 ] || ( $content[0] !== '\'' && $content[0] !== '"' ) ) {
return null;
}

$value = trim( substr( $content, 1, -1 ) );
$value = strtolower( $value );

if ( in_array( $value, array( 'yes', 'no' ), true ) ) {
return $value;
}

return null;
}

/**
* Replace the argument tokens with the boolean literal.
*
* @param File $phpcsFile File reference.
* @param array $argument Argument boundaries.
* @param string $replacement Replacement text.
*
* @return void
*/
private function replaceArgumentWithBoolean( File $phpcsFile, array $argument, $replacement ) {
$fixer = $phpcsFile->fixer;
$fixer->beginChangeset();

for ( $i = $argument['start']; $i <= $argument['end']; $i++ ) {
if ( $i === $argument['start'] ) {
$fixer->replaceToken( $i, $replacement );
continue;
}

$fixer->replaceToken( $i, '' );
}

$fixer->endChangeset();
}

/**
* Basic function argument parser.
*
* @param File $phpcsFile File reference.
* @param int $openParen Position of the opening parenthesis.
*
* @return array<int, array{start:int,end:int}>
*/
private function getFunctionArguments( File $phpcsFile, $openParen ) {
$tokens = $phpcsFile->getTokens();
$arguments = array();

if ( ! isset( $tokens[ $openParen ]['parenthesis_closer'] ) ) {
return $arguments;
}

$closeParen = $tokens[ $openParen ]['parenthesis_closer'];
$argStart = null;

$level = 0;

for ( $i = $openParen + 1; $i < $closeParen; $i++ ) {
$code = $tokens[ $i ]['code'];

if ( $code === T_OPEN_PARENTHESIS || $code === T_OPEN_SHORT_ARRAY || $code === T_OPEN_SQUARE_BRACKET ) {
$level++;
} elseif ( $code === T_CLOSE_PARENTHESIS || $code === T_CLOSE_SQUARE_BRACKET ) {
$level--;
}
Comment on lines +142 to +146
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing T_CLOSE_SHORT_ARRAY in level decrement.

The level tracking correctly increments for T_OPEN_SHORT_ARRAY but the decrement only handles T_CLOSE_PARENTHESIS and T_CLOSE_SQUARE_BRACKET. This could cause incorrect argument parsing for code containing short array syntax [...].

🐛 Proposed fix
 			if ( $code === T_OPEN_PARENTHESIS || $code === T_OPEN_SHORT_ARRAY || $code === T_OPEN_SQUARE_BRACKET ) {
 				$level++;
-			} elseif ( $code === T_CLOSE_PARENTHESIS || $code === T_CLOSE_SQUARE_BRACKET ) {
+			} elseif ( $code === T_CLOSE_PARENTHESIS || $code === T_CLOSE_SQUARE_BRACKET || $code === T_CLOSE_SHORT_ARRAY ) {
 				$level--;
 			}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if ( $code === T_OPEN_PARENTHESIS || $code === T_OPEN_SHORT_ARRAY || $code === T_OPEN_SQUARE_BRACKET ) {
$level++;
} elseif ( $code === T_CLOSE_PARENTHESIS || $code === T_CLOSE_SQUARE_BRACKET ) {
$level--;
}
if ( $code === T_OPEN_PARENTHESIS || $code === T_OPEN_SHORT_ARRAY || $code === T_OPEN_SQUARE_BRACKET ) {
$level++;
} elseif ( $code === T_CLOSE_PARENTHESIS || $code === T_CLOSE_SQUARE_BRACKET || $code === T_CLOSE_SHORT_ARRAY ) {
$level--;
}
🤖 Prompt for AI Agents
In
`@phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/UpdateOptionAutoloadBooleanSniff.php`
around lines 142 - 146, The level tracking in UpdateOptionAutoloadBooleanSniff
is incrementing for T_OPEN_SHORT_ARRAY but not decrementing for its counterpart;
update the conditional that decrements $level (currently checking
T_CLOSE_PARENTHESIS and T_CLOSE_SQUARE_BRACKET) to also check for
T_CLOSE_SHORT_ARRAY so short-array brackets "[]" properly balance with the
T_OPEN_SHORT_ARRAY token during argument parsing.


$nextIsSeparator = ( $code === T_COMMA && 0 === $level );

if ( false === $argStart ) {
continue;
}
Comment on lines +150 to +152
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Type mismatch in comparison - $argStart initialized as null but compared to false.

$argStart is initialized as null on line 135, but the condition on line 150 checks false === $argStart. In PHP, false === null evaluates to false, so this condition will never be true. This appears to be dead code or a bug.

🐛 Proposed fix
-			if ( false === $argStart ) {
+			if ( null === $argStart && $tokens[ $i ]['code'] === T_WHITESPACE ) {
 				continue;
 			}

Or simply remove this block if the intent is already handled by line 169's condition.

🤖 Prompt for AI Agents
In
`@phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/UpdateOptionAutoloadBooleanSniff.php`
around lines 150 - 152, The condition using "false === $argStart" in
UpdateOptionAutoloadBooleanSniff is wrong because $argStart is initialized to
null, so update the check to "null === $argStart" (or "! isset($argStart)" /
"$argStart === null") so the condition can ever be true, or simply remove the
entire "false === $argStart" branch if the later null-check already covers this
case; target the comparison using the $argStart variable and the existing "false
=== $argStart" expression for the change.


if ( $nextIsSeparator || $i === $closeParen - 1 ) {
$end = $nextIsSeparator ? $i - 1 : $i;

while ( $end >= $argStart && $tokens[ $end ]['code'] === T_WHITESPACE ) {
$end--;
}

if ( $argStart <= $end && $tokens[ $argStart ]['code'] !== T_COMMA ) {
$arguments[] = array(
'start' => $argStart,
'end' => $end,
);
}

$argStart = null;
} elseif ( null === $argStart && $tokens[ $i ]['code'] !== T_WHITESPACE ) {
$argStart = $i;
}
}

return $arguments;
}
}
1 change: 1 addition & 0 deletions phpcs-sniffs/Formidable/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<rule ref="Formidable.CodeAnalysis.FlipLargeIfSmallElse" />
<rule ref="Formidable.CodeAnalysis.FlipLoopIfElseToContinue" />
<rule ref="Formidable.CodeAnalysis.CheckFunctionCallable" />
<rule ref="Formidable.CodeAnalysis.UpdateOptionAutoloadBoolean" />

<!-- PHPUnit -->
<rule ref="Formidable.PHPUnit.PreferAssertIsArray" />
Expand Down
14 changes: 7 additions & 7 deletions square/helpers/FrmSquareLiteConnectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static function get_oauth_redirect_url() {
}

if ( ! empty( $data->password ) ) {
update_option( self::get_server_side_token_option_name( $mode ), $data->password, 'no' );
update_option( self::get_server_side_token_option_name( $mode ), $data->password, false );
}

if ( ! is_object( $data ) || empty( $data->redirect_url ) ) {
Expand Down Expand Up @@ -355,7 +355,7 @@ private static function get_server_side_token_option_name( $mode = 'auto' ) {
*/
private static function generate_client_password( $mode ) {
$client_password = wp_generate_password();
update_option( self::get_client_side_token_option_name( $mode ), $client_password, 'no' );
update_option( self::get_client_side_token_option_name( $mode ), $client_password, false );
return $client_password;
}

Expand Down Expand Up @@ -484,17 +484,17 @@ private static function check_server_for_oauth_merchant_id() {
$data = self::post_to_connect_server( 'oauth_merchant_status', $body );

if ( is_object( $data ) && ! empty( $data->merchant_id ) ) {
update_option( self::get_merchant_id_option_name( $mode ), $data->merchant_id, 'no' );
update_option( self::get_merchant_id_option_name( $mode ), $data->merchant_id, false );

$currency = self::get_merchant_currency( true, $mode );
$location_id = self::get_location_id( true, $mode );

if ( $currency ) {
update_option( self::get_merchant_currency_option_name( $mode ), $currency, 'no' );
update_option( self::get_merchant_currency_option_name( $mode ), $currency, false );
}

if ( $location_id ) {
update_option( self::get_location_id_option_name( $mode ), $location_id, 'no' );
update_option( self::get_location_id_option_name( $mode ), $location_id, false );
}

FrmTransLiteAppController::install();
Expand Down Expand Up @@ -634,7 +634,7 @@ public static function get_location_id( $force = false, $mode = 'auto' ) {
$response = self::post_with_authenticated_body( 'get_location_id', $request_body );

if ( is_object( $response ) ) {
update_option( self::get_location_id_option_name( $mode ), $response->id, 'no' );
update_option( self::get_location_id_option_name( $mode ), $response->id, false );
return $response->id;
}

Expand Down Expand Up @@ -768,7 +768,7 @@ public static function get_merchant_currency( $force = false, $mode = 'auto' ) {
$response = self::post_with_authenticated_body( 'get_merchant_currency', $request_body );

if ( is_object( $response ) && ! empty( $response->currency ) ) {
update_option( self::get_merchant_currency_option_name( $mode ), $response->currency, 'no' );
update_option( self::get_merchant_currency_option_name( $mode ), $response->currency, false );
return $response->currency;
}

Expand Down
Loading