Skip to content

Commit 587dbc1

Browse files
committed
Create source locator from correct folder; better variable names
1 parent 25136af commit 587dbc1

File tree

11 files changed

+37
-31
lines changed

11 files changed

+37
-31
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"phpdocumentor/reflection-docblock": "^5.2",
99
"symfony/filesystem": "^5.2",
1010
"symfony/process": "^5.2",
11+
"nikic/php-parser": "4.6.*",
1112
"ext-simplexml": "*",
1213
"ext-dom": "*",
1314
"ext-libxml": "*"
@@ -19,6 +20,6 @@
1920
}
2021
},
2122
"require-dev": {
22-
"phpunit/phpunit": "^9.5"
23+
"phpunit/phpunit": "^9.0"
2324
}
2425
}

src/Configuration/generator.xsd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<xs:element name="generator">
44
<xs:complexType>
55
<xs:sequence>
6-
<xs:element name="source">
6+
<xs:element name="source" maxOccurs="unbounded">
77
<xs:complexType>
88
<xs:sequence>
9-
<xs:element name="standard">
9+
<xs:element name="standard" maxOccurs="unbounded">
1010
<xs:complexType>
1111
<xs:attribute name="path" type="xs:string" use="required"/>
1212
</xs:complexType>

src/Handler/GenerateHandler.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace App\Handler;
55

6-
use App\CodeRepository\CodeRepository;
76
use App\CodeRepository\CodeRepositoryFactory;
87
use App\Configuration\ConfigurationRepository;
98
use App\Generator\Generator;
@@ -41,15 +40,15 @@ public function handle(string $sniffPath = null): iterable
4140

4241
foreach ($config->getSources() as $source) {
4342
$codeRepository = $this->codeRepositoryFactory->fromType($source->getType());
44-
$repoPath = $codeRepository->getFolder($source);
43+
$sourceFolder = $codeRepository->getFolder($source);
4544
foreach ($source->getStandards() as $standard) {
46-
$standardFolder = new Folder($repoPath . $standard->getPath() . '/');
45+
$standardFolder = new Folder($sourceFolder . $standard->getPath() . '/');
4746
yield "Searching for sniffs in {$standardFolder}...";
4847

4948
if ($sniffPath !== null) {
50-
$sniffs = [$this->sniffFinder->getSniff($standardFolder, $sniffPath)];
49+
$sniffs = [$this->sniffFinder->getSniff($standardFolder, $sourceFolder, $sniffPath)];
5150
} else {
52-
$sniffs = $this->sniffFinder->getSniffs($standardFolder);
51+
$sniffs = $this->sniffFinder->getSniffs($standardFolder, $sourceFolder);
5352
}
5453

5554
foreach ($sniffs as $sniff) {

src/SniffFinder/FilesystemSniffFinder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
class FilesystemSniffFinder implements SniffFinder
2020
{
21-
public function getSniff(Folder $folder, string $sniffPath): Sniff
21+
public function getSniff(Folder $standardFolder, Folder $sourceFolder, string $sniffPath): Sniff
2222
{
2323
$parser = new SniffParser();
24-
$projectSourceLocator = $this->createProjectSourceLocator($folder);
24+
$projectSourceLocator = $this->createProjectSourceLocator($sourceFolder);
2525
return $parser->parse($sniffPath, $projectSourceLocator);
2626
}
2727

@@ -44,11 +44,11 @@ private function recursiveSearch(Folder $folder): Iterator
4444
});
4545
}
4646

47-
public function getSniffs(Folder $folder): iterable
47+
public function getSniffs(Folder $standardFolder, Folder $sourceFolder): iterable
4848
{
4949
$parser = new SniffParser();
50-
$globSniffs = new GlobIterator($folder->getPath() . 'Sniffs/*/*Sniff.php');
51-
$projectSourceLocator = $this->createProjectSourceLocator($folder);
50+
$globSniffs = new GlobIterator($standardFolder->getPath() . 'Sniffs/*/*Sniff.php');
51+
$projectSourceLocator = $this->createProjectSourceLocator($sourceFolder);
5252
foreach ($globSniffs as $fileInfo) {
5353
yield $parser->parse($fileInfo->getPathname(), $projectSourceLocator);
5454
}

src/SniffFinder/SniffFinder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
interface SniffFinder
1010
{
11-
public function getSniff(Folder $folder, string $sniffPath): Sniff;
11+
public function getSniff(Folder $standardFolder, Folder $sourceFolder, string $sniffPath): Sniff;
1212

1313
/**
1414
* @return iterable<Sniff>
1515
*/
16-
public function getSniffs(Folder $folder): iterable;
16+
public function getSniffs(Folder $standardFolder, Folder $sourceFolder): iterable;
1717
}

src/Value/Folder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(string $path)
1717
$this->path = $path;
1818
}
1919

20-
public function __toString()
20+
public function __toString(): string
2121
{
2222
return $this->getPath();
2323
}

src/Value/Url.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(string $url)
1717
$this->url = $url;
1818
}
1919

20-
public function __toString()
20+
public function __toString(): string
2121
{
2222
return $this->getUrl();
2323
}

tests/CodeRepository/GitCodeRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/** @covers \App\CodeRepository\GitCodeRepository */
1313
class GitCodeRepositoryTest extends TestCase
1414
{
15-
const LOCAL_GIT_PATH = 'var/tests/repo/Standard.git';
15+
private const LOCAL_GIT_PATH = 'var/tests/repo/Standard.git';
1616
private GitCodeRepository $codeRepo;
1717

1818
/** @test */

tests/Configuration/Value/ConfigurationTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,19 @@ class ConfigurationTest extends TestCase
1616
*/
1717
private static array $SOURCES;
1818

19-
/** @test */
20-
public function getSources()
19+
public static function setUpBeforeClass(): void
2120
{
22-
self::assertEquals(
23-
self::$SOURCES,
24-
$this->createValidVO()->getSources(),
25-
);
21+
self::$SOURCES = [
22+
new Source('path/to/source', [])
23+
];
2624
}
2725

2826
/** @test */
29-
public function getFormat()
27+
public function getSources()
3028
{
3129
self::assertEquals(
32-
self::FORMAT,
33-
$this->createValidVO()->getFormat(),
30+
self::$SOURCES,
31+
$this->createValidVO()->getSources(),
3432
);
3533
}
3634

@@ -42,10 +40,12 @@ private function createValidVO(): Configuration
4240
);
4341
}
4442

45-
public static function setUpBeforeClass(): void
43+
/** @test */
44+
public function getFormat()
4645
{
47-
self::$SOURCES = [
48-
new Source('path/to/source', [])
49-
];
46+
self::assertEquals(
47+
self::FORMAT,
48+
$this->createValidVO()->getFormat(),
49+
);
5050
}
5151
}

tests/SniffFinder/FilesystemSniffFinderTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function getSniffs()
3232
$sniffs = $this->finder->getSniffs(
3333
new Folder(
3434
'var/tests/src/Standard/'
35+
),
36+
new Folder(
37+
'var/tests/'
3538
)
3639
);
3740
self::assertEquals(
@@ -114,6 +117,9 @@ public function getSniff()
114117
new Folder(
115118
'var/tests/src/Standard/'
116119
),
120+
new Folder(
121+
'var/tests/'
122+
),
117123
self::PHP_SNIFF_PATH
118124
)
119125
);

var/repos/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)