Skip to content

Commit ba0987d

Browse files
authored
DAM issue resolved (#688)
1 parent 0cc64bc commit ba0987d

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

config/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v4.16.1
1+
v4.16.2

src/Domain/Fixture/FixtureCustomizer.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,28 +137,35 @@ protected function removeModuleDevDependencyTests(
137137
string $search_string,
138138
): void {
139139
$finder = $this->finderFactory->create();
140-
// Converting drupal/acquia_dam to acquia_dam.
141140
$module_name = explode("/", $module_name)[1];
142141

143142
try {
144143
$path = $this->fixturePathHandler->getPath('docroot/modules/contrib/' . $module_name);
145144

146145
$files = $finder->in($path)->filter(function (\SplFileInfo $file) use ($search_string) {
147146
$content = $file->getContents();
148-
149-
// This Regex looks for the search string ($search_string)
150-
// BUT ensures it is NOT preceded by comment markers on the same line.
151-
// It skips lines starting with *, //, or inside a docblock.
152147
$quotedSearch = preg_quote($search_string, '/');
153148

154-
// Logic: Match the string only if the line doesn't start with common comment patterns
155-
$pattern = '/^(?!\s*(\*|\/\/|\/\*)).*' . $quotedSearch . '/m';
149+
// CONDITION 1: Match the search string ONLY when it follows 'extends' or 'implements'
150+
// This prevents deletion for 'use' statements (imports) or optional traits.
151+
$dependencyPattern = '/(extends|implements)\s+.*?(' . $quotedSearch . ')/s';
152+
153+
// Check if it's a hard dependency
154+
$isHardDependency = (bool) preg_match($dependencyPattern, $content);
155+
156+
if (!$isHardDependency) {
157+
return false;
158+
}
156159

157-
return (bool) preg_match($pattern, $content);
160+
// CONDITION 2: Ensure the specific line containing that dependency is NOT a comment.
161+
// We look for the line that actually contains the search string.
162+
$commentPattern = '/^(?!\s*(\*|\/\/|\/\*)).*' . $quotedSearch . '/m';
163+
164+
return (bool) preg_match($commentPattern, $content);
158165
});
159166

160167
if (iterator_count($files) === 0) {
161-
$this->output->writeln("\nNo customizations required (matches were only found in comments).\n");
168+
$this->output->writeln("\nNo customizations required (matches were only found in non-critical code or comments).\n");
162169
return;
163170
}
164171

@@ -167,7 +174,6 @@ protected function removeModuleDevDependencyTests(
167174
}
168175

169176
$this->filesystem->remove($files);
170-
171177
$this->output->writeln("\nFiles removed successfully.\n\n");
172178
}
173179
catch (\Exception $e) {

0 commit comments

Comments
 (0)