Skip to content

Commit 497ee8b

Browse files
committed
refactor: merge duplicate switch case and avoid mutating replacePath parameter
- Consolidate namespace_use_declaration and use_declaration into single fallthrough case - ProcessBuilder.replacePath now returns a new object instead of mutating the input
1 parent c6cbd6d commit 497ee8b

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

packages/phpunit/src/Interpreter/AstParser/TreeSitter/TreeSitterAdapter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,6 @@ function adaptTopLevelNode(node: SyntaxNode): AstNode | null {
955955
case 'method_declaration':
956956
return adaptMethod(node);
957957
case 'namespace_use_declaration':
958-
return adaptNamespaceUse(node);
959958
case 'use_declaration':
960959
return adaptNamespaceUse(node);
961960
case 'expression_statement':

packages/phpunit/src/ProcessBuilder/ProcessBuilder.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,25 @@ export class ProcessBuilder {
8888
return { runtime, args, options: { ...this.options, env: this.getEnvironment() } };
8989
}
9090

91-
replacePath(result: TestResult) {
91+
replacePath(result: TestResult): TestResult {
92+
const replaced: Record<string, unknown> = {};
93+
9294
if ('locationHint' in result && result.locationHint) {
93-
result.locationHint = this.pathReplacer.toLocal(result.locationHint);
95+
replaced.locationHint = this.pathReplacer.toLocal(result.locationHint);
9496
}
9597

9698
if ('file' in result && result.file) {
97-
result.file = this.pathReplacer.toLocal(result.file);
99+
replaced.file = this.pathReplacer.toLocal(result.file);
98100
}
99101

100102
if ('details' in result) {
101-
result.details = result.details.map(({ file, line }) => ({
103+
replaced.details = result.details.map(({ file, line }) => ({
102104
file: this.pathReplacer.toLocal(file),
103105
line,
104106
}));
105107
}
106108

107-
return result;
109+
return Object.keys(replaced).length > 0 ? { ...result, ...replaced } : result;
108110
}
109111

110112
toString() {

0 commit comments

Comments
 (0)