MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / is_extractable_literal

Function is_extractable_literal

src/code_actions/extract_constant.rs:33–66  ·  view source on GitHub ↗

Returns `true` when the trimmed selection text looks like a PHP literal that can be extracted into a class constant.

(text: &str)

Source from the content-addressed store, hash-verified

31/// Returns `true` when the trimmed selection text looks like a PHP
32/// literal that can be extracted into a class constant.
33fn is_extractable_literal(text: &str) -> bool {
34 let t = text.trim();
35 if t.is_empty() {
36 return false;
37 }
38
39 // String literals
40 if (t.starts_with('\'') && t.ends_with('\'')) || (t.starts_with('"') && t.ends_with('"')) {
41 return t.len() >= 2;
42 }
43
44 // Boolean / null literals
45 let lower = t.to_ascii_lowercase();
46 if matches!(lower.as_str(), "true" | "false" | "null") {
47 return true;
48 }
49
50 // Numeric literals (integer or float)
51 if is_numeric_literal(t) {
52 return true;
53 }
54
55 // Concatenated string expression: `'a' . 'b'`
56 if is_concat_expression(t) {
57 return true;
58 }
59
60 // Negative numeric literal: `-42`, `-3.14`
61 if t.starts_with('-') && is_numeric_literal(t[1..].trim_start()) {
62 return true;
63 }
64
65 false
66}
67
68/// Returns `true` when the text is a numeric literal (integer or float,
69/// including hex `0x`, octal `0o`, binary `0b`, and underscored forms).

Calls 3

is_numeric_literalFunction · 0.85
is_concat_expressionFunction · 0.85
is_emptyMethod · 0.45

Tested by

no test coverage detected