MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extractDrupalServices

Function extractDrupalServices

src/resolution/frameworks/drupal.ts:342–437  ·  view source on GitHub ↗

* Service definitions from a `*.services.yml` file. Line by line, as the routes are: * ids sit at one indent under the top-level `services:`, and what a service is given * sits below its id, in any of the places Symfony takes one (`arguments`, `calls`, * `factory`, `parent`, `decorates`, an alias

(
  filePath: string,
  content: string
)

Source from the content-addressed store, hash-verified

340 * `factory`, `parent`, `decorates`, an alias).
341 */
342function extractDrupalServices(
343 filePath: string,
344 content: string
345): { nodes: Node[]; references: UnresolvedRef[] } {
346 const nodes: Node[] = [];
347 const references: UnresolvedRef[] = [];
348 const now = Date.now();
349 let inServices = false;
350 let idIndent = -1;
351 let current: Node | null = null;
352 let given = new Set<string>();
353
354 const reference = (from: Node, referenceName: string): void => {
355 references.push({
356 fromNodeId: from.id,
357 referenceName,
358 referenceKind: 'references',
359 line: from.startLine,
360 column: 0,
361 filePath,
362 language: 'yaml',
363 });
364 };
365 const give = (id: string): void => {
366 if (!current || given.has(id) || `service:${id}` === current.name) return;
367 given.add(id);
368 reference(current, `${SERVICE_REF}${id}`);
369 };
370 const giveAll = (text: string): void => {
371 SERVICE_ARGUMENT.lastIndex = 0;
372 let m: RegExpExecArray | null;
373 while ((m = SERVICE_ARGUMENT.exec(text)) !== null) give(m[1]!);
374 };
375 const setClass = (fqcn: string): void => {
376 if (!current || current.signature) return;
377 current.signature = fqcn;
378 reference(current, fqcnRef(fqcn));
379 };
380
381 const lines = content.split('\n');
382 for (let i = 0; i < lines.length; i++) {
383 const text = withoutYamlComment(lines[i]!).trimEnd();
384 const trimmed = text.trim();
385 if (!trimmed) continue;
386 const indent = text.length - text.trimStart().length;
387 if (indent === 0) {
388 inServices = /^services\s*:/.test(trimmed);
389 idIndent = -1;
390 current = null;
391 continue;
392 }
393 if (!inServices) continue;
394 if (idIndent < 0) idIndent = indent;
395
396 if (indent === idIndent) {
397 current = null;
398 const id = SERVICE_ID.exec(trimmed);
399 if (!id) continue;

Callers 1

extractFunction · 0.85

Calls 6

withoutYamlCommentFunction · 0.85
setClassFunction · 0.85
giveAllFunction · 0.85
giveFunction · 0.85
pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected