Suggest mb_* functions with explicit encoding
Is there a way (a setting or a plugin) to make PHPStorm suggest use of multibyte string functions instead of regular ones and suggest explicit encoding in those? Like a style recommendation kind of thing? Ideally with automatic suppression if potential binary data is detected in the flow.
Please sign in to leave a comment.
i've worked-around:
go to settings/editor/inspections
on profile - export it
in the resulting xml-file search for <inspection_tool class="SSBasedInspection" (dont know if it's always there, i already had some custom entries here) and change or append the lines below. It's a search/replace from this list https://www.php.net/manual/en/ref.mbstring.php
then import the modified file back.
afterwards you can easyly change the severity/highlighting config within the settings dialog.
the code:
<inspection_tool class="SSBasedInspection" enabled="true" level="WARNING" enabled_by_default="true">
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="check_encoding(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="chr(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="convert_case(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="convert_encoding(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="convert_kana(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="convert_variables(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="decode_mimeheader(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="decode_numericentity(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="detect_encoding(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="detect_order(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="encode_mimeheader(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="encode_numericentity(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="encoding_aliases(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="ereg_match(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="ereg_replace_callback(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="ereg_replace(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="ereg_search_getpos(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="ereg_search_getregs(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="ereg_search_init(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="ereg_search_pos(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="ereg_search_regs(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="ereg_search_setpos(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="ereg_search(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="ereg(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="eregi_replace(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="eregi(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="get_info(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="http_input(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="http_output(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="internal_encoding(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="language(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="list_encodings(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="ord(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="output_handler(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="parse_str(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="preferred_mime_name(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="regex_encoding(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="regex_set_options(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="scrub(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="send_mail(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="split(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="str_pad(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="str_split(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="strcut(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="strimwidth(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="stripos(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="stristr(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="strlen(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="strpos(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="strrchr(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="strrichr(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="strripos(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="strrpos(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="strstr(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="strtolower(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="strtoupper(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="strwidth(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="substitute_character(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="substr_count(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
<searchConfiguration name="use mb_* function??" uuid="0650c09d-2ec9-3959-93a2-7bcebe01be31" text="substr(" recursive="true" caseInsensitive="true" type="PHP">
<constraint name="__context__" within="" contains="" />
</searchConfiguration>
</inspection_tool>
I am not sure using same uuid for all items is a good idea, and changing them manually may also be a bad one. I also expect that this will highlight functions even when working with binary data, and would not allow to update function from context menu (which is a minor thing, of course). I would prefer something like this in a plugin format, or maybe even native. Perhaps JetBrains people can turn this into feature request? Or is this too niche?
Apparently, identical UUIDs is expected (unless this is a bug), at least when adding custom inspections through UI, they do get same UUIDs. Here's what I did for my needs. It does not handle named references, though. Does anyone have any ideas it can be modified? And how can I turn this into a plugin?