-
-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor AnnotationExtractor fomr FileDiff value object to standalone…
… RectorsChangelogResolver service
- Loading branch information
1 parent
00a3e43
commit ab6b960
Showing
12 changed files
with
176 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ngesReporting/Annotation/AppliedRectorsChangelogResolver/RectorsChangelogResolverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\ChangesReporting\Annotation\AppliedRectorsChangelogResolver; | ||
|
||
use Rector\ChangesReporting\Annotation\RectorsChangelogResolver; | ||
use Rector\ChangesReporting\ValueObject\RectorWithFileAndLineChange; | ||
use Rector\Core\HttpKernel\RectorKernel; | ||
use Rector\Core\ValueObject\Reporting\FileDiff; | ||
use Rector\Tests\ChangesReporting\Annotation\AppliedRectorsChangelogResolver\Source\RectorWithChangelog; | ||
use Rector\Tests\ChangesReporting\Annotation\AppliedRectorsChangelogResolver\Source\RectorWithOutChangelog; | ||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class RectorsChangelogResolverTest extends AbstractKernelTestCase | ||
{ | ||
/** | ||
* @var RectorsChangelogResolver | ||
*/ | ||
private $rectorsChangelogResolver; | ||
|
||
/** | ||
* @var FileDiff | ||
*/ | ||
private $fileDiff; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->bootKernel(RectorKernel::class); | ||
$this->rectorsChangelogResolver = $this->getService(RectorsChangelogResolver::class); | ||
|
||
$this->fileDiff = $this->createFileDiff(); | ||
} | ||
|
||
public function test(): void | ||
{ | ||
$rectorsChangelogs = $this->rectorsChangelogResolver->resolve($this->fileDiff->getRectorClasses()); | ||
|
||
$epectedRectorsChangelogs = [ | ||
RectorWithChangelog::class => 'https://github.com/rectorphp/rector/blob/master/docs/rector_rules_overview.md', | ||
]; | ||
$this->assertSame($epectedRectorsChangelogs, $rectorsChangelogs); | ||
} | ||
|
||
private function createFileDiff(): FileDiff | ||
{ | ||
// This is by intention to test the array_unique functionality | ||
$rectorWithFileAndLineChange1 = new RectorWithFileAndLineChange( | ||
new RectorWithChangelog(), | ||
__DIR__ . '/Source/RectorWithChangelog.php', | ||
1 | ||
); | ||
|
||
$rectorWithFileAndLineChange2 = new RectorWithFileAndLineChange( | ||
new RectorWithChangelog(), | ||
__DIR__ . '/Source/RectorWithChangelog.php', | ||
1 | ||
); | ||
|
||
$rectorWithFileAndLineChange3 = new RectorWithFileAndLineChange( | ||
new RectorWithOutChangelog(), | ||
__DIR__ . '/Source/RectorWithOutChangelog.php', | ||
1 | ||
); | ||
|
||
$rectorWithFileAndLineChanges = [ | ||
$rectorWithFileAndLineChange1, | ||
$rectorWithFileAndLineChange2, | ||
$rectorWithFileAndLineChange3, | ||
]; | ||
|
||
return new FileDiff(new SmartFileInfo(__FILE__), 'foo', 'foo', $rectorWithFileAndLineChanges); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...alueObject/Source/RectorWithChangelog.php → ...ogResolver/Source/RectorWithChangelog.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...eObject/Source/RectorWithOutChangelog.php → ...esolver/Source/RectorWithOutChangelog.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
packages-tests/ChangesReporting/ValueObject/FileDiffTest.php
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
packages-tests/ChangesReporting/ValueObject/RectorWithFileAndLineChangeTest.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/ChangesReporting/Annotation/RectorsChangelogResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\ChangesReporting\Annotation; | ||
|
||
use Rector\Core\Contract\Rector\RectorInterface; | ||
|
||
final class RectorsChangelogResolver | ||
{ | ||
/** | ||
* @var AnnotationExtractor | ||
*/ | ||
private $annotationExtractor; | ||
|
||
public function __construct(AnnotationExtractor $annotationExtractor) | ||
{ | ||
$this->annotationExtractor = $annotationExtractor; | ||
} | ||
|
||
/** | ||
* @param array<class-string<RectorInterface>> $rectorClasses | ||
* @return array<class-string, string> | ||
*/ | ||
public function resolve(array $rectorClasses): array | ||
{ | ||
$rectorClassesToChangelogUrls = $this->resolveIncludingMissing($rectorClasses); | ||
return array_filter($rectorClassesToChangelogUrls); | ||
} | ||
|
||
/** | ||
* @param array<class-string<RectorInterface>> $rectorClasses | ||
* @return array<class-string, string|null> | ||
*/ | ||
public function resolveIncludingMissing(array $rectorClasses): array | ||
{ | ||
$rectorClassesToChangelogUrls = []; | ||
foreach ($rectorClasses as $rectorClass) { | ||
$changelogUrl = $this->annotationExtractor->extractAnnotationFromClass($rectorClass, '@changelog'); | ||
$rectorClassesToChangelogUrls[$rectorClass] = $changelogUrl; | ||
} | ||
|
||
return $rectorClassesToChangelogUrls; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.