class
Analyzer::Elixir::Phoenix
Defined in:
analyzer/analyzers/elixir/elixir_phoenix.crConstant Summary
-
ELIXIR_INTERPOLATION_RE =
/\#\{([^}]+)\}/ -
Elixir double-quoted strings interpolate
#{expr}, and the Phoenix Router DSL captures the literal characters between quotes. Without normalization,get "/api/#{@version}/items"produced URL/api/#{@version}/itemswith the#{@…}syntax leaking into the path. Rewrite each interpolation site to a{name}placeholder (stripping any leading@module- attribute sigil) so the path-parameter extractor recognises it and the URL template reads cleanly. Mirrors the Python f-string, Ruby#{}, PHP$var, and Crystal#{}fixes. -
MODULE_NAME_RE =
/^\s*defmodule\s+([A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*)\s+do\b/m -
PHOENIX_ROUTE_EVIDENCE_RE =
/\ \b(?:get|post|put|patch|delete|options|head|match|resources|scope|socket|live|live_dashboard|forward) \s*(?:\(\s*)?(?:["']|unquote\b|:) |\bdefmacro\s+ /x -
File-level gate for the route-extraction pass. Controllers, schemas, views, and most application modules never declare Phoenix routes, but
#analyze_fileused to line-scan every.exfile anyway. Match the DSL shape (verb + optional paren + string/unquote/atom) so common non-route uses likeMap.get(orforgetdo not force a full scan. Custom route macros collected in the first pass are checked by name separately inmay_contain_phoenix_routes?. -
STANDARD_ROUTE_METHODS =
{"get" => "GET", "post" => "POST", "patch" => "PATCH", "put" => "PUT", "delete" => "DELETE", "options" => "OPTIONS", "head" => "HEAD"} -
get/post/… → its precompiled route regex.add_standard_routeruns once per verb per line of every.exfile;Regex.newthere recompiled the same 7 PCRE2 patterns on every call (~3.4M recompiles on a 2400-file repo, the dominant scan cost). The pattern depends only on the fixed verb set, so build it once. Seeadd_standard_routefor the shape rationale. RFC 10008'squeryis deliberately absent here. Unlike Plug (which already shipsquery/2), Phoenix's own router macro is still pending (phoenixframework/phoenix#6737); adding a bare verb here — viaadd_standard_route, which has noplug_route_path?-style leading-/guard — would misread any unrelatedquery("literal", CapitalizedMod)local function (a common Ecto/dispatch-helper shape) as a route. Since a Phoenix router sits on Plug,match :query, ...already routes today without needing this table — seematch_route_methodsbelow, which upcases whatever verb atom it's given. -
STANDARD_ROUTE_PATTERNS =
STANDARD_ROUTE_METHODS.keys.to_h do |verb| {verb, Regex.new("(?:^|[^.\\w])#{verb}\\s*(?:\\(\\s*)?['\"]([^'\"]+)['\"]\\s*,\\s*([A-Z]\\w*(?:\\.[A-Za-z_]\\w*)*|unquote\\(\\s*\\w+\\s*\\))(?=\\s*[,)]|\\s*$)(?:\\s*,\\s*:(\\w+[!?]?))?")} end
Class Method Summary
Instance Method Summary
- #analyze
- #analyze_file(path : String) : Array(Endpoint)
- #extract_controller_params
- #extract_params_from_controller(content : String, controller_name : String, controller_path : String)
- #extract_params_from_function_block(lines : Array(String), start_index : Int32, end_index : Int32, method : String) : Array(Param)
- #find_function_end(lines : Array(String), start_index : Int32) : Int32
- #line_to_endpoint(line : String, file_path : String, scope_prefix : String = "", scope_module : String = "", base : String = @base_path, string_bindings : Hash(String, String) = Hash(String, String).new) : Array(Endpoint)
-
#tech : String
Instance-side view of the same declaration.
Class methods inherited from class Analyzer::Elixir::ElixirEngine
test_path?(path : String) : Bool
test_path?
Instance methods inherited from class FileScanEngine
analyze
analyze,
analyze_file(path : String) : Array(Endpoint)
analyze_file
Instance methods inherited from class Analyzer
analyze
analyze,
base_path : String
base_path,
base_paths : Array(String)
base_paths,
base_relative_path(path : String) : String
base_relative_path,
callees_needed? : Bool
callees_needed?,
content_matches?(content : String, markers : Regex) : Bool
content_matches?,
http_header_name(name : String) : String | Nil
http_header_name,
line_number_for_index(content : String, char_index : Int32) : Int32
line_number_for_index,
logger : NoirLogger
logger,
parallel_analyze(files : Array(String), &block : String -> Nil)
parallel_analyze,
read_file_content(path : String) : String
read_file_content,
result : Array(Endpoint)
result,
tech : String
tech,
unique_params(params : Array(Param)) : Array(Param)
unique_params,
url : String
url,
web_root_path(path : String, markers : Array(String)) : String
web_root_path
Constructor methods inherited from class Analyzer
new(options : Hash(String, YAML::Any))
new
Macros inherited from class Analyzer
analyzer_for(tech)
analyzer_for
Instance methods inherited from module FileHelper
all_files : Array(String)
all_files,
get_files_by_basename(basename : String) : Array(String)
get_files_by_basename,
get_files_by_extension(extension : String) : Array(String)
get_files_by_extension,
get_files_by_extensions(extensions : Array(String)) : Array(String)
get_files_by_extensions,
get_files_by_prefix(prefix : String) : Array(String)
get_files_by_prefix,
get_files_by_prefix_and_extension(prefix : String, extension : String) : Array(String)
get_files_by_prefix_and_extension,
get_files_by_relative_path(relative_path : String, root : String = "") : Array(String)
get_files_by_relative_path,
get_public_dir_files(base_path : String, folder : String) : Array(String)
get_public_dir_files,
get_public_files(base_path : String, anchors : Array(String) = ["shard.yml", "Gemfile"]) : Array(String)
get_public_files,
walked_path(expanded : String) : String
walked_path
Class Method Detail
Instance Method Detail
Instance-side view of the same declaration. The per-file rescues live on
this base class, which has no way to name the analyzer that is running
inside them, so a skipped file could not be attributed to a tech.
Deriving it from analyzer_for keeps the name written exactly once.