@dataparade/cli 0.0.11 → 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 (48) 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/config/file.js +1 -0
  21. package/dist/src/config/resolve.js +1 -0
  22. package/dist/src/core/pipeline/classifier-phase.js +3 -3
  23. package/dist/src/core/pipeline/structural-scan.js +39 -14
  24. package/dist/src/core/schema/scan-config.schema.d.ts +1 -0
  25. package/dist/src/core/schema/scan-config.schema.js +1 -0
  26. package/dist/src/core/schema/scan-result.schema.d.ts +1 -0
  27. package/dist/src/core/schema/scan-result.schema.js +1 -0
  28. package/dist/src/core/sectioning/discover-service-sections.js +3 -0
  29. package/dist/src/core/types/file.d.ts +1 -1
  30. package/dist/src/ingest/file-system.js +3 -0
  31. package/dist/src/patterns/config.d.ts +2 -0
  32. package/dist/src/patterns/config.js +31 -0
  33. package/dist/src/patterns/detectors/php.d.ts +9 -0
  34. package/dist/src/patterns/detectors/php.js +466 -0
  35. package/dist/src/patterns/engine.js +7 -0
  36. package/dist/tests/unit/analyzers/php/dependency-manifests.spec.d.ts +1 -0
  37. package/dist/tests/unit/analyzers/php/dependency-manifests.spec.js +54 -0
  38. package/dist/tests/unit/analyzers/php/parser.spec.d.ts +1 -0
  39. package/dist/tests/unit/analyzers/php/parser.spec.js +128 -0
  40. package/dist/tests/unit/analyzers/php/patterns.spec.d.ts +1 -0
  41. package/dist/tests/unit/analyzers/php/patterns.spec.js +334 -0
  42. package/dist/tests/unit/classifier/classify.spec.js +68 -0
  43. package/dist/tests/unit/ingest/php-languages.spec.d.ts +1 -0
  44. package/dist/tests/unit/ingest/php-languages.spec.js +40 -0
  45. package/package.json +1 -1
  46. package/patterns/php.md +74 -0
  47. package/patterns/php.patterns.yaml +311 -0
  48. package/patterns/third-party.patterns.yaml +10 -0
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const parser_1 = require("../../../../src/analyzers/php/parser");
4
+ function createPhpFile(content, path = "index.php") {
5
+ return {
6
+ path,
7
+ name: path,
8
+ content,
9
+ language: "php",
10
+ size: content.length,
11
+ };
12
+ }
13
+ describe("PHP parser - parsePhpSourceFile", () => {
14
+ it("indexes namespace, use imports, classes, functions, and calls", () => {
15
+ const content = [
16
+ "<?php",
17
+ "",
18
+ "namespace App\\Http;",
19
+ "",
20
+ "use GuzzleHttp\\Client;",
21
+ "use Illuminate\\Support\\Facades\\DB as Database;",
22
+ "require_once 'vendor/autoload.php';",
23
+ "",
24
+ "class OrdersController",
25
+ "{",
26
+ " public function index()",
27
+ " {",
28
+ ' $client = new Client();',
29
+ ' $client->get("https://api.example.com/items");',
30
+ " return Database::table('orders')->get();",
31
+ " }",
32
+ "}",
33
+ "",
34
+ "function boot()",
35
+ "{",
36
+ ' getenv("APP_KEY");',
37
+ "}",
38
+ "",
39
+ ].join("\n");
40
+ const result = (0, parser_1.parsePhpSourceFile)(createPhpFile(content));
41
+ expect(result.warnings).toEqual([]);
42
+ expect(result.namespace).toBe("App\\Http");
43
+ expect(result.imports.map((i) => i.path)).toEqual([
44
+ "GuzzleHttp\\Client",
45
+ "Illuminate\\Support\\Facades\\DB",
46
+ "vendor/autoload.php",
47
+ ]);
48
+ const guzzle = result.imports.find((i) => i.path === "GuzzleHttp\\Client");
49
+ expect(guzzle?.isRequire).toBe(false);
50
+ const db = result.imports.find((i) => i.path === "Illuminate\\Support\\Facades\\DB");
51
+ expect(db?.alias).toBe("Database");
52
+ const require = result.imports.find((i) => i.path === "vendor/autoload.php");
53
+ expect(require?.isRequire).toBe(true);
54
+ const controller = result.types.find((t) => t.name === "OrdersController");
55
+ expect(controller?.kind).toBe("class");
56
+ const index = result.functions.find((fn) => fn.name === "index");
57
+ expect(index?.className).toBe("OrdersController");
58
+ const boot = result.functions.find((fn) => fn.name === "boot");
59
+ expect(boot?.className).toBeUndefined();
60
+ expect(result.calls.some((c) => c.callee === "new Client")).toBe(true);
61
+ expect(result.calls.some((c) => c.callee === "->get")).toBe(true);
62
+ expect(result.calls.some((c) => c.callee === "Database::table")).toBe(true);
63
+ expect(result.calls.some((c) => c.callee === "getenv")).toBe(true);
64
+ });
65
+ it("blanks comments while preserving string literals and layout", () => {
66
+ const content = [
67
+ "<?php",
68
+ '// $client->get("https://old.example.com");',
69
+ "# ignored hash comment",
70
+ '/* $client->get("https://block.example.com"); */',
71
+ '$client->get("https://live.example.com");',
72
+ "",
73
+ ].join("\n");
74
+ const result = (0, parser_1.parsePhpSourceFile)(createPhpFile(content));
75
+ expect(result.strippedContent).not.toContain("old.example.com");
76
+ expect(result.strippedContent).not.toContain("block.example.com");
77
+ expect(result.strippedContent).toContain("https://live.example.com");
78
+ expect(result.calls.some((c) => c.callee === "->get")).toBe(true);
79
+ });
80
+ it("preserves PHP 8 attributes when stripping hash comments", () => {
81
+ const content = [
82
+ "<?php",
83
+ "",
84
+ '#[Route("/api/users", methods: ["GET"])]',
85
+ "class UsersController",
86
+ "{",
87
+ "}",
88
+ "",
89
+ ].join("\n");
90
+ const result = (0, parser_1.parsePhpSourceFile)(createPhpFile(content));
91
+ expect(result.strippedContent).toContain('#[Route("/api/users"');
92
+ });
93
+ it("expands grouped use imports into full paths", () => {
94
+ const content = [
95
+ "<?php",
96
+ "",
97
+ "use GuzzleHttp\\{Client, HandlerStack};",
98
+ "use Slim\\{App as SlimApp, Routing\\RouteCollector};",
99
+ "use function App\\Helpers\\{format, slugify as toSlug};",
100
+ "",
101
+ ].join("\n");
102
+ const result = (0, parser_1.parsePhpSourceFile)(createPhpFile(content));
103
+ expect(result.imports.map((i) => i.path)).toEqual([
104
+ "GuzzleHttp\\Client",
105
+ "GuzzleHttp\\HandlerStack",
106
+ "Slim\\App",
107
+ "Slim\\Routing\\RouteCollector",
108
+ "App\\Helpers\\format",
109
+ "App\\Helpers\\slugify",
110
+ ]);
111
+ const slimApp = result.imports.find((i) => i.path === "Slim\\App");
112
+ expect(slimApp?.alias).toBe("SlimApp");
113
+ const slugify = result.imports.find((i) => i.path === "App\\Helpers\\slugify");
114
+ expect(slugify?.alias).toBe("toSlug");
115
+ });
116
+ it("returns a warning for non-php language", () => {
117
+ const file = {
118
+ path: "main.go",
119
+ name: "main.go",
120
+ content: "package main",
121
+ language: "go",
122
+ size: 12,
123
+ };
124
+ const result = (0, parser_1.parsePhpSourceFile)(file);
125
+ expect(result.warnings.length).toBe(1);
126
+ expect(result.imports).toEqual([]);
127
+ });
128
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,334 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const detector_1 = require("../../../../src/analyzers/php/detector");
4
+ function makePhpFile(content, path = "index.php") {
5
+ return {
6
+ path,
7
+ name: path,
8
+ content,
9
+ language: "php",
10
+ size: content.length,
11
+ };
12
+ }
13
+ describe("PHP analyzer patterns", () => {
14
+ it("detects Laravel routes with their HTTP method", () => {
15
+ const content = [
16
+ "<?php",
17
+ "",
18
+ "Route::get('/customers', [CustomerController::class, 'index']);",
19
+ "Route::post('/charges', [ChargeController::class, 'store']);",
20
+ "",
21
+ ].join("\n");
22
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "routes/web.php"));
23
+ const routes = findings.filter((f) => f.pattern === "express_route");
24
+ expect(routes.map((r) => r.name).sort()).toEqual([
25
+ "GET /customers",
26
+ "POST /charges",
27
+ ]);
28
+ expect(routes[0].properties.framework).toBe("laravel");
29
+ });
30
+ it("detects Slim routes when Slim is imported", () => {
31
+ const content = [
32
+ "<?php",
33
+ "",
34
+ "use Slim\\App;",
35
+ "",
36
+ "$app->get('/health', $healthHandler);",
37
+ "$app->post('/orders', $createOrder);",
38
+ "",
39
+ ].join("\n");
40
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "app.php"));
41
+ const routes = findings.filter((f) => f.pattern === "express_route");
42
+ expect(routes.map((r) => r.name).sort()).toEqual([
43
+ "GET /health",
44
+ "POST /orders",
45
+ ]);
46
+ expect(routes[0].properties.framework).toBe("slim");
47
+ });
48
+ it("resolves the engine from a PDO DSN", () => {
49
+ const content = [
50
+ "<?php",
51
+ "",
52
+ '$db = new PDO("pgsql:host=localhost;dbname=app", $user, $pass);',
53
+ "",
54
+ ].join("\n");
55
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "db.php"));
56
+ const dbs = findings.filter((f) => f.pattern === "database_connection");
57
+ const pdoDsn = dbs.find((d) => d.properties.client === "pdo_dsn");
58
+ expect(pdoDsn).toBeDefined();
59
+ expect(pdoDsn?.properties.driver).toBe("pgsql");
60
+ expect(pdoDsn?.properties.databaseType).toBe("postgres");
61
+ });
62
+ it("detects Guzzle external API calls with a URL", () => {
63
+ const content = [
64
+ "<?php",
65
+ "",
66
+ "use GuzzleHttp\\Client;",
67
+ "",
68
+ "$client = new Client();",
69
+ '$response = $client->get("https://api.stripe.com/v1/charges");',
70
+ "",
71
+ ].join("\n");
72
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "billing.php"));
73
+ const apis = findings.filter((f) => f.pattern === "external_api_call");
74
+ expect(apis.length).toBeGreaterThan(0);
75
+ expect(apis.some((a) => String(a.properties.url ?? "").includes("stripe.com"))).toBe(true);
76
+ });
77
+ it("detects env() and getenv variable reads", () => {
78
+ const content = [
79
+ "<?php",
80
+ "",
81
+ '$key = getenv("APP_KEY");',
82
+ '$db = env("DB_CONNECTION");',
83
+ '$fromEnv = $_ENV["STRIPE_SECRET"];',
84
+ "",
85
+ ].join("\n");
86
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "config.php"));
87
+ const envs = findings.filter((f) => f.pattern === "env_variable");
88
+ expect(envs.map((e) => e.properties.key).sort()).toEqual([
89
+ "APP_KEY",
90
+ "DB_CONNECTION",
91
+ "STRIPE_SECRET",
92
+ ]);
93
+ });
94
+ it("detects Sanctum auth from a use import", () => {
95
+ const content = [
96
+ "<?php",
97
+ "",
98
+ "use Laravel\\Sanctum\\HasApiTokens;",
99
+ "",
100
+ "class User",
101
+ "{",
102
+ " use HasApiTokens;",
103
+ "}",
104
+ "",
105
+ ].join("\n");
106
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "User.php"));
107
+ const auth = findings.filter((f) => f.pattern === "auth_middleware");
108
+ expect(auth.map((a) => a.name)).toContain("laravel_sanctum");
109
+ });
110
+ it("detects Symfony attribute routes", () => {
111
+ const content = [
112
+ "<?php",
113
+ "",
114
+ '#[Route("/api/users", methods: ["GET"])]',
115
+ "class UsersController",
116
+ "{",
117
+ "}",
118
+ "",
119
+ ].join("\n");
120
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "UsersController.php"));
121
+ const routes = findings.filter((f) => f.pattern === "express_route");
122
+ expect(routes.map((r) => r.name)).toContain("SYMFONY_ROUTE /api/users");
123
+ expect(routes[0].properties.framework).toBe("symfony");
124
+ });
125
+ it("detects Symfony docblock @Route annotations", () => {
126
+ const content = [
127
+ "<?php",
128
+ "",
129
+ "/**",
130
+ " * @Route(\"/legacy\")",
131
+ " */",
132
+ "class LegacyController",
133
+ "{",
134
+ "}",
135
+ "",
136
+ ].join("\n");
137
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "LegacyController.php"));
138
+ const routes = findings.filter((f) => f.pattern === "express_route");
139
+ expect(routes.map((r) => r.name)).toContain("SYMFONY_ROUTE /legacy");
140
+ expect(routes[0].properties.framework).toBe("symfony");
141
+ });
142
+ it("does not treat Guzzle new Client() as Predis", () => {
143
+ const content = [
144
+ "<?php",
145
+ "",
146
+ "use GuzzleHttp\\Client;",
147
+ "",
148
+ "$client = new Client();",
149
+ '$response = $client->get("https://api.stripe.com/v1/charges");',
150
+ "",
151
+ ].join("\n");
152
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "billing.php"));
153
+ const dbs = findings.filter((f) => f.pattern === "database_connection");
154
+ expect(dbs.map((d) => d.name)).not.toContain("predis");
155
+ });
156
+ it("detects Predis when Predis is imported", () => {
157
+ const content = [
158
+ "<?php",
159
+ "",
160
+ "use Predis\\Client;",
161
+ "",
162
+ "$redis = new Client();",
163
+ "",
164
+ ].join("\n");
165
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "cache.php"));
166
+ const dbs = findings.filter((f) => f.pattern === "database_connection");
167
+ expect(dbs.map((d) => d.name)).toContain("predis");
168
+ });
169
+ it("resolves the engine from a fully-qualified new \\PDO DSN", () => {
170
+ const content = [
171
+ "<?php",
172
+ "",
173
+ '$db = new \\PDO("pgsql:host=localhost;dbname=app", $user, $pass);',
174
+ "",
175
+ ].join("\n");
176
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "db.php"));
177
+ const dbs = findings.filter((f) => f.pattern === "database_connection");
178
+ const pdoDsn = dbs.find((d) => d.properties.client === "pdo_dsn");
179
+ expect(pdoDsn).toBeDefined();
180
+ expect(pdoDsn?.properties.driver).toBe("pgsql");
181
+ expect(pdoDsn?.properties.databaseType).toBe("postgres");
182
+ });
183
+ it("detects mysqli with a leading backslash", () => {
184
+ const content = [
185
+ "<?php",
186
+ "",
187
+ '$db = new \\mysqli("localhost", "user", "pass", "app");',
188
+ "",
189
+ ].join("\n");
190
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "db.php"));
191
+ const dbs = findings.filter((f) => f.pattern === "database_connection");
192
+ expect(dbs.map((d) => d.name)).toContain("mysqli");
193
+ });
194
+ it("detects Guzzle calls when imported via grouped use", () => {
195
+ const content = [
196
+ "<?php",
197
+ "",
198
+ "use GuzzleHttp\\{Client};",
199
+ "",
200
+ "$client = new Client();",
201
+ '$response = $client->get("https://api.stripe.com/v1/charges");',
202
+ "",
203
+ ].join("\n");
204
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "billing.php"));
205
+ const apis = findings.filter((f) => f.pattern === "external_api_call");
206
+ expect(apis.length).toBeGreaterThan(0);
207
+ expect(apis.some((a) => String(a.properties.url ?? "").includes("stripe.com"))).toBe(true);
208
+ });
209
+ it("detects Slim routes when imported via grouped use", () => {
210
+ const content = [
211
+ "<?php",
212
+ "",
213
+ "use Slim\\{App};",
214
+ "",
215
+ "$app->get('/health', $healthHandler);",
216
+ "$app->post('/orders', $createOrder);",
217
+ "",
218
+ ].join("\n");
219
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "app.php"));
220
+ const routes = findings.filter((f) => f.pattern === "express_route");
221
+ expect(routes.map((r) => r.name).sort()).toEqual([
222
+ "GET /health",
223
+ "POST /orders",
224
+ ]);
225
+ expect(routes[0].properties.framework).toBe("slim");
226
+ });
227
+ it("detects Laravel config() helper as config_file", () => {
228
+ const content = ["<?php", "", '$name = config("app.name");', ""].join("\n");
229
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "settings.php"));
230
+ const configs = findings.filter((f) => f.pattern === "config_file");
231
+ expect(configs.map((c) => c.name)).toContain("laravel_config");
232
+ });
233
+ it("detects Guzzle when the URL is on the line after ->get", () => {
234
+ const content = [
235
+ "<?php",
236
+ "",
237
+ "use GuzzleHttp\\Client;",
238
+ "",
239
+ "$client = new Client();",
240
+ "$response = $client->get(",
241
+ ' "https://api.stripe.com/v1/charges"',
242
+ ");",
243
+ "",
244
+ ].join("\n");
245
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "billing.php"));
246
+ const apis = findings.filter((f) => f.pattern === "external_api_call");
247
+ expect(apis.length).toBeGreaterThan(0);
248
+ expect(apis.some((a) => String(a.properties.url ?? "").includes("stripe.com"))).toBe(true);
249
+ });
250
+ it("emits a single curl finding for init/setopt/exec with one URL", () => {
251
+ const content = [
252
+ "<?php",
253
+ "",
254
+ "$ch = curl_init();",
255
+ 'curl_setopt($ch, CURLOPT_URL, "https://api.example.com/v1");',
256
+ "curl_exec($ch);",
257
+ "",
258
+ ].join("\n");
259
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "http.php"));
260
+ const curls = findings.filter((f) => f.pattern === "external_api_call" &&
261
+ String(f.name).startsWith("curl"));
262
+ expect(curls).toHaveLength(1);
263
+ expect(String(curls[0].properties.url ?? "")).toContain("api.example.com");
264
+ });
265
+ it("detects Eloquent via Eloquent:: method calls when imported", () => {
266
+ const content = [
267
+ "<?php",
268
+ "",
269
+ "use Illuminate\\Database\\Eloquent\\Model;",
270
+ "",
271
+ "Eloquent::unguard();",
272
+ "",
273
+ ].join("\n");
274
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "model.php"));
275
+ const dbs = findings.filter((f) => f.pattern === "database_connection");
276
+ expect(dbs.map((d) => d.name)).toContain("eloquent");
277
+ });
278
+ it("detects Laravel Socialite as oauth2 auth_middleware", () => {
279
+ const content = [
280
+ "<?php",
281
+ "",
282
+ "use Laravel\\Socialite\\Facades\\Socialite;",
283
+ "",
284
+ "return Socialite::driver('google')->redirect();",
285
+ "",
286
+ ].join("\n");
287
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "oauth.php"));
288
+ const auth = findings.filter((f) => f.pattern === "auth_middleware");
289
+ expect(auth.map((a) => a.name)).toContain("laravel_socialite");
290
+ expect(auth.find((a) => a.name === "laravel_socialite")?.properties.strategy).toBe("oauth2");
291
+ });
292
+ it("detects league/oauth2-client as oauth2 auth_middleware", () => {
293
+ const content = [
294
+ "<?php",
295
+ "",
296
+ "use League\\OAuth2\\Client\\Provider\\GenericProvider;",
297
+ "",
298
+ "$provider = new GenericProvider([]);",
299
+ "",
300
+ ].join("\n");
301
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "oidc.php"));
302
+ const auth = findings.filter((f) => f.pattern === "auth_middleware");
303
+ expect(auth.map((a) => a.name)).toContain("league_oauth2_client");
304
+ expect(auth.find((a) => a.name === "league_oauth2_client")?.properties.strategy).toBe("oauth2");
305
+ });
306
+ it("detects AWS S3 from Aws\\S3 import presence", () => {
307
+ const content = [
308
+ "<?php",
309
+ "",
310
+ "use Aws\\S3\\S3Client;",
311
+ "",
312
+ "$client = new S3Client([]);",
313
+ "",
314
+ ].join("\n");
315
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "storage.php"));
316
+ const apis = findings.filter((f) => f.pattern === "external_api_call");
317
+ expect(apis.some((a) => a.properties.serviceName === "aws" ||
318
+ a.properties.client === "aws_s3")).toBe(true);
319
+ });
320
+ it("detects AWS S3 from league/flysystem-aws-s3-v3 package import", () => {
321
+ const content = [
322
+ "<?php",
323
+ "",
324
+ "use League\\Flysystem\\AwsS3V3\\AwsS3V3Adapter;",
325
+ "",
326
+ "$adapter = new AwsS3V3Adapter($client, 'bucket');",
327
+ "",
328
+ ].join("\n");
329
+ const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "flysystem.php"));
330
+ const apis = findings.filter((f) => f.pattern === "external_api_call");
331
+ expect(apis.some((a) => a.properties.serviceName === "aws" ||
332
+ a.properties.client === "aws_s3")).toBe(true);
333
+ });
334
+ });
@@ -1099,6 +1099,74 @@ describe("classifier/dedupe & application asset - DP-P0-CLI-204", () => {
1099
1099
  expect(auth0?.properties.authentication_method).toBe("jwt");
1100
1100
  expect(auth0?.type).toBe("third_party");
1101
1101
  });
1102
+ it("merges auth_service into HTTP API instead of database when no IdP or main app", () => {
1103
+ const components = [
1104
+ makeComponent({
1105
+ id: "api_1",
1106
+ name: "API",
1107
+ type: "asset",
1108
+ subType: "api",
1109
+ properties: {
1110
+ section_id: "root",
1111
+ isSectionApiNode: true,
1112
+ },
1113
+ detectedFrom: [
1114
+ {
1115
+ pattern: "express_route",
1116
+ sourceLocation: makeLocation({ filePath: "routes/web.php" }),
1117
+ },
1118
+ ],
1119
+ }),
1120
+ makeComponent({
1121
+ id: "db_1",
1122
+ name: "Eloquent",
1123
+ type: "asset",
1124
+ subType: "database",
1125
+ properties: { section_id: "root", client: "eloquent" },
1126
+ }),
1127
+ makeComponent({
1128
+ id: "auth_1",
1129
+ name: "Laravel Socialite",
1130
+ type: "asset",
1131
+ subType: "auth_service",
1132
+ properties: {
1133
+ section_id: "root",
1134
+ strategy: "oauth2",
1135
+ authentication_method: "oauth_2_0",
1136
+ },
1137
+ }),
1138
+ ];
1139
+ const compacted = (0, classify_1.compactAuthServiceComponents)(components);
1140
+ expect(compacted.find((c) => c.id === "auth_1")).toBeUndefined();
1141
+ const api = compacted.find((c) => c.id === "api_1");
1142
+ expect(api).toBeDefined();
1143
+ expect(api?.properties.strategy).toBe("oauth2");
1144
+ expect(api?.properties.authentication_method).toBe("oauth_2_0");
1145
+ expect(api?.subType).toBe("api");
1146
+ const db = compacted.find((c) => c.id === "db_1");
1147
+ expect(db?.detectedFrom.some((r) => r.pattern === "auth_middleware")).toBe(false);
1148
+ });
1149
+ it("keeps auth_service standalone when only database assets exist in section", () => {
1150
+ const components = [
1151
+ makeComponent({
1152
+ id: "db_1",
1153
+ name: "Eloquent",
1154
+ type: "asset",
1155
+ subType: "database",
1156
+ properties: { section_id: "root", client: "eloquent" },
1157
+ }),
1158
+ makeComponent({
1159
+ id: "auth_1",
1160
+ name: "Laravel Socialite",
1161
+ type: "asset",
1162
+ subType: "auth_service",
1163
+ properties: { section_id: "root", strategy: "oauth2" },
1164
+ }),
1165
+ ];
1166
+ const compacted = (0, classify_1.compactAuthServiceComponents)(components);
1167
+ expect(compacted.find((c) => c.id === "auth_1")).toBeDefined();
1168
+ expect(compacted.find((c) => c.id === "db_1")).toBeDefined();
1169
+ });
1102
1170
  });
1103
1171
  it("merges third_party components by serviceName even when names differ", () => {
1104
1172
  const components = [
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const promises_1 = __importDefault(require("fs/promises"));
7
+ const os_1 = __importDefault(require("os"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const file_system_1 = require("../../../src/ingest/file-system");
10
+ describe("ingest/file-system - PHP language mapping", () => {
11
+ let root;
12
+ beforeAll(async () => {
13
+ root = await promises_1.default.mkdtemp(path_1.default.join(os_1.default.tmpdir(), "dp-ingest-php-"));
14
+ const files = {
15
+ "index.php": "<?php echo 'ok';",
16
+ "view.phtml": "<?= $title ?>",
17
+ "notes.md": "# notes",
18
+ };
19
+ for (const [name, content] of Object.entries(files)) {
20
+ await promises_1.default.writeFile(path_1.default.join(root, name), content, "utf8");
21
+ }
22
+ await promises_1.default.mkdir(path_1.default.join(root, "vendor", "guzzlehttp"), { recursive: true });
23
+ await promises_1.default.writeFile(path_1.default.join(root, "vendor", "guzzlehttp", "Client.php"), "<?php class Client {}", "utf8");
24
+ });
25
+ afterAll(async () => {
26
+ await promises_1.default.rm(root, { recursive: true, force: true });
27
+ });
28
+ it("maps .php and .phtml to php", async () => {
29
+ const files = await (0, file_system_1.ingestFileSystem)(root);
30
+ const byName = new Map(files.map((file) => [file.name, file.language]));
31
+ expect(byName.get("index.php")).toBe("php");
32
+ expect(byName.get("view.phtml")).toBe("php");
33
+ expect(byName.has("notes.md")).toBe(false);
34
+ });
35
+ it("excludes Composer vendor/ by default", async () => {
36
+ const files = await (0, file_system_1.ingestFileSystem)(root);
37
+ const names = files.map((file) => file.name);
38
+ expect(names).not.toContain("Client.php");
39
+ });
40
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataparade/cli",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "dataPARADE CLI — scan codebases for privacy and security data flows",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -0,0 +1,74 @@
1
+ # PHP Patterns (CLI Scanner)
2
+
3
+ This document describes the PHP patterns implemented by the CLI codebase
4
+ scanner.
5
+
6
+ The PHP analyzer emits `RawFinding[]` using the **shared pattern IDs** from
7
+ `core/types/detection.ts`:
8
+
9
+ - `express_route`
10
+ - `database_connection`
11
+ - `external_api_call`
12
+ - `auth_middleware`
13
+ - `config_file`
14
+ - `env_variable`
15
+ - `lambda_handler`
16
+
17
+ These pattern IDs align with the TypeScript/JavaScript, Python, Go, C++, and C#
18
+ analyzers so that the classifier and data-flow detector treat every language
19
+ consistently.
20
+
21
+ ## Structure
22
+
23
+ - **YAML configuration** at `cli/patterns/php.patterns.yaml` defines pattern
24
+ IDs, namespaces, Composer package names, call names, route regexes, and
25
+ confidences.
26
+ - **Config loader** (`cli/src/analyzers/php/php-detection-config.ts`) validates
27
+ the YAML and compiles its regexes.
28
+ - **Parser** (`cli/src/analyzers/php/parser.ts`) produces a source-file model:
29
+ namespace, `use` / `require` imports, classes/interfaces/traits, functions,
30
+ and call sites (`Class::method`, `$obj->method`, `new Class`, functions).
31
+ - **Detectors** (`cli/src/patterns/detectors/php.ts`) run inside the shared
32
+ `matchPatterns()` engine (one call per file).
33
+
34
+ ### Namespace vs Composer package matching
35
+
36
+ | Field | Shape | Example |
37
+ | --- | --- | --- |
38
+ | `importNamespaces` | PSR namespace / class (`\`) | `GuzzleHttp`, `Illuminate\Database` |
39
+ | `packageNames` | Composer package (`/`) | `guzzlehttp/guzzle`, `laravel/framework` |
40
+
41
+ The two spaces stay disjoint so a `composer.json` hit does not also match as a
42
+ `use` statement (and vice versa).
43
+
44
+ ## Routes
45
+
46
+ - **Laravel** — `Route::get/post/...` (ungated; facade is usually unimported)
47
+ - **Symfony** — `#[Route(...)]` (attributes kept when stripping `#` comments) and
48
+ `@Route(...)` (docblock annotations scanned from raw source)
49
+ - **Slim** — `$app->get/post/...` when Slim is imported
50
+
51
+ ## Database
52
+
53
+ - PDO, Eloquent / Illuminate, Doctrine DBAL/ORM, mysqli, Predis, MongoDB
54
+ - `pdo_dsn` resolves `new PDO(...)` / `new \PDO(...)` to a concrete `databaseType`
55
+ - Gated clients (Predis, Eloquent, …) require a matching `use` or Composer
56
+ package so a bare `new Client()` does not false-positive
57
+
58
+ ## External APIs
59
+
60
+ - Guzzle (`->get` / `->request` with URL)
61
+ - cURL (`curl_setopt` / `curl_exec`)
62
+ - Symfony HttpClient
63
+ - AWS S3 (`Aws\S3`, `league/flysystem-aws-s3-v3`; presence-gated)
64
+
65
+ ## Auth / env
66
+
67
+ - Sanctum, Passport, Socialite, league/oauth2-client, firebase/php-jwt, Symfony Security, bearer headers
68
+ - `getenv` / `env()` / `$_ENV` / `$_SERVER`
69
+
70
+ ## Dependency manifests
71
+
72
+ `composer.json` `require` / `require-dev` package names feed `matchPatterns`
73
+ the same way `go.mod` does for Go. Platform requirements (`php`, `ext-*`) are
74
+ skipped. `composer.json` is also a monorepo **service-section** marker.