diff --git a/src/ir/phpcore/phpcore.go b/src/ir/phpcore/phpcore.go index 5729b5dc..b249c548 100644 --- a/src/ir/phpcore/phpcore.go +++ b/src/ir/phpcore/phpcore.go @@ -9,7 +9,7 @@ func ResolveAlias(function ir.Node) ir.Node { if !ok { return function } - alias, ok := funcAliases[nm.Value] + alias, ok := FuncAliases[nm.Value] if ok { return alias } @@ -17,41 +17,138 @@ func ResolveAlias(function ir.Node) ir.Node { } func ResolveAliasName(n *ir.Name) *ir.Name { - alias, ok := funcAliases[n.Value] + alias, ok := FuncAliases[n.Value] if ok { return alias } return n } -var funcAliases = map[string]*ir.Name{ +var FuncAliases = map[string]*ir.Name{ // See https://www.php.net/manual/ru/aliases.php - `doubleval`: {Value: `floatval`}, - - `ini_alter`: {Value: `ini_set`}, - `is_integer`: {Value: `is_int`}, - `is_long`: {Value: `is_int`}, - `is_real`: {Value: `is_float`}, - `is_double`: {Value: `is_float`}, - - `join`: {Value: `implode`}, - `chop`: {Value: `rtrim`}, - `strchr`: {Value: `strstr`}, - `pos`: {Value: `current`}, - `key_exists`: {Value: `array_key_exists`}, - `sizeof`: {Value: `count`}, - - `checkdnsrr`: {Value: `dns_check_record`}, - `getmxrr`: {Value: `dns_get_mx`}, - - `is_writeable`: {Value: `is_writable`}, - `diskfreespace`: {Value: `disk_free_space`}, - `close`: {Value: `closedir`}, - `fputs`: {Value: `fwrite`}, - `magic_quotes_runtime`: {Value: `set_magic_quotes_runtime`}, - `show_source`: {Value: `highlight_file`}, - + "chop": {Value: "rtrim"}, + "close": {Value: "closedir"}, + "com_get": {Value: "com_propget"}, + "com_propset": {Value: "com_propput"}, + "com_set": {Value: "com_propput"}, + "die": {Value: "exit"}, + "diskfreespace": {Value: "disk_free_space"}, + "doubleval": {Value: "floatval"}, + "fputs": {Value: "fwrite"}, + "gzputs": {Value: "gzwrite"}, + "i18n_convert": {Value: "mb_convert_encoding"}, + "i18n_discover_encoding": {Value: "mb_detect_encoding"}, + "i18n_http_input": {Value: "mb_http_input"}, + "i18n_http_output": {Value: "mb_http_output"}, + "i18n_internal_encoding": {Value: "mb_internal_encoding"}, + "i18n_ja_jp_hantozen": {Value: "mb_convert_kana"}, + "i18n_mime_header_decode": {Value: "mb_decode_mimeheader"}, + "i18n_mime_header_encode": {Value: "mb_encode_mimeheader"}, + "imap_create": {Value: "imap_createmailbox"}, + "imap_fetchtext": {Value: "imap_body"}, + "imap_getmailboxes": {Value: "imap_list_full"}, + "imap_getsubscribed": {Value: "imap_lsub_full"}, + "imap_header": {Value: "imap_headerinfo"}, + "imap_listmailbox": {Value: "imap_list"}, + "imap_listsubscribed": {Value: "imap_lsub"}, + "imap_rename": {Value: "imap_renamemailbox"}, + "imap_scan": {Value: "imap_listscan"}, + "imap_scanmailbox": {Value: "imap_listscan"}, + "ini_alter": {Value: "ini_set"}, + "is_double": {Value: "is_float"}, + "is_integer": {Value: "is_int"}, + "is_long": {Value: "is_int"}, + "is_real": {Value: "is_float"}, + "is_writeable": {Value: "is_writable"}, + "join": {Value: "implode"}, + "key_exists": {Value: "array_key_exists"}, + "ldap_close": {Value: "ldap_unbind"}, + "mbstrcut": {Value: "mb_strcut"}, + "mbstrlen": {Value: "mb_strlen"}, + "mbstrpos": {Value: "mb_strpos"}, + "mbstrrpos": {Value: "mb_strrpos"}, + "mbsubstr": {Value: "mb_substr"}, + "mysql": {Value: "mysql_db_query"}, + "mysql_createdb": {Value: "mysql_create_db"}, + "mysql_db_name": {Value: "mysql_result"}, + "mysql_dbname": {Value: "mysql_result"}, + "mysql_dropdb": {Value: "mysql_drop_db"}, + "mysql_fieldflags": {Value: "mysql_field_flags"}, + "mysql_fieldlen": {Value: "mysql_field_len"}, + "mysql_fieldname": {Value: "mysql_field_name"}, + "mysql_fieldtable": {Value: "mysql_field_table"}, + "mysql_fieldtype": {Value: "mysql_field_type"}, + "mysql_freeresult": {Value: "mysql_free_result"}, + "mysql_listdbs": {Value: "mysql_list_dbs"}, + "mysql_listfields": {Value: "mysql_list_fields"}, + "mysql_listtables": {Value: "mysql_list_tables"}, + "mysql_numfields": {Value: "mysql_num_fields"}, + "mysql_numrows": {Value: "mysql_num_rows"}, + "mysql_selectdb": {Value: "mysql_select_db"}, + "mysql_tablename": {Value: "mysql_result"}, + "ociassignelem": {Value: "OCICollection::assignElem"}, + "ocibindbyname": {Value: "oci_bind_by_name"}, + "ocicancel": {Value: "oci_cancel"}, + "ocicloselob": {Value: "OCILob::close"}, + "ocicollappend": {Value: "OCICollection::append"}, + "ocicollassign": {Value: "OCICollection::assign"}, + "ocicollmax": {Value: "OCICollection::max"}, + "ocicollsize": {Value: "OCICollection::size"}, + "ocicolltrim": {Value: "OCICollection::trim"}, + "ocicolumnisnull": {Value: "oci_field_is_null"}, + "ocicolumnname": {Value: "oci_field_name"}, + "ocicolumnprecision": {Value: "oci_field_precision"}, + "ocicolumnscale": {Value: "oci_field_scale"}, + "ocicolumnsize": {Value: "oci_field_size"}, + "ocicolumntype": {Value: "oci_field_type"}, + "ocicolumntyperaw": {Value: "oci_field_type_raw"}, + "ocicommit": {Value: "oci_commit"}, + "ocidefinebyname": {Value: "oci_define_by_name"}, + "ocierror": {Value: "oci_error"}, + "ociexecute": {Value: "oci_execute"}, + "ocifetch": {Value: "oci_fetch"}, + "ocifetchinto": {Value: "oci_fetch_object"}, + "ocifetchstatement": {Value: "oci_fetch_all"}, + "ocifreecollection": {Value: "OCICollection::free"}, + "ocifreecursor": {Value: "oci_free_statement"}, + "ocifreedesc": {Value: "oci_free_descriptor"}, + "ocifreestatement": {Value: "oci_free_statement"}, + "ocigetelem": {Value: "OCICollection::getElem"}, + "ociinternaldebug": {Value: "oci_internal_debug"}, + "ociloadlob": {Value: "OCILob::load"}, + "ocilogon": {Value: "oci_connect"}, + "ocinewcollection": {Value: "oci_new_collection"}, + "ocinewcursor": {Value: "oci_new_cursor"}, + "ocinewdescriptor": {Value: "oci_new_descriptor"}, + "ocinlogon": {Value: "oci_new_connect"}, + "ocinumcols": {Value: "oci_num_fields"}, + "ociparse": {Value: "oci_parse"}, + "ocipasswordchange": {Value: "oci_password_change"}, + "ociplogon": {Value: "oci_pconnect"}, + "ociresult": {Value: "oci_result"}, + "ocirollback": {Value: "oci_rollback"}, + "ocisavelob": {Value: "OCILob::save"}, + "ocisavelobfile": {Value: "OCILob::import"}, + "ociserverversion": {Value: "oci_server_version"}, + "ocisetprefetch": {Value: "oci_set_prefetch"}, + "ocistatementtype": {Value: "oci_statement_type"}, + "ociwritelobtofile": {Value: "OCILob::export"}, + "ociwritetemporarylob": {Value: "OCILob::writeTemporary"}, + "odbc_do": {Value: "odbc_exec"}, + "odbc_field_precision": {Value: "odbc_field_len"}, + "pg_clientencoding": {Value: "pg_client_encoding"}, + "pg_setclientencoding": {Value: "pg_set_client_encoding"}, + "pos": {Value: "current"}, + "recode": {Value: "recode_string"}, + "show_source": {Value: "highlight_file"}, + "sizeof": {Value: "count"}, + "snmpwalkoid": {Value: "snmprealwalk"}, + "strchr": {Value: "strstr"}, + "xptr_new_context": {Value: "xpath_new_context"}, + `checkdnsrr`: {Value: `dns_check_record`}, + `getmxrr`: {Value: `dns_get_mx`}, + `magic_quotes_runtime`: {Value: `set_magic_quotes_runtime`}, `stream_register_wrapper`: {Value: `stream_wrapper_register`}, `set_file_buffer`: {Value: `stream_set_write_buffer`}, `socket_set_blocking`: {Value: `stream_set_blocking`}, diff --git a/src/linter/block_linter.go b/src/linter/block_linter.go index c4c8bbbc..59711703 100644 --- a/src/linter/block_linter.go +++ b/src/linter/block_linter.go @@ -11,7 +11,6 @@ import ( "github.com/VKCOM/noverify/src/ir/phpcore" "github.com/VKCOM/noverify/src/linter/autogen" "github.com/VKCOM/noverify/src/meta" - "github.com/VKCOM/noverify/src/php" "github.com/VKCOM/noverify/src/quickfix" "github.com/VKCOM/noverify/src/solver" "github.com/VKCOM/noverify/src/types" @@ -1006,15 +1005,15 @@ func (b *blockLinter) checkFunctionCall(e *ir.FunctionCallExpr) { call := resolveFunctionCall(b.walker.ctx.sc, b.classParseState(), b.walker.ctx.customTypes, e) fqName := call.funcName - var phpAlias = php.Aliases[fqName] - if phpAlias != "" { - b.report(e, LevelWarning, "phpAliases", "Use %s instead of '%s'", phpAlias, strings.TrimPrefix(fqName, `\`)) - b.walker.r.addQuickFix("phpAliases", b.quickfix.PhpAliasesReplace(e.Function.(*ir.Name), phpAlias)) + var trimName = strings.TrimPrefix(fqName, `\`) + var phpMasterFunc = phpcore.FuncAliases[trimName] + if phpMasterFunc != nil { + b.report(e, LevelWarning, "phpAliases", "Use %s instead of '%s'", phpMasterFunc.Value, trimName) + b.walker.r.addQuickFix("phpAliases", b.quickfix.PhpAliasesReplace(e.Function.(*ir.Name), phpMasterFunc.Value)) } if call.isClosure { - varName := strings.TrimPrefix(fqName, `\`) - b.walker.untrackVarName(varName) + b.walker.untrackVarName(trimName) } else { b.checkFunctionAvailability(e, &call) b.walker.r.checker.CheckNameCase(e.Function, call.funcName, call.info.Name) diff --git a/src/php/php_aliases.go b/src/php/php_aliases.go deleted file mode 100644 index 3712e1e0..00000000 --- a/src/php/php_aliases.go +++ /dev/null @@ -1,123 +0,0 @@ -package php - -var Aliases = map[string]string{ - "\\chop": "rtrim", - "\\close": "closedir", - "\\com_get": "com_propget", - "\\com_propset": "com_propput", - "\\com_set": "com_propput", - "\\die": "exit", - "\\diskfreespace": "disk_free_space", - "\\doubleval": "floatval", - "\\fputs": "fwrite", - "\\gzputs": "gzwrite", - "\\i18n_convert": "mb_convert_encoding", - "\\i18n_discover_encoding": "mb_detect_encoding", - "\\i18n_http_input": "mb_http_input", - "\\i18n_http_output": "mb_http_output", - "\\i18n_internal_encoding": "mb_internal_encoding", - "\\i18n_ja_jp_hantozen": "mb_convert_kana", - "\\i18n_mime_header_decode": "mb_decode_mimeheader", - "\\i18n_mime_header_encode": "mb_encode_mimeheader", - "\\imap_create": "imap_createmailbox", - "\\imap_fetchtext": "imap_body", - "\\imap_getmailboxes": "imap_list_full", - "\\imap_getsubscribed": "imap_lsub_full", - "\\imap_header": "imap_headerinfo", - "\\imap_listmailbox": "imap_list", - "\\imap_listsubscribed": "imap_lsub", - "\\imap_rename": "imap_renamemailbox", - "\\imap_scan": "imap_listscan", - "\\imap_scanmailbox": "imap_listscan", - "\\ini_alter": "ini_set", - "\\is_double": "is_float", - "\\is_integer": "is_int", - "\\is_long": "is_int", - "\\is_real": "is_float", - "\\is_writeable": "is_writable", - "\\join": "implode", - "\\key_exists": "array_key_exists", - "\\ldap_close": "ldap_unbind", - "\\mbstrcut": "mb_strcut", - "\\mbstrlen": "mb_strlen", - "\\mbstrpos": "mb_strpos", - "\\mbstrrpos": "mb_strrpos", - "\\mbsubstr": "mb_substr", - "\\mysql": "mysql_db_query", - "\\mysql_createdb": "mysql_create_db", - "\\mysql_db_name": "mysql_result", - "\\mysql_dbname": "mysql_result", - "\\mysql_dropdb": "mysql_drop_db", - "\\mysql_fieldflags": "mysql_field_flags", - "\\mysql_fieldlen": "mysql_field_len", - "\\mysql_fieldname": "mysql_field_name", - "\\mysql_fieldtable": "mysql_field_table", - "\\mysql_fieldtype": "mysql_field_type", - "\\mysql_freeresult": "mysql_free_result", - "\\mysql_listdbs": "mysql_list_dbs", - "\\mysql_listfields": "mysql_list_fields", - "\\mysql_listtables": "mysql_list_tables", - "\\mysql_numfields": "mysql_num_fields", - "\\mysql_numrows": "mysql_num_rows", - "\\mysql_selectdb": "mysql_select_db", - "\\mysql_tablename": "mysql_result", - "\\ociassignelem": "OCICollection::assignElem", - "\\ocibindbyname": "oci_bind_by_name", - "\\ocicancel": "oci_cancel", - "\\ocicloselob": "OCILob::close", - "\\ocicollappend": "OCICollection::append", - "\\ocicollassign": "OCICollection::assign", - "\\ocicollmax": "OCICollection::max", - "\\ocicollsize": "OCICollection::size", - "\\ocicolltrim": "OCICollection::trim", - "\\ocicolumnisnull": "oci_field_is_null", - "\\ocicolumnname": "oci_field_name", - "\\ocicolumnprecision": "oci_field_precision", - "\\ocicolumnscale": "oci_field_scale", - "\\ocicolumnsize": "oci_field_size", - "\\ocicolumntype": "oci_field_type", - "\\ocicolumntyperaw": "oci_field_type_raw", - "\\ocicommit": "oci_commit", - "\\ocidefinebyname": "oci_define_by_name", - "\\ocierror": "oci_error", - "\\ociexecute": "oci_execute", - "\\ocifetch": "oci_fetch", - "\\ocifetchinto": "oci_fetch_object", - "\\ocifetchstatement": "oci_fetch_all", - "\\ocifreecollection": "OCICollection::free", - "\\ocifreecursor": "oci_free_statement", - "\\ocifreedesc": "oci_free_descriptor", - "\\ocifreestatement": "oci_free_statement", - "\\ocigetelem": "OCICollection::getElem", - "\\ociinternaldebug": "oci_internal_debug", - "\\ociloadlob": "OCILob::load", - "\\ocilogon": "oci_connect", - "\\ocinewcollection": "oci_new_collection", - "\\ocinewcursor": "oci_new_cursor", - "\\ocinewdescriptor": "oci_new_descriptor", - "\\ocinlogon": "oci_new_connect", - "\\ocinumcols": "oci_num_fields", - "\\ociparse": "oci_parse", - "\\ocipasswordchange": "oci_password_change", - "\\ociplogon": "oci_pconnect", - "\\ociresult": "oci_result", - "\\ocirollback": "oci_rollback", - "\\ocisavelob": "OCILob::save", - "\\ocisavelobfile": "OCILob::import", - "\\ociserverversion": "oci_server_version", - "\\ocisetprefetch": "oci_set_prefetch", - "\\ocistatementtype": "oci_statement_type", - "\\ociwritelobtofile": "OCILob::export", - "\\ociwritetemporarylob": "OCILob::writeTemporary", - "\\odbc_do": "odbc_exec", - "\\odbc_field_precision": "odbc_field_len", - "\\pg_clientencoding": "pg_client_encoding", - "\\pg_setclientencoding": "pg_set_client_encoding", - "\\pos": "current", - "\\recode": "recode_string", - "\\show_source": "highlight_file", - "\\sizeof": "count", - "\\snmpwalkoid": "snmprealwalk", - "\\strchr": "strstr", - "\\xptr_new_context": "xpath_new_context", -}