@dataparade/cli 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/analyzers/php/dependency-manifests.d.ts +10 -0
  3. package/dist/src/analyzers/php/dependency-manifests.js +117 -0
  4. package/dist/src/analyzers/php/detector.d.ts +3 -0
  5. package/dist/src/analyzers/php/detector.js +20 -0
  6. package/dist/src/analyzers/php/index.d.ts +2 -0
  7. package/dist/src/analyzers/php/index.js +11 -0
  8. package/dist/src/analyzers/php/manifest-parsers.d.ts +14 -0
  9. package/dist/src/analyzers/php/manifest-parsers.js +40 -0
  10. package/dist/src/analyzers/php/parser.d.ts +42 -0
  11. package/dist/src/analyzers/php/parser.js +297 -0
  12. package/dist/src/analyzers/php/patterns.d.ts +3 -0
  13. package/dist/src/analyzers/php/patterns.js +49 -0
  14. package/dist/src/analyzers/php/php-detection-config.d.ts +104 -0
  15. package/dist/src/analyzers/php/php-detection-config.js +192 -0
  16. package/dist/src/analyzers/registry.js +3 -0
  17. package/dist/src/analyzers/shared/strip-comments.js +3 -2
  18. package/dist/src/classifier/postprocessing.d.ts +6 -0
  19. package/dist/src/classifier/postprocessing.js +61 -6
  20. package/dist/src/cli.js +27 -0
  21. package/dist/src/config/file.js +1 -0
  22. package/dist/src/config/resolve.js +1 -0
  23. package/dist/src/core/pipeline/classifier-phase.js +3 -3
  24. package/dist/src/core/pipeline/structural-scan.js +39 -14
  25. package/dist/src/core/schema/scan-config.schema.d.ts +1 -0
  26. package/dist/src/core/schema/scan-config.schema.js +1 -0
  27. package/dist/src/core/schema/scan-result.schema.d.ts +1 -0
  28. package/dist/src/core/schema/scan-result.schema.js +1 -0
  29. package/dist/src/core/sectioning/discover-service-sections.js +3 -0
  30. package/dist/src/core/types/file.d.ts +1 -1
  31. package/dist/src/ingest/file-system.js +3 -0
  32. package/dist/src/patterns/config.d.ts +2 -0
  33. package/dist/src/patterns/config.js +31 -0
  34. package/dist/src/patterns/detectors/php.d.ts +9 -0
  35. package/dist/src/patterns/detectors/php.js +466 -0
  36. package/dist/src/patterns/engine.js +7 -0
  37. package/dist/src/platform-api/telemetry-client.d.ts +6 -0
  38. package/dist/src/platform-api/telemetry-client.js +65 -0
  39. package/dist/src/platform-api/telemetry.types.d.ts +13 -0
  40. package/dist/src/platform-api/telemetry.types.js +2 -0
  41. package/dist/src/platform-api/upload-client.d.ts +2 -0
  42. package/dist/src/platform-api/upload-client.js +4 -0
  43. package/dist/src/platform-api/upload.types.d.ts +2 -0
  44. package/dist/src/upload/build-preview-url.d.ts +2 -2
  45. package/dist/src/upload/build-preview-url.js +10 -3
  46. package/dist/src/upload/run-upload.js +62 -19
  47. package/dist/src/upload/types.d.ts +2 -0
  48. package/dist/tests/unit/analyzers/php/dependency-manifests.spec.d.ts +1 -0
  49. package/dist/tests/unit/analyzers/php/dependency-manifests.spec.js +54 -0
  50. package/dist/tests/unit/analyzers/php/parser.spec.d.ts +1 -0
  51. package/dist/tests/unit/analyzers/php/parser.spec.js +128 -0
  52. package/dist/tests/unit/analyzers/php/patterns.spec.d.ts +1 -0
  53. package/dist/tests/unit/analyzers/php/patterns.spec.js +334 -0
  54. package/dist/tests/unit/classifier/classify.spec.js +68 -0
  55. package/dist/tests/unit/ingest/php-languages.spec.d.ts +1 -0
  56. package/dist/tests/unit/ingest/php-languages.spec.js +40 -0
  57. package/dist/tests/unit/platform-api/telemetry-client.spec.d.ts +1 -0
  58. package/dist/tests/unit/platform-api/telemetry-client.spec.js +48 -0
  59. package/dist/tests/unit/upload/build-preview-url.spec.js +10 -0
  60. package/dist/tests/unit/upload/run-upload.spec.js +18 -0
  61. package/package.json +1 -1
  62. package/patterns/php.md +74 -0
  63. package/patterns/php.patterns.yaml +311 -0
  64. package/patterns/third-party.patterns.yaml +10 -0
@@ -16,6 +16,7 @@ const fileLanguageEnum = zod_1.z.enum([
16
16
  "cpp",
17
17
  "csharp",
18
18
  "go",
19
+ "php",
19
20
  "java",
20
21
  "kotlin",
21
22
  "terraform",
@@ -20,6 +20,7 @@ export declare const fileInfoSchema: z.ZodObject<{
20
20
  cpp: "cpp";
21
21
  csharp: "csharp";
22
22
  go: "go";
23
+ php: "php";
23
24
  java: "java";
24
25
  kotlin: "kotlin";
25
26
  terraform: "terraform";
@@ -14,6 +14,7 @@ const fileLanguageEnum = zod_1.z.enum([
14
14
  "cpp",
15
15
  "csharp",
16
16
  "go",
17
+ "php",
17
18
  "java",
18
19
  "kotlin",
19
20
  "terraform",
@@ -82,6 +82,8 @@ async function walkForManifests(currentDirAbs, rootDirAbs, excludePaths, accumul
82
82
  // go.mod is the canonical Go module root, so it maps exactly onto a
83
83
  // service boundary in a multi-module repository.
84
84
  const isGoModule = lower === "go.mod";
85
+ // composer.json is the Composer package root for PHP services.
86
+ const isComposerManifest = lower === "composer.json";
85
87
  // Maven and Gradle both place a build file at each module root, and on the
86
88
  // JVM a module is the deployable unit — unlike `CMakeLists.txt`, one build
87
89
  // file per directory *is* the service boundary. `settings.gradle` marks the
@@ -99,6 +101,7 @@ async function walkForManifests(currentDirAbs, rootDirAbs, excludePaths, accumul
99
101
  !isPipfile &&
100
102
  !isDotnetProject &&
101
103
  !isGoModule &&
104
+ !isComposerManifest &&
102
105
  !isJvmManifest &&
103
106
  !isCppManifest) {
104
107
  continue;
@@ -1,4 +1,4 @@
1
- export type FileLanguage = "typescript" | "javascript" | "json" | "yaml" | "env" | "python" | "cpp" | "csharp" | "go" | "java" | "kotlin" | "terraform" | "dockerfile";
1
+ export type FileLanguage = "typescript" | "javascript" | "json" | "yaml" | "env" | "python" | "cpp" | "csharp" | "go" | "php" | "java" | "kotlin" | "terraform" | "dockerfile";
2
2
  export interface FileInfo {
3
3
  path: string;
4
4
  name: string;
@@ -94,6 +94,9 @@ function getFileLanguage(filePath) {
94
94
  if (ext === ".go") {
95
95
  return "go";
96
96
  }
97
+ if (ext === ".php" || ext === ".phtml") {
98
+ return "php";
99
+ }
97
100
  if (ext === ".java") {
98
101
  return "java";
99
102
  }
@@ -5,6 +5,7 @@ import type { TypeScriptPatternConfig } from "../analyzers/typescript/typescript
5
5
  import type { ClassifierConfig } from "../classifier/config";
6
6
  import type { PythonPatternConfig } from "../analyzers/python/python-detection-config";
7
7
  import type { GoPatternConfig } from "../analyzers/go/go-detection-config";
8
+ import type { PhpPatternConfig } from "../analyzers/php/php-detection-config";
8
9
  import type { JvmPatternConfig } from "../analyzers/jvm/jvm-detection-config";
9
10
  import type { CppPatternConfig } from "../analyzers/cpp/cpp-detection-config";
10
11
  import type { CSharpPatternConfig } from "../analyzers/csharp/csharp-detection-config";
@@ -17,6 +18,7 @@ export interface UnifiedPatternConfig {
17
18
  classifier: ClassifierConfig;
18
19
  python: PythonPatternConfig;
19
20
  go: GoPatternConfig;
21
+ php: PhpPatternConfig;
20
22
  jvm: JvmPatternConfig;
21
23
  cpp: CppPatternConfig;
22
24
  csharp: CSharpPatternConfig;
@@ -8,6 +8,7 @@ const typescript_detection_config_1 = require("../analyzers/typescript/typescrip
8
8
  const config_1 = require("../classifier/config");
9
9
  const python_detection_config_1 = require("../analyzers/python/python-detection-config");
10
10
  const go_detection_config_1 = require("../analyzers/go/go-detection-config");
11
+ const php_detection_config_1 = require("../analyzers/php/php-detection-config");
11
12
  const jvm_detection_config_1 = require("../analyzers/jvm/jvm-detection-config");
12
13
  const cpp_detection_config_1 = require("../analyzers/cpp/cpp-detection-config");
13
14
  const csharp_detection_config_1 = require("../analyzers/csharp/csharp-detection-config");
@@ -106,6 +107,34 @@ function validateUnifiedPatternConfig(unified) {
106
107
  for (const c of unified.go.externalApis.httpClients) {
107
108
  emittedPatternIds.add(String(c.patternId));
108
109
  }
110
+ // PHP.
111
+ for (const db of unified.php.dbClients) {
112
+ emittedPatternIds.add(String(db.patternId));
113
+ }
114
+ if (unified.php.pdoDsn) {
115
+ emittedPatternIds.add(String(unified.php.pdoDsn.patternId));
116
+ }
117
+ for (const lib of unified.php.auth.libraries) {
118
+ emittedPatternIds.add(String(lib.patternId));
119
+ }
120
+ for (const fw of unified.php.routes.frameworks) {
121
+ emittedPatternIds.add(String(fw.patternId));
122
+ }
123
+ for (const handler of unified.php.serverless.handlers) {
124
+ emittedPatternIds.add(String(handler.patternId));
125
+ }
126
+ if (unified.php.envConfig.envVariable) {
127
+ emittedPatternIds.add(String(unified.php.envConfig.envVariable.patternId));
128
+ }
129
+ if (unified.php.envConfig.configLoaders) {
130
+ emittedPatternIds.add(String(unified.php.envConfig.configLoaders.patternId));
131
+ }
132
+ if (unified.php.envConfig.configFile) {
133
+ emittedPatternIds.add(String(unified.php.envConfig.configFile.patternId));
134
+ }
135
+ for (const c of unified.php.externalApis.httpClients) {
136
+ emittedPatternIds.add(String(c.patternId));
137
+ }
109
138
  // JVM (Java + Kotlin).
110
139
  for (const db of unified.jvm.dbClients) {
111
140
  emittedPatternIds.add(String(db.patternId));
@@ -230,6 +259,7 @@ function loadUnifiedPatternConfig() {
230
259
  const classifier = (0, config_1.loadClassifierConfig)();
231
260
  const python = (0, python_detection_config_1.loadPythonPatternConfig)();
232
261
  const go = (0, go_detection_config_1.loadGoPatternConfig)();
262
+ const php = (0, php_detection_config_1.loadPhpPatternConfig)();
233
263
  const jvm = (0, jvm_detection_config_1.loadJvmPatternConfig)();
234
264
  const cpp = (0, cpp_detection_config_1.loadCppPatternConfig)();
235
265
  const csharp = (0, csharp_detection_config_1.loadCSharpPatternConfig)();
@@ -242,6 +272,7 @@ function loadUnifiedPatternConfig() {
242
272
  classifier,
243
273
  python,
244
274
  go,
275
+ php,
245
276
  jvm,
246
277
  cpp,
247
278
  csharp,
@@ -0,0 +1,9 @@
1
+ import type { PatternContext } from "../engine";
2
+ import type { UnifiedPatternConfig } from "../config";
3
+ import type { RawFinding } from "../../core/types/detection";
4
+ export declare function detectPhpDatabaseConnectionsFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
5
+ export declare function detectPhpAuthFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
6
+ export declare function detectPhpEnvAndConfigFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
7
+ export declare function detectPhpRoutesFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
8
+ export declare function detectPhpServerlessHandlersFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
9
+ export declare function detectPhpExternalApisFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
@@ -0,0 +1,466 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectPhpDatabaseConnectionsFromConfig = detectPhpDatabaseConnectionsFromConfig;
4
+ exports.detectPhpAuthFromConfig = detectPhpAuthFromConfig;
5
+ exports.detectPhpEnvAndConfigFromConfig = detectPhpEnvAndConfigFromConfig;
6
+ exports.detectPhpRoutesFromConfig = detectPhpRoutesFromConfig;
7
+ exports.detectPhpServerlessHandlersFromConfig = detectPhpServerlessHandlersFromConfig;
8
+ exports.detectPhpExternalApisFromConfig = detectPhpExternalApisFromConfig;
9
+ const external_url_third_party_1 = require("../../classifier/external-url-third-party");
10
+ const helpers_1 = require("./helpers");
11
+ /**
12
+ * Match a PHP `use` namespace against a configured prefix.
13
+ * `Illuminate\Database` matches `Illuminate\Database\Eloquent\Model`.
14
+ */
15
+ function namespaceMatches(importPath, want) {
16
+ if (!want)
17
+ return false;
18
+ if (importPath === want)
19
+ return true;
20
+ return (importPath.startsWith(`${want}\\`) || importPath.endsWith(`\\${want}`));
21
+ }
22
+ function hasAnyNamespace(ctx, namespaces) {
23
+ if (namespaces.length === 0)
24
+ return false;
25
+ const imports = ctx.imports ?? [];
26
+ return imports.some((imp) => namespaces.some((want) => namespaceMatches(imp.module, want)));
27
+ }
28
+ /**
29
+ * Composer package names use `/` (`guzzlehttp/guzzle`). That keeps them
30
+ * disjoint from PSR namespaces (`GuzzleHttp\Client`), which use `\`.
31
+ */
32
+ function hasAnyPackageName(ctx, packageNames) {
33
+ if (packageNames.length === 0)
34
+ return false;
35
+ const imports = ctx.imports ?? [];
36
+ return imports.some((imp) => {
37
+ if (!imp.module.includes("/"))
38
+ return false;
39
+ return packageNames.some((want) => imp.module === want || imp.module.startsWith(`${want}/`));
40
+ });
41
+ }
42
+ function sourceOf(ctx) {
43
+ return ctx.strippedContent ?? ctx.file.content ?? "";
44
+ }
45
+ function escapeRegexLiteral(value) {
46
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
47
+ }
48
+ /**
49
+ * Build a content-scan regex for configured call names.
50
+ * - Strips a trailing `(` / `{` so YAML can list either `config` or `config(`.
51
+ * - `new Class` also matches `new \Class`.
52
+ * - Names ending in `::` match any method (`Eloquent::unguard()`).
53
+ * - Names starting with `->` allow a receiver before the arrow (`$c->get(`).
54
+ */
55
+ function callNameRegex(callNames) {
56
+ const parts = callNames
57
+ .filter((name) => typeof name === "string" && name.length > 0)
58
+ .map((raw) => {
59
+ const name = raw.replace(/[({]+$/, "");
60
+ if (!name)
61
+ return null;
62
+ if (name.startsWith("new ")) {
63
+ const className = name.slice(4).replace(/^\\+/, "");
64
+ return `new\\s+\\\\?${escapeRegexLiteral(className)}`;
65
+ }
66
+ if (name.endsWith("::")) {
67
+ return `${escapeRegexLiteral(name)}\\w+`;
68
+ }
69
+ if (name.startsWith("->")) {
70
+ // Allow `$client->get(` / `$client?->get(` — word char before `->`.
71
+ return `\\??${escapeRegexLiteral(name)}`;
72
+ }
73
+ return escapeRegexLiteral(name);
74
+ })
75
+ .filter((part) => part != null);
76
+ if (parts.length === 0)
77
+ return /(?!)/; // never matches
78
+ const hasArrowOnly = parts.every((part) => part.includes("->"));
79
+ if (hasArrowOnly) {
80
+ return new RegExp(`(?:${parts.join("|")})\\s*[({]`);
81
+ }
82
+ // Mix of arrow and non-arrow: wrap arrow parts without the strict prefix.
83
+ const alternation = parts
84
+ .map((part) => part.includes("->")
85
+ ? part
86
+ : `(?:^|[^A-Za-z0-9_\\\\])${part}`)
87
+ .join("|");
88
+ return new RegExp(`(?:${alternation})\\s*[({]`);
89
+ }
90
+ /** Normalize `new \Foo` → `new Foo` so FQCN builtins match configured call names. */
91
+ function normalizeCallee(callee) {
92
+ return callee.replace(/^new\s+\\+/, "new ");
93
+ }
94
+ function calleeMatches(callee, callNames, suffixes) {
95
+ const normalized = normalizeCallee(callee);
96
+ if (callNames.some((name) => normalized === name ||
97
+ callee === name ||
98
+ normalized.endsWith(name) ||
99
+ callee.endsWith(name))) {
100
+ return true;
101
+ }
102
+ return suffixes.some((suffix) => normalized.endsWith(suffix) || callee.endsWith(suffix));
103
+ }
104
+ function detectPhpDatabaseConnectionsFromConfig(ctx, config) {
105
+ if (ctx.language !== "php")
106
+ return [];
107
+ const content = sourceOf(ctx);
108
+ const findings = [];
109
+ for (const db of config.php.dbClients) {
110
+ const hasImport = hasAnyNamespace(ctx, db.importNamespaces);
111
+ const hasPackage = hasAnyPackageName(ctx, db.packageNames);
112
+ const hasCall = db.callNames.length > 0 && callNameRegex(db.callNames).test(content);
113
+ const gated = db.importNamespaces.length > 0 || db.packageNames.length > 0;
114
+ if (gated) {
115
+ // Import/package required — avoids `new Client()` matching Predis/Guzzle/etc.
116
+ if (!hasImport && !hasPackage)
117
+ continue;
118
+ }
119
+ else if (!hasCall) {
120
+ continue;
121
+ }
122
+ findings.push({
123
+ pattern: db.patternId,
124
+ name: db.id,
125
+ confidence: db.confidence,
126
+ location: {
127
+ filePath: ctx.file.path,
128
+ startLine: 1,
129
+ endLine: 1,
130
+ },
131
+ properties: {
132
+ client: db.id,
133
+ databaseType: db.databaseType,
134
+ },
135
+ });
136
+ }
137
+ const pdoDsn = config.php.pdoDsn;
138
+ if (pdoDsn) {
139
+ const lines = content.split(/\r?\n/);
140
+ const seenDrivers = new Set();
141
+ for (let i = 0; i < lines.length; i += 1) {
142
+ const match = pdoDsn.regex.exec(lines[i]);
143
+ if (!match)
144
+ continue;
145
+ const dsn = (match[1] ?? "").trim();
146
+ const driver = dsn.split(":")[0]?.toLowerCase() ?? "";
147
+ if (!driver || seenDrivers.has(driver))
148
+ continue;
149
+ seenDrivers.add(driver);
150
+ const databaseType = pdoDsn.drivers[driver] ?? pdoDsn.defaultDatabaseType;
151
+ findings.push({
152
+ pattern: pdoDsn.patternId,
153
+ name: `${pdoDsn.name}:${driver}`,
154
+ confidence: pdoDsn.confidence,
155
+ location: {
156
+ filePath: ctx.file.path,
157
+ startLine: i + 1,
158
+ endLine: i + 1,
159
+ code: lines[i].trim(),
160
+ },
161
+ properties: {
162
+ client: pdoDsn.name,
163
+ databaseType,
164
+ driver,
165
+ dsn,
166
+ },
167
+ });
168
+ }
169
+ }
170
+ return findings;
171
+ }
172
+ function detectPhpAuthFromConfig(ctx, config) {
173
+ if (ctx.language !== "php")
174
+ return [];
175
+ const content = sourceOf(ctx);
176
+ const findings = [];
177
+ for (const lib of config.php.auth.libraries) {
178
+ const hasImport = hasAnyNamespace(ctx, lib.importNamespaces);
179
+ const hasPackage = hasAnyPackageName(ctx, lib.packageNames);
180
+ const hasCall = lib.callNames.length > 0 && callNameRegex(lib.callNames).test(content);
181
+ const matchesContent = lib.contentRegexes.length > 0 &&
182
+ lib.contentRegexes.some((re) => re.test(content));
183
+ if (!hasImport && !hasPackage && !hasCall && !matchesContent)
184
+ continue;
185
+ findings.push({
186
+ pattern: lib.patternId,
187
+ name: lib.id,
188
+ confidence: lib.confidence,
189
+ location: {
190
+ filePath: ctx.file.path,
191
+ startLine: 1,
192
+ endLine: 1,
193
+ },
194
+ properties: {
195
+ ...(lib.strategy ? { strategy: lib.strategy } : {}),
196
+ },
197
+ });
198
+ }
199
+ return findings;
200
+ }
201
+ function detectPhpEnvAndConfigFromConfig(ctx, config) {
202
+ if (ctx.language !== "php")
203
+ return [];
204
+ const envCfg = config.php.envConfig;
205
+ const content = sourceOf(ctx);
206
+ const findings = [];
207
+ if (envCfg.envVariable) {
208
+ const lines = content.split(/\r?\n/);
209
+ for (let i = 0; i < lines.length; i += 1) {
210
+ const line = lines[i];
211
+ const match = envCfg.envVariable.regex.exec(line);
212
+ if (!match)
213
+ continue;
214
+ const key = match[1] || match[2];
215
+ findings.push({
216
+ pattern: envCfg.envVariable.patternId,
217
+ name: key ? `env(${key})` : "env_variable",
218
+ confidence: envCfg.envVariable.confidence,
219
+ location: {
220
+ filePath: ctx.file.path,
221
+ startLine: i + 1,
222
+ endLine: i + 1,
223
+ code: line.trim(),
224
+ },
225
+ properties: key ? { key } : {},
226
+ });
227
+ }
228
+ }
229
+ if (envCfg.configLoaders) {
230
+ for (const loader of envCfg.configLoaders.loaders) {
231
+ const hasImport = hasAnyNamespace(ctx, loader.importNamespaces);
232
+ const hasPackage = hasAnyPackageName(ctx, loader.packageNames);
233
+ const hasCall = loader.callNames.length > 0 &&
234
+ callNameRegex(loader.callNames).test(content);
235
+ if (!hasImport && !hasPackage && !hasCall)
236
+ continue;
237
+ findings.push({
238
+ pattern: envCfg.configLoaders.patternId,
239
+ name: loader.id,
240
+ confidence: envCfg.configLoaders.confidence,
241
+ location: {
242
+ filePath: ctx.file.path,
243
+ startLine: 1,
244
+ endLine: 1,
245
+ },
246
+ properties: {},
247
+ });
248
+ }
249
+ }
250
+ if (envCfg.configFile) {
251
+ const normalizedPath = (ctx.normalizedPath ?? ctx.file.path).toLowerCase();
252
+ if (envCfg.configFile.fileNameRegex.test(normalizedPath)) {
253
+ findings.push({
254
+ pattern: envCfg.configFile.patternId,
255
+ name: envCfg.configFile.name,
256
+ confidence: envCfg.configFile.confidence,
257
+ location: {
258
+ filePath: ctx.file.path,
259
+ startLine: 1,
260
+ endLine: 1,
261
+ },
262
+ properties: {},
263
+ });
264
+ }
265
+ }
266
+ return findings;
267
+ }
268
+ function detectPhpRoutesFromConfig(ctx, config) {
269
+ if (ctx.language !== "php")
270
+ return [];
271
+ const strippedLines = sourceOf(ctx).split(/\r?\n/);
272
+ // Symfony @Route annotations live inside docblocks, which stripping removes.
273
+ // Scan raw source for that framework only; attributes survive hash-comment stripping.
274
+ const rawLines = (ctx.file.content ?? "").split(/\r?\n/);
275
+ const findings = [];
276
+ for (const fw of config.php.routes.frameworks) {
277
+ const gated = fw.importNamespaces.length > 0 || fw.packageNames.length > 0;
278
+ const supportsFramework = !gated ||
279
+ hasAnyNamespace(ctx, fw.importNamespaces) ||
280
+ hasAnyPackageName(ctx, fw.packageNames);
281
+ if (!supportsFramework)
282
+ continue;
283
+ const lines = fw.id === "symfony" ? rawLines : strippedLines;
284
+ for (const routeRegex of fw.routeRegexes) {
285
+ for (let i = 0; i < lines.length; i += 1) {
286
+ const text = lines[i].trim();
287
+ if (!text)
288
+ continue;
289
+ const match = routeRegex.regex.exec(text);
290
+ if (!match)
291
+ continue;
292
+ const rawMethod = routeRegex.methodGroup != null
293
+ ? match[routeRegex.methodGroup]
294
+ : routeRegex.defaultMethod;
295
+ const method = rawMethod ? rawMethod.toUpperCase() : undefined;
296
+ const routePath = routeRegex.pathGroup != null ? match[routeRegex.pathGroup] : undefined;
297
+ const name = method
298
+ ? `${method} ${routePath ?? ""}`.trim()
299
+ : `${fw.id.toUpperCase()}_ROUTE ${routePath ?? ""}`.trim();
300
+ findings.push({
301
+ pattern: fw.patternId,
302
+ name,
303
+ confidence: fw.confidence,
304
+ location: {
305
+ filePath: ctx.file.path,
306
+ startLine: i + 1,
307
+ endLine: i + 1,
308
+ code: text,
309
+ },
310
+ properties: {
311
+ framework: fw.id,
312
+ httpMethods: method ? [method] : [],
313
+ ...(routePath ? { path: routePath } : {}),
314
+ },
315
+ });
316
+ }
317
+ }
318
+ }
319
+ return findings;
320
+ }
321
+ function detectPhpServerlessHandlersFromConfig(ctx, config) {
322
+ if (ctx.language !== "php")
323
+ return [];
324
+ const findings = [];
325
+ for (const handler of config.php.serverless.handlers) {
326
+ const hasImport = hasAnyNamespace(ctx, handler.importNamespaces);
327
+ const hasPackage = hasAnyPackageName(ctx, handler.packageNames);
328
+ if (!hasImport && !hasPackage)
329
+ continue;
330
+ findings.push({
331
+ pattern: handler.patternId,
332
+ name: handler.id,
333
+ confidence: handler.confidence,
334
+ location: {
335
+ filePath: ctx.file.path,
336
+ startLine: 1,
337
+ endLine: 1,
338
+ },
339
+ properties: {
340
+ framework: handler.id,
341
+ },
342
+ });
343
+ }
344
+ return findings;
345
+ }
346
+ function detectPhpExternalApisFromConfig(ctx, config) {
347
+ if (ctx.language !== "php")
348
+ return [];
349
+ const calls = ctx.moduleLevelCalls ?? [];
350
+ const content = sourceOf(ctx);
351
+ const findings = [];
352
+ const urlHostPatterns = (0, helpers_1.buildThirdPartyUrlHostPatterns)(config);
353
+ for (const client of config.php.externalApis.httpClients) {
354
+ const gated = client.importNamespaces.length > 0 || client.packageNames.length > 0;
355
+ const supportsClient = !gated ||
356
+ hasAnyNamespace(ctx, client.importNamespaces) ||
357
+ hasAnyPackageName(ctx, client.packageNames);
358
+ if (!supportsClient)
359
+ continue;
360
+ let emitted = false;
361
+ const seenKeys = new Set();
362
+ const clientFindings = [];
363
+ for (const call of calls) {
364
+ const callee = call.callee ?? "";
365
+ if (!calleeMatches(callee, client.callNames, client.callNameSuffixes)) {
366
+ continue;
367
+ }
368
+ const snippet = call.argumentsSnippet ?? "";
369
+ const match = client.urlRegex.exec(snippet);
370
+ const url = match?.[1];
371
+ const serviceName = (0, helpers_1.inferServiceNameFromUrl)(url, urlHostPatterns) ??
372
+ (0, external_url_third_party_1.defaultServiceNameFromLiteralPublicUrl)(url) ??
373
+ client.clientName;
374
+ const dedupeKey = `${client.clientName}|${url ?? ""}`;
375
+ if (seenKeys.has(dedupeKey))
376
+ continue;
377
+ seenKeys.add(dedupeKey);
378
+ clientFindings.push({
379
+ pattern: client.patternId,
380
+ name: `${client.clientName}_call`,
381
+ confidence: client.confidence,
382
+ location: call.location,
383
+ properties: {
384
+ ...(url ? { url } : {}),
385
+ ...(serviceName ? { serviceName } : {}),
386
+ },
387
+ });
388
+ emitted = true;
389
+ }
390
+ // Prefer URL-bearing findings when both empty-URL and URL hits exist
391
+ // (e.g. curl_init + curl_setopt with CURLOPT_URL).
392
+ const hasUrlFinding = clientFindings.some((f) => f.properties.url);
393
+ let kept = hasUrlFinding
394
+ ? clientFindings.filter((f) => f.properties.url)
395
+ : clientFindings;
396
+ // Multiline calls often leave the URL off the callee line; pull it from content.
397
+ if (kept.length > 0 && !kept.some((f) => f.properties.url)) {
398
+ const urlMatch = client.urlRegex.exec(content);
399
+ const url = urlMatch?.[1];
400
+ if (url) {
401
+ const serviceName = (0, helpers_1.inferServiceNameFromUrl)(url, urlHostPatterns) ??
402
+ (0, external_url_third_party_1.defaultServiceNameFromLiteralPublicUrl)(url) ??
403
+ client.clientName;
404
+ kept = [
405
+ {
406
+ ...kept[0],
407
+ properties: {
408
+ ...kept[0].properties,
409
+ url,
410
+ ...(serviceName ? { serviceName } : {}),
411
+ },
412
+ },
413
+ ];
414
+ }
415
+ }
416
+ findings.push(...kept);
417
+ // Fallback: import/package present and callNames appear in content
418
+ // (covers curl_setopt where the URL is on a separate line).
419
+ if (!emitted && client.callNames.length > 0) {
420
+ if (callNameRegex(client.callNames).test(content)) {
421
+ const urlMatch = client.urlRegex.exec(content);
422
+ const url = urlMatch?.[1];
423
+ const serviceName = (0, helpers_1.inferServiceNameFromUrl)(url, urlHostPatterns) ??
424
+ (0, external_url_third_party_1.defaultServiceNameFromLiteralPublicUrl)(url) ??
425
+ client.clientName;
426
+ findings.push({
427
+ pattern: client.patternId,
428
+ name: `${client.clientName}_call`,
429
+ confidence: client.confidence,
430
+ location: {
431
+ filePath: ctx.file.path,
432
+ startLine: 1,
433
+ endLine: 1,
434
+ },
435
+ properties: {
436
+ ...(url ? { url } : {}),
437
+ ...(serviceName ? { serviceName } : {}),
438
+ },
439
+ });
440
+ emitted = true;
441
+ }
442
+ }
443
+ // SDK presence (e.g. aws_s3): gated import/package alone emits when opted in.
444
+ if (!emitted && client.emitOnPresence && gated) {
445
+ const hasImport = hasAnyNamespace(ctx, client.importNamespaces);
446
+ const hasPackage = hasAnyPackageName(ctx, client.packageNames);
447
+ if (hasImport || hasPackage) {
448
+ findings.push({
449
+ pattern: client.patternId,
450
+ name: `${client.clientName}_client`,
451
+ confidence: client.confidence,
452
+ location: {
453
+ filePath: ctx.file.path,
454
+ startLine: 1,
455
+ endLine: 1,
456
+ },
457
+ properties: {
458
+ serviceName: client.clientName,
459
+ client: client.id,
460
+ },
461
+ });
462
+ }
463
+ }
464
+ }
465
+ return findings;
466
+ }
@@ -7,6 +7,7 @@ const python_1 = require("./detectors/python");
7
7
  const cpp_1 = require("./detectors/cpp");
8
8
  const csharp_1 = require("./detectors/csharp");
9
9
  const go_1 = require("./detectors/go");
10
+ const php_1 = require("./detectors/php");
10
11
  const jvm_1 = require("./detectors/jvm");
11
12
  const typescript_1 = require("./detectors/typescript");
12
13
  function findFirstLineMatch(content, regex) {
@@ -125,6 +126,12 @@ function matchPatterns(ctx) {
125
126
  findings.push(...(0, go_1.detectGoExternalApisFromConfig)(ctx, config));
126
127
  findings.push(...(0, go_1.detectGoRoutesFromConfig)(ctx, config));
127
128
  findings.push(...(0, go_1.detectGoServerlessHandlersFromConfig)(ctx, config));
129
+ findings.push(...(0, php_1.detectPhpDatabaseConnectionsFromConfig)(ctx, config));
130
+ findings.push(...(0, php_1.detectPhpAuthFromConfig)(ctx, config));
131
+ findings.push(...(0, php_1.detectPhpEnvAndConfigFromConfig)(ctx, config));
132
+ findings.push(...(0, php_1.detectPhpExternalApisFromConfig)(ctx, config));
133
+ findings.push(...(0, php_1.detectPhpRoutesFromConfig)(ctx, config));
134
+ findings.push(...(0, php_1.detectPhpServerlessHandlersFromConfig)(ctx, config));
128
135
  findings.push(...(0, jvm_1.detectJvmDatabaseConnectionsFromConfig)(ctx, config));
129
136
  findings.push(...(0, jvm_1.detectJvmAuthFromConfig)(ctx, config));
130
137
  findings.push(...(0, jvm_1.detectJvmEnvAndConfigFromConfig)(ctx, config));
@@ -0,0 +1,6 @@
1
+ import type { ReportCliUsageEventInput } from "./telemetry.types";
2
+ export declare function isCliTelemetryEnabled(env?: NodeJS.ProcessEnv): boolean;
3
+ /**
4
+ * Fire-and-forget CLI usage telemetry. Never throws.
5
+ */
6
+ export declare function reportCliUsageEvent(input: ReportCliUsageEventInput, env?: NodeJS.ProcessEnv): Promise<void>;