Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit e137de6

Browse files
committed
Merge pull request #99 from MarvinKlemp/fix/ruleset_generation
Fixed performance issue concerning the ComposerLoader
2 parents 2a878df + 291e963 commit e137de6

File tree

5 files changed

+62
-11
lines changed

5 files changed

+62
-11
lines changed

src/DetectorFactory.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,10 @@ public function create(Configuration $configuration, OutputInterface $output)
100100
'Deprecation detection'
101101
);
102102
$deprecationUsageParser = $this->getUsageParser($configuration);
103-
$deprecationUsageFinder = new ParsedPhpFileFinder(
103+
$deprecationUsageFinder = ParsedPhpFileFinder::usageFinder(
104104
$deprecationUsageParser,
105105
$deprecationProgressOutput
106106
);
107-
$deprecationUsageFinder
108-
->exclude('vendor')
109-
->exclude('Tests')
110-
->exclude('Test');
111107

112108
$this->ancestorResolver = new AncestorResolver($deprecationUsageParser);
113109

@@ -117,15 +113,10 @@ public function create(Configuration $configuration, OutputInterface $output)
117113
'RuleSet generation'
118114
);
119115
$ruleSetDeprecationParser = $this->getDeprecationParser();
120-
$ruleSetDeprecationFinder = new ParsedPhpFileFinder(
116+
$ruleSetDeprecationFinder = ParsedPhpFileFinder::deprecationFinder(
121117
$ruleSetDeprecationParser,
122118
$ruleSetProgressOutput
123119
);
124-
$ruleSetDeprecationFinder
125-
->contains('@deprecated')
126-
->exclude('vendor')
127-
->exclude('Tests')
128-
->exclude('Test');
129120
$deprecationDirectoryTraverser = new DirectoryTraverser($ruleSetDeprecationFinder);
130121

131122
$violationDetector = $this->getViolationDetector($configuration);

src/Finder/ParsedPhpFileFinder.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,54 @@ public function getParserErrors()
8585
{
8686
return $this->parserErrors;
8787
}
88+
89+
/**
90+
* @param ParserInterface $parser
91+
* @param VerboseProgressOutput $progressOutput
92+
* @return ParsedPhpFileFinder
93+
*/
94+
public static function deprecationFinder(ParserInterface $parser, VerboseProgressOutput $progressOutput)
95+
{
96+
$finder = new ParsedPhpFileFinder($parser, $progressOutput);
97+
$finder
98+
->contains('@deprecated')
99+
->exclude('vendor')
100+
->exclude('Tests')
101+
->exclude('Test');
102+
103+
return $finder;
104+
105+
}
106+
107+
/**
108+
* @param ParserInterface $parser
109+
* @param VerboseProgressOutput $progressOutput
110+
* @return ParsedPhpFileFinder
111+
*/
112+
public static function usageFinder(ParserInterface $parser, VerboseProgressOutput $progressOutput)
113+
{
114+
$finder = new ParsedPhpFileFinder($parser, $progressOutput);
115+
$finder
116+
->exclude('vendor')
117+
->exclude('Tests')
118+
->exclude('Test');
119+
120+
return $finder;
121+
}
122+
123+
/**
124+
* @return ParserInterface
125+
*/
126+
public function getParser()
127+
{
128+
return $this->parser;
129+
}
130+
131+
/**
132+
* @return VerboseProgressOutput
133+
*/
134+
public function getOutput()
135+
{
136+
return $this->progressOutput;
137+
}
88138
}

src/RuleSet/DirectoryTraverser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ public function traverse($path, RuleSet $ruleSet = null)
4848

4949
return $ruleSet;
5050
}
51+
52+
public function reset()
53+
{
54+
$this->finder = ParsedPhpFileFinder::deprecationFinder(
55+
$this->finder->getParser(),
56+
$this->finder->getOutput()
57+
);
58+
}
5159
}

src/RuleSet/Loader/Composer/ComposerLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ private function loadPackageRuleSet(Package $package)
7373
if ($this->cache->has($key)) {
7474
$ruleSet = $this->cache->getCachedRuleSet($key);
7575
} elseif (is_dir($path = $package->getPackagePath(self::PACKAGE_PATH))) {
76+
$this->traverser->reset();
7677
$ruleSet = $this->traverser->traverse($path);
7778
$this->cache->cacheRuleSet($key, $ruleSet);
7879
} else {

tests/RuleSet/Loader/Composer/ComposerLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function testLoadRuleSet()
8585

8686
$traverser = $this->prophesize('SensioLabs\DeprecationDetector\RuleSet\DirectoryTraverser');
8787
$traverser->traverse(vfsStream::url('root/vendor/avendor/anotherlib'))->willReturn($aVendorAnotherLibRuleSet);
88+
$traverser->reset()->shouldBeCalled();
8889
$cache->cacheRuleSet('vendor_anotherlib_1.0.0', $aVendorAnotherLibRuleSet)->shouldBeCalled();
8990

9091
$factory = $this->prophesize('SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\ComposerFactory');

0 commit comments

Comments
 (0)