-
Notifications
You must be signed in to change notification settings - Fork 41
Add deprecated messages to FrmAppHelper::icon_by_class
#3321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1358,7 +1358,7 @@ | |||||||||||||||||
| * | ||||||||||||||||||
| * @since 4.0.02 | ||||||||||||||||||
| * | ||||||||||||||||||
| * @param string $class | ||||||||||||||||||
| * @param string $class Icon classes. A class list without an SVG marker is treated as a font icon, which is deprecated since x.x. | ||||||||||||||||||
| * @param array $atts | ||||||||||||||||||
| * | ||||||||||||||||||
| * @return string|null | ||||||||||||||||||
|
|
@@ -1370,7 +1370,28 @@ | |||||||||||||||||
| unset( $atts['echo'] ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| $icon = trim( str_replace( array( 'frm_icon_font', 'frmfont ' ), '', $class ) ); | ||||||||||||||||||
| /** | ||||||||||||||||||
| * An frmfont or frm_icon_font marker anywhere in the list means the icon is in the SVG | ||||||||||||||||||
| * sprite. Each class is compared whole, so a class that merely starts with a marker name, | ||||||||||||||||||
| * like frmfont-sm, is left alone, and the markers can appear in any position. | ||||||||||||||||||
| */ | ||||||||||||||||||
| $icon_classes = array(); | ||||||||||||||||||
| $is_font_icon = true; | ||||||||||||||||||
|
|
||||||||||||||||||
| foreach ( preg_split( '/\s+/', $class, -1, PREG_SPLIT_NO_EMPTY ) as $single_class ) { | ||||||||||||||||||
| if ( 'frmfont' === $single_class || 'frm_icon_font' === $single_class ) { | ||||||||||||||||||
| $is_font_icon = false; | ||||||||||||||||||
| continue; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| $icon_classes[] = $single_class; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| $icon = implode( ' ', $icon_classes ); | ||||||||||||||||||
|
|
||||||||||||||||||
| if ( $is_font_icon && $icon_classes ) { | ||||||||||||||||||
| _deprecated_argument( __METHOD__, 'x.x', 'Font icons are deprecated. Pass the class of an icon in the SVG sprite instead.' ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // Replace icons that have been removed or renamed. | ||||||||||||||||||
| $deprecated = array( | ||||||||||||||||||
|
|
@@ -1379,12 +1400,15 @@ | |||||||||||||||||
| 'frm_keyalt_solid_icon' => 'frm_key_solid_icon', | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| if ( isset( $deprecated[ $icon ] ) ) { | ||||||||||||||||||
| $icon = $deprecated[ $icon ]; | ||||||||||||||||||
| $class = str_replace( $icon, $deprecated[ $icon ], $class ); | ||||||||||||||||||
| } | ||||||||||||||||||
| // The icon name is the first class in the list. Anything after it is extra styling. | ||||||||||||||||||
| $icon_name = $icon_classes ? $icon_classes[0] : ''; | ||||||||||||||||||
|
|
||||||||||||||||||
| if ( isset( $deprecated[ $icon_name ] ) ) { | ||||||||||||||||||
| _deprecated_argument( __METHOD__, 'x.x', 'The ' . esc_html( $icon_name ) . ' icon is deprecated. Use ' . esc_html( $deprecated[ $icon_name ] ) . ' instead.' ); | ||||||||||||||||||
|
|
||||||||||||||||||
| $is_font_icon = $icon === $class; | ||||||||||||||||||
| $class = str_replace( $icon_name, $deprecated[ $icon_name ], $class ); | ||||||||||||||||||
| $icon = str_replace( $icon_name, $deprecated[ $icon_name ], $icon ); | ||||||||||||||||||
|
Comment on lines
+1409
to
+1410
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Replace only the icon class token.
📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if ( ! $is_font_icon ) { | ||||||||||||||||||
| $class = str_contains( $icon, ' ' ) ? ' ' . $icon : ''; | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🤖 get_repo_knowledge executed:
get_repo_knowledge Strategy11/formidable-forms /tmp/coderabbit-repo-knowledge/strategy11-formidable-forms-fa1cd633Length of output: 379
🏁 Script executed:
Repository: Strategy11/formidable-forms
Length of output: 28874
🏁 Script executed:
Repository: Strategy11/formidable-forms
Length of output: 30235
🏁 Script executed:
Repository: Strategy11/formidable-forms
Length of output: 2164
Normalize the
preg_split()result before iteration.preg_split()returnsarray|false, so thisforeachcan trigger Psalm'sPossiblyFalseIteratorerror. Use an empty array fallback.Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 GitHub Actions: Psalm Code Analysis / 0_Psalm.txt
[error] 1381-1381: Psalm analysis failed: PossiblyFalseIterator. Cannot iterate over a falsable value of type false|list.
🪛 GitHub Actions: Psalm Code Analysis / Psalm
[error] 1381-1381: Psalm PossiblyFalseIterator: Cannot iterate over falsable variable of type false|list.
🪛 GitHub Check: Psalm
[failure] 1381-1381: PossiblyFalseIterator
classes/helpers/FrmAppHelper.php:1381:13: PossiblyFalseIterator: Cannot iterate over falsable var false|list (see https://psalm.dev/164)
🤖 Prompt for AI Agents
Source: Linters/SAST tools