@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
package/dist/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,10 @@
1
+ import type { RawFinding } from "../../core/types/detection";
2
+ import { type ManifestScanBudgetOptions } from "../shared/manifest-budgets";
3
+ export interface PhpManifestPackages {
4
+ manifestRelativePath: string;
5
+ /** The package's own name from composer.json `name`. */
6
+ packageName?: string;
7
+ packages: string[];
8
+ }
9
+ export declare function parsePhpDependencyManifests(rootPath: string, opts?: ManifestScanBudgetOptions): Promise<PhpManifestPackages[]>;
10
+ export declare function detectPhpPatternsFromDependencyManifests(rootPath: string, opts?: ManifestScanBudgetOptions): Promise<RawFinding[]>;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.parsePhpDependencyManifests = parsePhpDependencyManifests;
40
+ exports.detectPhpPatternsFromDependencyManifests = detectPhpPatternsFromDependencyManifests;
41
+ const promises_1 = __importDefault(require("fs/promises"));
42
+ const path = __importStar(require("path"));
43
+ const engine_1 = require("../../patterns/engine");
44
+ const manifest_budgets_1 = require("../shared/manifest-budgets");
45
+ const manifest_fs_1 = require("../shared/manifest-fs");
46
+ const manifest_parsers_1 = require("./manifest-parsers");
47
+ function toPosixPath(p) {
48
+ return p.split(path.sep).join("/");
49
+ }
50
+ function createManifestFileInfo(manifestRelativePath) {
51
+ return {
52
+ path: manifestRelativePath,
53
+ name: path.basename(manifestRelativePath),
54
+ content: "",
55
+ language: "php",
56
+ size: 0,
57
+ };
58
+ }
59
+ async function parsePhpDependencyManifests(rootPath, opts) {
60
+ const rootDir = path.resolve(rootPath);
61
+ const manifests = [];
62
+ const state = (0, manifest_budgets_1.budgetStateFromOptions)(opts);
63
+ await (0, manifest_fs_1.walkForManifests)(rootDir, manifests, {
64
+ rootDir,
65
+ state,
66
+ excludePaths: opts?.excludePaths,
67
+ isManifestFile: (_entry, entryPath) => path.basename(entryPath).toLowerCase() === "composer.json",
68
+ });
69
+ const byManifest = [];
70
+ let bytesRead = 0;
71
+ const maxBytes = state.maxTotalManifestReadBytes;
72
+ for (const manifestAbsPath of manifests) {
73
+ if (bytesRead >= maxBytes)
74
+ break;
75
+ const manifestRelativePath = toPosixPath(path.relative(rootDir, manifestAbsPath));
76
+ let raw;
77
+ try {
78
+ raw = await promises_1.default.readFile(manifestAbsPath, "utf8");
79
+ }
80
+ catch {
81
+ continue;
82
+ }
83
+ bytesRead += raw.length;
84
+ const parsed = (0, manifest_parsers_1.parseComposerJson)(raw);
85
+ if (parsed.packages.length === 0)
86
+ continue;
87
+ byManifest.push({
88
+ manifestRelativePath,
89
+ packageName: parsed.name,
90
+ packages: Array.from(new Set(parsed.packages)),
91
+ });
92
+ }
93
+ return byManifest;
94
+ }
95
+ async function detectPhpPatternsFromDependencyManifests(rootPath, opts) {
96
+ const manifestPackages = await parsePhpDependencyManifests(rootPath, opts);
97
+ if (manifestPackages.length === 0)
98
+ return [];
99
+ const findings = [];
100
+ for (const manifest of manifestPackages) {
101
+ const manifestFile = createManifestFileInfo(manifest.manifestRelativePath);
102
+ const imports = manifest.packages.map((p) => {
103
+ const segments = p.split("/").filter(Boolean);
104
+ return {
105
+ module: p,
106
+ names: Array.from(new Set([p, ...segments])),
107
+ };
108
+ });
109
+ findings.push(...(0, engine_1.matchPatterns)({
110
+ language: "php",
111
+ file: manifestFile,
112
+ normalizedPath: manifestFile.path,
113
+ imports,
114
+ }));
115
+ }
116
+ return findings;
117
+ }
@@ -0,0 +1,3 @@
1
+ import type { FileInfo } from "../../core/types/file";
2
+ import type { RawFinding } from "../../core/types/detection";
3
+ export declare function detectPhpPatterns(file: FileInfo): RawFinding[];
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectPhpPatterns = detectPhpPatterns;
4
+ const property_inference_1 = require("../shared/property-inference");
5
+ const parser_1 = require("./parser");
6
+ const patterns_1 = require("./patterns");
7
+ function detectPhpPatterns(file) {
8
+ const model = (0, parser_1.parsePhpSourceFile)(file);
9
+ if (model.file.language !== "php") {
10
+ return [];
11
+ }
12
+ const findings = (0, patterns_1.detectPhpPatternsFromModel)(model);
13
+ for (const finding of findings) {
14
+ const detected = (0, property_inference_1.getPropertiesFromFinding)(finding, file.content);
15
+ if (Object.keys(detected).length > 0) {
16
+ finding.properties = { ...(finding.properties ?? {}), ...detected };
17
+ }
18
+ }
19
+ return findings;
20
+ }
@@ -0,0 +1,2 @@
1
+ import type { Analyzer } from "../types";
2
+ export declare function createPhpAnalyzer(): Analyzer;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPhpAnalyzer = createPhpAnalyzer;
4
+ const detector_1 = require("./detector");
5
+ function createPhpAnalyzer() {
6
+ return {
7
+ detect(file) {
8
+ return (0, detector_1.detectPhpPatterns)(file);
9
+ },
10
+ };
11
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Dependency extraction for Composer manifests.
3
+ *
4
+ * `composer.json` is the package root for a PHP service. Package names
5
+ * (`guzzlehttp/guzzle`) are distinct from PSR namespaces (`GuzzleHttp\Client`)
6
+ * — detectors match them via `packageNames` vs `importNamespaces`.
7
+ */
8
+ export interface ComposerManifest {
9
+ /** `name` field, e.g. `acme/billing`. */
10
+ name?: string;
11
+ /** Package names from `require` and `require-dev`, versions stripped. */
12
+ packages: string[];
13
+ }
14
+ export declare function parseComposerJson(content: string): ComposerManifest;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /**
3
+ * Dependency extraction for Composer manifests.
4
+ *
5
+ * `composer.json` is the package root for a PHP service. Package names
6
+ * (`guzzlehttp/guzzle`) are distinct from PSR namespaces (`GuzzleHttp\Client`)
7
+ * — detectors match them via `packageNames` vs `importNamespaces`.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.parseComposerJson = parseComposerJson;
11
+ function isComposerPackageName(token) {
12
+ if (!token || token === "php" || token.startsWith("ext-"))
13
+ return false;
14
+ // Composer packages are `vendor/package`; platform reqs like `php` are skipped.
15
+ return /^[a-z0-9_.-]+\/[a-z0-9_.-]+$/i.test(token);
16
+ }
17
+ function parseComposerJson(content) {
18
+ let parsed;
19
+ try {
20
+ parsed = JSON.parse(content);
21
+ }
22
+ catch {
23
+ return { packages: [] };
24
+ }
25
+ if (!parsed || typeof parsed !== "object") {
26
+ return { packages: [] };
27
+ }
28
+ const obj = parsed;
29
+ const packages = new Set();
30
+ for (const section of [obj.require, obj["require-dev"]]) {
31
+ if (!section || typeof section !== "object")
32
+ continue;
33
+ for (const key of Object.keys(section)) {
34
+ if (isComposerPackageName(key))
35
+ packages.add(key);
36
+ }
37
+ }
38
+ const name = typeof obj.name === "string" && obj.name.trim() ? obj.name.trim() : undefined;
39
+ return { name, packages: Array.from(packages) };
40
+ }
@@ -0,0 +1,42 @@
1
+ import type { FileInfo, SourceLocation } from "../../core/types/file";
2
+ export interface PhpImportEntry {
3
+ /**
4
+ * Fully-qualified name from a `use` statement, e.g. `GuzzleHttp\Client`,
5
+ * or a require/include path for non-PSR files.
6
+ */
7
+ path: string;
8
+ /** Alias from `use Foo\Bar as Baz`. */
9
+ alias?: string;
10
+ /** True for `require` / `include` (and `_once` variants). */
11
+ isRequire: boolean;
12
+ location: SourceLocation;
13
+ }
14
+ export interface PhpFunctionEntry {
15
+ name: string;
16
+ /** Class name for methods: `function foo()` inside `class Bar`. */
17
+ className?: string;
18
+ location: SourceLocation;
19
+ }
20
+ export interface PhpTypeEntry {
21
+ name: string;
22
+ kind: "class" | "interface" | "trait";
23
+ location: SourceLocation;
24
+ }
25
+ export interface PhpCallEntry {
26
+ callee: string;
27
+ argumentsSnippet: string;
28
+ location: SourceLocation;
29
+ }
30
+ export interface PhpSourceFileModel {
31
+ file: FileInfo;
32
+ normalizedPath: string;
33
+ /** Source with comments blanked out; line/column offsets are preserved. */
34
+ strippedContent: string;
35
+ namespace?: string;
36
+ imports: PhpImportEntry[];
37
+ functions: PhpFunctionEntry[];
38
+ types: PhpTypeEntry[];
39
+ calls: PhpCallEntry[];
40
+ warnings: string[];
41
+ }
42
+ export declare function parsePhpSourceFile(file: FileInfo): PhpSourceFileModel;
@@ -0,0 +1,297 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.parsePhpSourceFile = parsePhpSourceFile;
37
+ const nodePath = __importStar(require("path"));
38
+ const strip_comments_1 = require("../shared/strip-comments");
39
+ const NAMESPACE_REGEX = /^namespace\s+([A-Za-z_\\][\w\\]*)\s*;/;
40
+ const USE_REGEX = /^use\s+(?:function\s+|const\s+)?([A-Za-z_\\][\w\\]*)(?:\s+as\s+([A-Za-z_]\w*))?\s*;/;
41
+ /** `use Foo\Bar\{A, B as Alias, Nested\C};` (and function/const variants). */
42
+ const USE_GROUP_REGEX = /^use\s+(?:function\s+|const\s+)?([A-Za-z_\\][\w\\]*)\\\{([^}]+)\}\s*;/;
43
+ const USE_GROUP_MEMBER_REGEX = /^([A-Za-z_\\][\w\\]*)(?:\s+as\s+([A-Za-z_]\w*))?$/;
44
+ const REQUIRE_REGEX = /^(?:require|include)(?:_once)?\s*\(?\s*["']([^"']+)["']/;
45
+ const TYPE_REGEX = /^(?:(?:abstract|final)\s+)?(class|interface|trait)\s+([A-Za-z_]\w*)/;
46
+ const FUNCTION_REGEX = /^(?:(?:public|protected|private|static|final)\s+)*function\s+&?([A-Za-z_]\w*)\s*\(/;
47
+ const STATIC_CALL_REGEX = /([A-Za-z_\\][\w\\]*)::([A-Za-z_]\w*)\s*\(/g;
48
+ const METHOD_CALL_REGEX = /\$[A-Za-z_]\w*\s*\??->\s*([A-Za-z_]\w*)\s*\(/g;
49
+ const NEW_CALL_REGEX = /\bnew\s+([A-Za-z_\\][\w\\]*)\s*\(/g;
50
+ const FUNC_CALL_REGEX = /\b([A-Za-z_]\w*)\s*\(/g;
51
+ const PHP_KEYWORDS = new Set([
52
+ "if",
53
+ "else",
54
+ "elseif",
55
+ "for",
56
+ "foreach",
57
+ "while",
58
+ "do",
59
+ "switch",
60
+ "case",
61
+ "function",
62
+ "class",
63
+ "interface",
64
+ "trait",
65
+ "namespace",
66
+ "use",
67
+ "return",
68
+ "echo",
69
+ "print",
70
+ "new",
71
+ "try",
72
+ "catch",
73
+ "finally",
74
+ "throw",
75
+ "match",
76
+ "isset",
77
+ "empty",
78
+ "array",
79
+ "list",
80
+ ]);
81
+ function normalizePath(p) {
82
+ if (!p)
83
+ return "";
84
+ const normalized = p.split("\\").join("/");
85
+ return normalizedPathIsRelativeToCwd(normalized)
86
+ ? normalized
87
+ : normalized.replace(nodePath.resolve(), "").replace(/^\/+/, "");
88
+ }
89
+ function normalizedPathIsRelativeToCwd(p) {
90
+ return !p.startsWith("/") && !p.match(/^[A-Za-z]:\//);
91
+ }
92
+ function emptyModel(file, normalizedPath, warnings) {
93
+ return {
94
+ file,
95
+ normalizedPath,
96
+ strippedContent: "",
97
+ imports: [],
98
+ functions: [],
99
+ types: [],
100
+ calls: [],
101
+ warnings,
102
+ };
103
+ }
104
+ function findBlockEndLine(lines, startIndex) {
105
+ let depth = 0;
106
+ let seenOpening = false;
107
+ for (let i = startIndex; i < lines.length; i += 1) {
108
+ const line = lines[i] ?? "";
109
+ for (const char of line) {
110
+ if (char === "{") {
111
+ depth += 1;
112
+ seenOpening = true;
113
+ }
114
+ else if (char === "}") {
115
+ depth -= 1;
116
+ }
117
+ }
118
+ if (seenOpening && depth <= 0)
119
+ return i + 1;
120
+ }
121
+ return startIndex + 1;
122
+ }
123
+ /**
124
+ * Expand a single-line `use` (plain or grouped) into import entries.
125
+ * Returns null when the line is not a `use` statement.
126
+ */
127
+ function parseUseImports(text, location) {
128
+ const groupMatch = text.match(USE_GROUP_REGEX);
129
+ if (groupMatch) {
130
+ const prefix = groupMatch[1];
131
+ const entries = [];
132
+ for (const rawMember of groupMatch[2].split(",")) {
133
+ const member = rawMember.trim();
134
+ if (!member)
135
+ continue;
136
+ const memberMatch = member.match(USE_GROUP_MEMBER_REGEX);
137
+ if (!memberMatch)
138
+ continue;
139
+ entries.push({
140
+ path: `${prefix}\\${memberMatch[1]}`,
141
+ alias: memberMatch[2],
142
+ isRequire: false,
143
+ location,
144
+ });
145
+ }
146
+ return entries;
147
+ }
148
+ const useMatch = text.match(USE_REGEX);
149
+ if (!useMatch)
150
+ return null;
151
+ return [
152
+ {
153
+ path: useMatch[1],
154
+ alias: useMatch[2],
155
+ isRequire: false,
156
+ location,
157
+ },
158
+ ];
159
+ }
160
+ function extractCalls(lines, filePath) {
161
+ const calls = [];
162
+ for (let i = 0; i < lines.length; i += 1) {
163
+ const line = lines[i] ?? "";
164
+ const lineNumber = i + 1;
165
+ const location = {
166
+ filePath,
167
+ startLine: lineNumber,
168
+ endLine: lineNumber,
169
+ };
170
+ const push = (callee, fromIndex) => {
171
+ const openParen = line.indexOf("(", fromIndex);
172
+ const closeParen = openParen === -1 ? -1 : line.indexOf(")", openParen);
173
+ const argumentsSnippet = openParen !== -1
174
+ ? line.slice(openParen + 1, closeParen === -1 ? undefined : closeParen)
175
+ : "";
176
+ calls.push({ callee, argumentsSnippet, location });
177
+ };
178
+ STATIC_CALL_REGEX.lastIndex = 0;
179
+ let match;
180
+ while ((match = STATIC_CALL_REGEX.exec(line)) !== null) {
181
+ push(`${match[1]}::${match[2]}`, match.index);
182
+ }
183
+ METHOD_CALL_REGEX.lastIndex = 0;
184
+ while ((match = METHOD_CALL_REGEX.exec(line)) !== null) {
185
+ push(`->${match[1]}`, match.index);
186
+ }
187
+ NEW_CALL_REGEX.lastIndex = 0;
188
+ while ((match = NEW_CALL_REGEX.exec(line)) !== null) {
189
+ push(`new ${match[1]}`, match.index);
190
+ }
191
+ FUNC_CALL_REGEX.lastIndex = 0;
192
+ while ((match = FUNC_CALL_REGEX.exec(line)) !== null) {
193
+ const name = match[1];
194
+ if (PHP_KEYWORDS.has(name.toLowerCase()))
195
+ continue;
196
+ // Skip names already captured as Class::method or after `new `.
197
+ const before = line.slice(Math.max(0, match.index - 2), match.index);
198
+ if (before.endsWith("::") || before.endsWith(">"))
199
+ continue;
200
+ push(name, match.index);
201
+ }
202
+ }
203
+ return calls;
204
+ }
205
+ function parsePhpSourceFile(file) {
206
+ const warnings = [];
207
+ const normalizedPath = normalizePath(file.path);
208
+ if (file.language !== "php") {
209
+ warnings.push(`Unsupported language '${file.language}' for PHP parser in file '${file.path}'.`);
210
+ return emptyModel(file, normalizedPath, warnings);
211
+ }
212
+ const content = file.content ?? "";
213
+ if (content.includes("\u0000")) {
214
+ warnings.push(`File '${file.path}' appears unreadable (contains null bytes); parser will continue with best-effort analysis.`);
215
+ }
216
+ const strippedContent = (0, strip_comments_1.stripCommentsPreservingLayout)(content, {
217
+ hashComments: true,
218
+ });
219
+ const lines = strippedContent.split(/\r?\n/);
220
+ const imports = [];
221
+ const functions = [];
222
+ const types = [];
223
+ let namespace;
224
+ let currentClass;
225
+ let classEndLine = 0;
226
+ const toLocation = (startLine, endLine) => ({
227
+ filePath: file.path,
228
+ startLine,
229
+ endLine,
230
+ });
231
+ for (let i = 0; i < lines.length; i += 1) {
232
+ const text = (lines[i] ?? "").trim();
233
+ const lineNumber = i + 1;
234
+ if (!text || text === "<?php" || text === "<?=")
235
+ continue;
236
+ if (currentClass && lineNumber > classEndLine) {
237
+ currentClass = undefined;
238
+ }
239
+ if (!namespace) {
240
+ const nsMatch = text.match(NAMESPACE_REGEX);
241
+ if (nsMatch) {
242
+ namespace = nsMatch[1];
243
+ continue;
244
+ }
245
+ }
246
+ const useImports = parseUseImports(text, toLocation(lineNumber, lineNumber));
247
+ if (useImports) {
248
+ imports.push(...useImports);
249
+ continue;
250
+ }
251
+ const requireMatch = text.match(REQUIRE_REGEX);
252
+ if (requireMatch) {
253
+ imports.push({
254
+ path: requireMatch[1],
255
+ isRequire: true,
256
+ location: toLocation(lineNumber, lineNumber),
257
+ });
258
+ continue;
259
+ }
260
+ const typeMatch = text.match(TYPE_REGEX);
261
+ if (typeMatch) {
262
+ const kind = typeMatch[1];
263
+ const name = typeMatch[2];
264
+ const endLine = findBlockEndLine(lines, i);
265
+ types.push({
266
+ name,
267
+ kind,
268
+ location: toLocation(lineNumber, endLine),
269
+ });
270
+ if (kind === "class") {
271
+ currentClass = name;
272
+ classEndLine = endLine;
273
+ }
274
+ continue;
275
+ }
276
+ const functionMatch = text.match(FUNCTION_REGEX);
277
+ if (functionMatch) {
278
+ functions.push({
279
+ name: functionMatch[1],
280
+ className: currentClass,
281
+ location: toLocation(lineNumber, findBlockEndLine(lines, i)),
282
+ });
283
+ }
284
+ }
285
+ const calls = extractCalls(lines, file.path);
286
+ return {
287
+ file,
288
+ normalizedPath,
289
+ strippedContent,
290
+ namespace,
291
+ imports,
292
+ functions,
293
+ types,
294
+ calls,
295
+ warnings,
296
+ };
297
+ }
@@ -0,0 +1,3 @@
1
+ import type { RawFinding } from "../../core/types/detection";
2
+ import type { PhpSourceFileModel } from "./parser";
3
+ export declare function detectPhpPatternsFromModel(model: PhpSourceFileModel): RawFinding[];
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectPhpPatternsFromModel = detectPhpPatternsFromModel;
4
+ const engine_1 = require("../../patterns/engine");
5
+ /**
6
+ * Represent a PHP `use` / require as a language-agnostic import.
7
+ *
8
+ * Namespaces keep their `\` separators so PHP detectors can prefix-match.
9
+ * Path segments and the final class name are also listed in `names` so the
10
+ * shared third-party catalog (lowercase fragments) can still resolve them.
11
+ */
12
+ function importsForEngine(model) {
13
+ return model.imports.map((entry) => {
14
+ const importPath = entry.path;
15
+ const segments = importPath.split(/[\\/]/).filter(Boolean);
16
+ const names = Array.from(new Set([
17
+ importPath,
18
+ ...segments,
19
+ ...(entry.alias ? [entry.alias] : []),
20
+ ])).filter(Boolean);
21
+ return { module: importPath, names };
22
+ });
23
+ }
24
+ function detectPhpPatternsFromModel(model) {
25
+ return (0, engine_1.matchPatterns)({
26
+ language: "php",
27
+ file: model.file,
28
+ normalizedPath: model.normalizedPath,
29
+ strippedContent: model.strippedContent,
30
+ imports: importsForEngine(model),
31
+ functions: model.functions.map((fn) => ({
32
+ name: fn.name,
33
+ decorators: [],
34
+ location: fn.location,
35
+ })),
36
+ types: model.types.map((type) => ({
37
+ name: type.name,
38
+ kind: type.kind,
39
+ baseTypes: [],
40
+ decorators: [],
41
+ location: type.location,
42
+ })),
43
+ moduleLevelCalls: model.calls.map((call) => ({
44
+ callee: call.callee,
45
+ argumentsSnippet: call.argumentsSnippet,
46
+ location: call.location,
47
+ })),
48
+ });
49
+ }