Skip to content

Commit 092b044

Browse files
committed
add detection for duplicated masks
1 parent 7ab6354 commit 092b044

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Command/DuplicatedDefinitionsCommand.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5353
$contextFileInfos
5454
);
5555

56+
// 1. find duplicated masks, e.g. if 2 methods have the same mask, its a race condition problem
57+
$classMethodContextDefinitions = $this->classMethodContextDefinitionsAnalyzer->resolve($contextFileInfos);
58+
$groupedByMask = [];
59+
foreach ($classMethodContextDefinitions as $classMethodContextDefinition) {
60+
$groupedByMask[$classMethodContextDefinition->getMask()][] = $classMethodContextDefinition;
61+
}
62+
63+
foreach ($groupedByMask as $mask => $sameMaksClassMethodContextDefinitions) {
64+
if (count($sameMaksClassMethodContextDefinitions) === 1) {
65+
continue;
66+
}
67+
68+
// two or more methods have the same mask
69+
$this->symfonyStyle->section('Duplicated mask: "' . $mask . '"');
70+
foreach ($sameMaksClassMethodContextDefinitions as $classMethodContextDefinition) {
71+
$relativeFilePath = substr(
72+
$classMethodContextDefinition->getFilePath(),
73+
strlen((string) $testDirectories[0]) + 1
74+
);
75+
$this->symfonyStyle->writeln($relativeFilePath . ':' . $classMethodContextDefinition->getMethodLine());
76+
}
77+
78+
$this->symfonyStyle->newLine();
79+
}
80+
81+
// 2. find duplicate method contents
82+
5683
// keep only duplicated
5784
$classMethodContextDefinitionByClassMethodHash = $this->filterOutNotDuplicated(
5885
$classMethodContextDefinitionByClassMethodHash

0 commit comments

Comments
 (0)