-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDuplicatedScenarioTitleRule.php
More file actions
52 lines (42 loc) · 1.51 KB
/
DuplicatedScenarioTitleRule.php
File metadata and controls
52 lines (42 loc) · 1.51 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
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
namespace Rector\Behastan\Rule;
use Rector\Behastan\Analyzer\DuplicatedScenarioTitlesAnalyzer;
use Rector\Behastan\Contract\RuleInterface;
use Rector\Behastan\Enum\RuleIdentifier;
use Rector\Behastan\ValueObject\PatternCollection;
use Rector\Behastan\ValueObject\RuleError;
use Symfony\Component\Finder\SplFileInfo;
final readonly class DuplicatedScenarioTitleRule implements RuleInterface
{
public function __construct(
private DuplicatedScenarioTitlesAnalyzer $duplicatedScenarioNamesAnalyzer
) {
}
/**
* @param SplFileInfo[] $contextFiles
* @param SplFileInfo[] $featureFiles
*
* @return RuleError[]
*/
public function process(
array $contextFiles,
array $featureFiles,
PatternCollection $patternCollection,
string $projectDirectory
): array {
$scenarioNamesToFiles = $this->duplicatedScenarioNamesAnalyzer->analyze($featureFiles);
$ruleErrors = [];
foreach ($scenarioNamesToFiles as $scenarioName => $files) {
// it can be used multiple times in single file
$uniqueFiles = array_unique($files);
$errorMessage = sprintf('Scenario name "%s" is duplicated %d-times', $scenarioName, count($files));
$ruleErrors[] = new RuleError($errorMessage, $uniqueFiles, $this->getIdentifier());
}
return $ruleErrors;
}
public function getIdentifier(): string
{
return RuleIdentifier::DUPLICATED_SCENARIO_TITLES;
}
}