Skip to content

Commit 9ab27fb

Browse files
authored
add getRawPsrViolations (#16)
1 parent c1c70e6 commit 9ab27fb

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/ClassMap.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,16 @@ public function count(): int
176176
{
177177
return \count($this->map);
178178
}
179+
180+
/**
181+
* Get the raw psr violations
182+
*
183+
* This is a map of filepath to an associative array of the warning string
184+
* and the offending class name.
185+
* @return array<string, array<array{warning: string, className: string}>>
186+
*/
187+
public function getRawPsrViolations(): array
188+
{
189+
return $this->psrViolations;
190+
}
179191
}

tests/ClassMapGeneratorTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,32 @@ public function testGetPSR4Violations(): void
277277
);
278278
}
279279

280+
public function testGetRawPSR4Violations(): void
281+
{
282+
$this->generator->scanPaths(__DIR__ . '/Fixtures/psrViolations', null, 'psr-4', 'ExpectedNamespace\\');
283+
$classMap = $this->generator->getClassMap();
284+
$rawViolations = $classMap->getRawPsrViolations();
285+
286+
$classWithoutNameSpaceFilepath = __DIR__ . '/Fixtures/psrViolations/ClassWithoutNameSpace.php';
287+
$classWithIncorrectSubNamespaceFilepath = __DIR__ . '/Fixtures/psrViolations/ClassWithIncorrectSubNamespace.php';
288+
$classWithNameSpaceOutsideConfiguredScopeFilepath = __DIR__ . '/Fixtures/psrViolations/ClassWithNameSpaceOutsideConfiguredScope.php';
289+
290+
self::assertArrayHasKey($classWithoutNameSpaceFilepath, $rawViolations);
291+
self::assertCount(1, $rawViolations[$classWithoutNameSpaceFilepath]);
292+
self::assertSame('Class ClassWithoutNameSpace located in ./tests/Fixtures/psrViolations/ClassWithoutNameSpace.php does not comply with psr-4 autoloading standard (rule: ExpectedNamespace\ => ./tests/Fixtures/psrViolations). Skipping.', $rawViolations[$classWithoutNameSpaceFilepath][0]['warning']);
293+
self::assertSame('ClassWithoutNameSpace', $rawViolations[$classWithoutNameSpaceFilepath][0]['className']);
294+
295+
self::assertArrayHasKey($classWithIncorrectSubNamespaceFilepath, $rawViolations);
296+
self::assertCount(1, $rawViolations[$classWithIncorrectSubNamespaceFilepath]);
297+
self::assertSame('Class ExpectedNamespace\UnexpectedSubNamespace\ClassWithIncorrectSubNamespace located in ./tests/Fixtures/psrViolations/ClassWithIncorrectSubNamespace.php does not comply with psr-4 autoloading standard (rule: ExpectedNamespace\ => ./tests/Fixtures/psrViolations). Skipping.', $rawViolations[$classWithIncorrectSubNamespaceFilepath][0]['warning']);
298+
self::assertSame('ExpectedNamespace\UnexpectedSubNamespace\ClassWithIncorrectSubNamespace', $rawViolations[$classWithIncorrectSubNamespaceFilepath][0]['className']);
299+
300+
self::assertArrayHasKey($classWithNameSpaceOutsideConfiguredScopeFilepath, $rawViolations);
301+
self::assertCount(1, $rawViolations[$classWithNameSpaceOutsideConfiguredScopeFilepath]);
302+
self::assertSame('Class UnexpectedNamespace\ClassWithNameSpaceOutsideConfiguredScope located in ./tests/Fixtures/psrViolations/ClassWithNameSpaceOutsideConfiguredScope.php does not comply with psr-4 autoloading standard (rule: ExpectedNamespace\ => ./tests/Fixtures/psrViolations). Skipping.', $rawViolations[$classWithNameSpaceOutsideConfiguredScopeFilepath][0]['warning']);
303+
self::assertSame('UnexpectedNamespace\ClassWithNameSpaceOutsideConfiguredScope', $rawViolations[$classWithNameSpaceOutsideConfiguredScopeFilepath][0]['className']);
304+
}
305+
280306
public function testCreateMapWithDirectoryExcluded(): void
281307
{
282308
$expected = array(

0 commit comments

Comments
 (0)