Skip to content

Commit 641a112

Browse files
committed
Allow sorting, add some more docs
1 parent 50b130b commit 641a112

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ $generator->scanPaths('path/to/scan');
4949
$generator->scanPaths('path/to/scan2');
5050
5151
$classMap = $generator->getClassMap();
52+
$classMap->sort(); // optionally sort classes alphabetically
5253
foreach ($classMap->getMap() as $symbol => $path) {
5354
// do your thing
5455
}

src/ClassMap.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class ClassMap
3333
private $psrViolations = [];
3434

3535
/**
36+
* Returns the class map, which is a list of paths indexed by class name
37+
*
3638
* @return array<class-string, non-empty-string>
3739
*/
3840
public function getMap(): array
@@ -41,6 +43,14 @@ public function getMap(): array
4143
}
4244

4345
/**
46+
* Returns warning strings containing details about PSR-0/4 violations that were detected
47+
*
48+
* Violations are for ex a class which is in the wrong file/directory and thus should not be
49+
* found using psr-0/psr-4 autoloading but was found by the ClassMapGenerator as it scans all files.
50+
*
51+
* This is only happening when scanning paths using psr-0/psr-4 autoload type. Classmap type
52+
* always accepts every class as it finds it.
53+
*
4454
* @return string[]
4555
*/
4656
public function getPsrViolations(): array
@@ -51,6 +61,8 @@ public function getPsrViolations(): array
5161
/**
5262
* A map of class names to their list of ambiguous paths
5363
*
64+
* This occurs when the same class can be found in several files
65+
*
5466
* To get the path the class is being mapped to, call getClassPath
5567
*
5668
* @return array<class-string, array<non-empty-string>>
@@ -60,6 +72,14 @@ public function getAmbiguousClasses(): array
6072
return $this->ambiguousClasses;
6173
}
6274

75+
/**
76+
* Sorts the class map alphabetically by class names
77+
*/
78+
public function sort(): void
79+
{
80+
ksort($this->map);
81+
}
82+
6383
/**
6484
* @param class-string $className
6585
* @param non-empty-string $path

0 commit comments

Comments
 (0)