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: 0 additions & 2 deletions classes/controllers/FrmAddonsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ public static function license_settings() {

if ( ! $plugins ) {
esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );

return;
}

Expand Down Expand Up @@ -1546,7 +1545,6 @@ private static function allowed_external_urls() {

if ( ! is_array( $allowed_url_list ) ) {
_doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' );

return array();
}

Expand Down
4 changes: 0 additions & 4 deletions classes/controllers/FrmFormsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,6 @@ public static function delete_all() {

if ( $permission_error !== false ) {
self::display_forms_list( array(), '', array( $permission_error ) );

return;
}

Expand Down Expand Up @@ -2027,23 +2026,20 @@ public static function process_bulk_form_actions( $errors ) {

if ( $bulkaction && str_starts_with( $bulkaction, 'bulk_' ) ) {
FrmAppHelper::remove_get_action();

$bulkaction = str_replace( 'bulk_', '', $bulkaction );
}

$ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );

if ( ! $ids ) {
$errors[] = __( 'No forms were specified', 'formidable' );

return $errors;
}

$permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );

if ( $permission_error !== false ) {
$errors[] = $permission_error;

return $errors;
}

Expand Down
2 changes: 0 additions & 2 deletions classes/helpers/FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,6 @@ public static function post_edit_link( $post_id ) {

if ( $post ) {
$post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );

return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
}

Expand Down Expand Up @@ -2389,7 +2388,6 @@ public static function permission_check( $permission, $show_message = 'show' ) {
public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
if ( $permission && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
$frm_settings = self::get_settings();

return $frm_settings->admin_permission;
}

Expand Down
1 change: 0 additions & 1 deletion classes/helpers/FrmEntriesListHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ public function no_items() {

if ( $s ) {
esc_html_e( 'No Entries Found', 'formidable' );

return;
}

Expand Down
1 change: 0 additions & 1 deletion classes/helpers/FrmFormsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,6 @@ public static function get_plan_required( &$item ) {
foreach ( $item['categories'] as $k => $category ) {
if ( in_array( $category, $plans, true ) ) {
unset( $item['categories'][ $k ] );

return self::convert_legacy_package_names( $category );
}
}
Expand Down
1 change: 0 additions & 1 deletion classes/helpers/FrmXMLHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,6 @@ private static function remove_default_html( $html_name, $defaults, &$options )
// phpcs:ignore Universal.Operators.StrictComparisons
if ( $old_html == $default_html ) {
unset( $options[ $html_name ] );

return;
}

Expand Down
1 change: 0 additions & 1 deletion classes/models/FrmAddon.php
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,6 @@ private function get_license_status() {

if ( empty( $this->license ) ) {
$response['error'] = false;

return $response;
}

Expand Down
1 change: 0 additions & 1 deletion classes/models/FrmCreateFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public function append_file( $file_content ) {
if ( $this->has_permission ) {

if ( file_exists( $this->new_file_path ) ) {

$existing_content = $this->get_contents();
$file_content = $existing_content . $file_content;
}
Expand Down
1 change: 0 additions & 1 deletion classes/models/FrmEntryMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ public static function get_entry_meta_by_field( $entry_id, $field_id ) {

if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) {
$result = $cached->metas[ $field_id ];

return wp_unslash( $result );
}

Expand Down
4 changes: 1 addition & 3 deletions classes/models/FrmEntryValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public static function validate( $values, $exclude = false ) {

if ( ! isset( $values['form_id'] ) || ! isset( $values['item_meta'] ) ) {
$errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' );

return $errors;
}

Expand Down Expand Up @@ -1128,8 +1127,7 @@ private static function get_all_form_ids_and_flatten_meta( &$values ) { // phpcs

// Convert name array to string.
if ( isset( $subsubvalue['first'] ) && isset( $subsubvalue['last'] ) ) {
$subsubvalue = trim( implode( ' ', $subsubvalue ) );

$subsubvalue = trim( implode( ' ', $subsubvalue ) );
$values['name_field_ids'][] = $subsubindex;
}

Expand Down
3 changes: 1 addition & 2 deletions classes/models/FrmFieldValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ public function get_displayed_value() {
*/
protected function generate_displayed_value_for_field_type( $atts ) {
if ( ! FrmAppHelper::is_empty_value( $this->displayed_value, '' ) ) {
$field_obj = FrmFieldFactory::get_field_object( $this->field );

$field_obj = FrmFieldFactory::get_field_object( $this->field );
$this->displayed_value = $field_obj->get_display_value( $this->displayed_value, $atts );
}
}
Expand Down
3 changes: 1 addition & 2 deletions classes/models/FrmStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,7 @@ public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
}//end foreach

if ( ! $default_style ) {
$default_style = reset( $styles );

$default_style = reset( $styles );
$styles[ $default_style->ID ]->menu_order = 1;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* Formidable_Sniffs_WhiteSpace_NoBlankLineInShortIfSniff
*
* Removes blank lines inside if blocks that are exactly 3 lines.
*
* @package Formidable\Sniffs
*/

namespace Formidable\Sniffs\WhiteSpace;

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

/**
* Removes blank lines inside if blocks that are exactly 3 lines.
*
* Bad:
* if ( $condition ) {
* do_something();
*
* return;
* }
*
* Good:
* if ( $condition ) {
* do_something();
* return;
* }
*/
class NoBlankLineInShortIfSniff implements Sniff {

/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register() {
return array( T_IF, T_ELSEIF, T_ELSE );
}

/**
* Processes this test, when one of its tokens is encountered.
*
* @param File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
*
* @return void
*/
public function process( File $phpcsFile, $stackPtr ) {
$tokens = $phpcsFile->getTokens();

// Make sure this if/else has a scope (curly braces).
if ( ! isset( $tokens[ $stackPtr ]['scope_opener'] ) || ! isset( $tokens[ $stackPtr ]['scope_closer'] ) ) {
return;
}

$scopeOpener = $tokens[ $stackPtr ]['scope_opener'];
$scopeCloser = $tokens[ $stackPtr ]['scope_closer'];

// Calculate the number of lines in the block body.
$openerLine = $tokens[ $scopeOpener ]['line'];
$closerLine = $tokens[ $scopeCloser ]['line'];

// Body lines = closerLine - openerLine - 1.
// We want to trigger when there are exactly 3 body lines (2 code + 1 blank).
// This means the if block has 2 statements but a blank line between them.
$bodyLines = $closerLine - $openerLine - 1;

// Only process if the body is exactly 3 lines (2 code lines + 1 blank line).
if ( $bodyLines !== 3 ) {
return;
}

// Find if there's a blank line inside the block.
// A blank line is a whitespace token that contains 2+ consecutive newlines.
$blankLineToken = null;

for ( $i = $scopeOpener + 1; $i < $scopeCloser; $i++ ) {
if ( $tokens[ $i ]['code'] === T_WHITESPACE ) {
$content = $tokens[ $i ]['content'];
$newlineCount = substr_count( $content, "\n" );

// If this whitespace has 2+ newlines, it contains a blank line.
if ( $newlineCount >= 2 ) {
$blankLineToken = $i;
break;
}
}
}

if ( null === $blankLineToken ) {
// Also check for consecutive newline tokens (PHPCS sometimes splits them).
$lastWasNewline = false;

for ( $i = $scopeOpener + 1; $i < $scopeCloser; $i++ ) {
if ( $tokens[ $i ]['code'] === T_WHITESPACE && $tokens[ $i ]['content'] === "\n" ) {
if ( $lastWasNewline ) {
$blankLineToken = $i;
break;
}
$lastWasNewline = true;
} else {
$lastWasNewline = false;
}
}
}

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

$fix = $phpcsFile->addFixableError(
'Remove blank line inside short if block (3 lines or less).',
$blankLineToken,
'BlankLineInShortIf'
);
Comment on lines +113 to +117
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Error message inconsistency.

The message says "3 lines or less" but the sniff only triggers for exactly 3-line blocks (line 71 checks $bodyLines !== 3).

📝 Suggested fix
 		$fix = $phpcsFile->addFixableError(
-			'Remove blank line inside short if block (3 lines or less).',
+			'Remove blank line inside short if block (exactly 3 body lines).',
 			$blankLineToken,
 			'BlankLineInShortIf'
 		);
📝 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
$fix = $phpcsFile->addFixableError(
'Remove blank line inside short if block (3 lines or less).',
$blankLineToken,
'BlankLineInShortIf'
);
$fix = $phpcsFile->addFixableError(
'Remove blank line inside short if block (exactly 3 body lines).',
$blankLineToken,
'BlankLineInShortIf'
);
🤖 Prompt for AI Agents
In @phpcs-sniffs/Formidable/Sniffs/WhiteSpace/NoBlankLineInShortIfSniff.php
around lines 113 - 117, The error text is inconsistent with the check in
NoBlankLineInShortIfSniff: the sniff only triggers when $bodyLines === 3 but the
message says "3 lines or less"; update either the condition or the message to
match. Easiest fix: change the message passed to $phpcsFile->addFixableError in
NoBlankLineInShortIfSniff to "Remove blank line inside short if block (exactly 3
lines)." Alternatively, if the intention is to cover blocks with up to 3 lines,
adjust the $bodyLines check (currently comparing $bodyLines !== 3) to $bodyLines
<= 3 so the behavior matches the original message.


if ( true === $fix ) {
$phpcsFile->fixer->beginChangeset();

$content = $tokens[ $blankLineToken ]['content'];

// Remove one newline from the whitespace.
if ( substr_count( $content, "\n" ) >= 2 ) {
// Replace double newline with single newline, preserving indentation.
$newContent = preg_replace( "/\n\n/", "\n", $content, 1 );
$phpcsFile->fixer->replaceToken( $blankLineToken, $newContent );
Comment on lines +125 to +128
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix may fail when newlines aren't consecutive in the token content.

The detection at line 85 triggers when a whitespace token contains 2+ newlines anywhere (substr_count), but the fix regex /\n\n/ only matches consecutive newlines. If the blank line has indentation (e.g., content is "\n \n"), the regex won't match and $newContent equals $content, leaving the blank line unfixed.

🐛 Proposed fix
 			// Remove one newline from the whitespace.
 			if ( substr_count( $content, "\n" ) >= 2 ) {
-				// Replace double newline with single newline, preserving indentation.
-				$newContent = preg_replace( "/\n\n/", "\n", $content, 1 );
+				// Remove the first blank line (newline + any following whitespace up to next newline).
+				$newContent = preg_replace( "/\n[ \t]*\n/", "\n", $content, 1 );
 				$phpcsFile->fixer->replaceToken( $blankLineToken, $newContent );
🤖 Prompt for AI Agents
In @phpcs-sniffs/Formidable/Sniffs/WhiteSpace/NoBlankLineInShortIfSniff.php
around lines 125 - 128, The fix fails when the whitespace token contains a blank
line with indentation because substr_count( $content, "\n" ) detects 2+ newlines
but the preg_replace( "/\n\n/", "\n", $content, 1 ) only matches consecutive
newlines; update the preg_replace call in NoBlankLineInShortIfSniff (operating
on $content and $blankLineToken) to match a newline, any intervening
spaces/tabs, then another newline (use a regex like newline + optional [ \t]* +
newline), capture the indentation and replace with a single newline plus the
captured indentation (still with a limit of 1) so indented blank lines are
collapsed correctly.

} elseif ( $content === "\n" ) {
// This is a standalone newline token that creates a blank line.
$phpcsFile->fixer->replaceToken( $blankLineToken, '' );
}

$phpcsFile->fixer->endChangeset();
}
}
}
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,5 @@
<rule ref="Formidable.WhiteSpace.ShortFunctionBlankLine" />
<rule ref="Formidable.CodeAnalysis.SimplifyIfReturn" />
<rule ref="Formidable.CodeAnalysis.PreferObGetClean" />
<rule ref="Formidable.WhiteSpace.NoBlankLineInShortIf" />
</ruleset>
Loading