-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDuplicatedScenarioNamesAnalyzer.php
More file actions
39 lines (31 loc) · 1.16 KB
/
DuplicatedScenarioNamesAnalyzer.php
File metadata and controls
39 lines (31 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types=1);
namespace Rector\Behastan\Analyzer;
use Entropy\Attributes\RelatedTest;
use Entropy\Utils\Regex;
use Rector\Behastan\Tests\Analyzer\DuplicatedScenarioNamesAnalyzer\DuplicatedScenarioNamesAnalyzerTest;
use Symfony\Component\Finder\SplFileInfo;
#[RelatedTest(DuplicatedScenarioNamesAnalyzerTest::class)]
final class DuplicatedScenarioNamesAnalyzer
{
private const string SCENARIO_NAME_REGEX = '#\s+Scenario:\s+(?<name>.*?)\n#';
/**
* @param SplFileInfo[] $featureFiles
* @return array<string, string[]>
*/
public function analyze(array $featureFiles): array
{
$scenarioNamesToFiles = [];
foreach ($featureFiles as $featureFile) {
// match Scenario: "<name>"
$matches = Regex::matchAll($featureFile->getContents(), self::SCENARIO_NAME_REGEX);
foreach ($matches as $match) {
$scenarioName = $match['name'];
$scenarioNamesToFiles[$scenarioName][] = $featureFile->getRealPath();
}
}
return array_filter($scenarioNamesToFiles, function (array $files): bool {
return count($files) > 1;
});
}
}