@@ -39,34 +39,28 @@ public static function name(): string
3939 /**
4040 * Get the commit reference of the root package, if known
4141 */
42- public static function reference (bool $ short = true ): ?string
42+ public static function ref (bool $ short = true ): ?string
4343 {
4444 /** @var string|null */
4545 $ ref = self ::getRootPackageValue ('reference ' );
46- return self ::formatReference ($ ref , $ short );
46+ return self ::formatRef ($ ref , $ short );
4747 }
4848
4949 /**
5050 * Get the version of the root package
5151 *
5252 * If Composer returns a version like `dev-*` or `v1.x-dev`, `@<reference>`
53- * is added. Otherwise, if `$withReference ` is `true` and a commit reference
54- * is available, `-<reference>` is added.
53+ * is added. Otherwise, if `$withRef ` is `true` and a commit reference is
54+ * available, `-<reference>` is added.
5555 *
5656 * @param bool $pretty If `true`, return the original version number, e.g.
5757 * `v1.2.3` instead of `1.2.3.0`.
5858 */
59- public static function version (
60- bool $ pretty = true ,
61- bool $ withReference = false
62- ): string {
59+ public static function version (bool $ pretty = true , bool $ withRef = false ): string
60+ {
6361 /** @var string */
6462 $ version = self ::getRootPackageValue ($ pretty ? 'pretty_version ' : 'version ' );
65- return self ::formatVersion (
66- $ version ,
67- $ withReference ,
68- fn () => self ::reference ()
69- );
63+ return self ::formatVersion ($ version , $ withRef , fn () => self ::ref ());
7064 }
7165
7266 /**
@@ -82,56 +76,53 @@ public static function path(): string
8276 /**
8377 * Get the commit reference of an installed package, if known
8478 */
85- public static function packageReference (
86- string $ package ,
87- bool $ short = true
88- ): ?string {
79+ public static function getPackageRef (string $ package , bool $ short = true ): ?string
80+ {
8981 if (!self ::isInstalled ($ package )) {
9082 return null ;
9183 }
9284
93- return self ::formatReference (
94- self ::filterData (
95- Installed::getReference ($ package ),
96- Installed::class,
97- 'getReference ' ,
98- $ package ,
99- ),
100- $ short ,
85+ $ ref = self ::filterData (
86+ Installed::getReference ($ package ),
87+ Installed::class,
88+ 'getReference ' ,
89+ $ package ,
10190 );
91+
92+ return self ::formatRef ($ ref , $ short );
10293 }
10394
10495 /**
10596 * Get the version of an installed package, or null if it is not installed
10697 *
10798 * If Composer returns a version like `dev-*` or `v1.x-dev`, `@<reference>`
108- * is added. Otherwise, if `$withReference ` is `true` and a commit reference
99+ * is added. Otherwise, if `$withRef ` is `true` and a commit reference
109100 * is available, `-<reference>` is added.
110101 *
111102 * @param bool $pretty If `true`, return the original version number, e.g.
112103 * `v1.2.3` instead of `1.2.3.0`.
113104 */
114- public static function packageVersion (
105+ public static function getPackageVersion (
115106 string $ package ,
116107 bool $ pretty = true ,
117- bool $ withReference = false
108+ bool $ withRef = false
118109 ): ?string {
119110 if (!self ::isInstalled ($ package )) {
120111 return null ;
121112 }
122113
123114 return self ::formatVersion (
124115 (string ) self ::getVersion ($ package , $ pretty ),
125- $ withReference ,
126- fn () => self ::packageReference ($ package )
116+ $ withRef ,
117+ fn () => self ::getPackageRef ($ package ),
127118 );
128119 }
129120
130121 /**
131122 * Get the canonical path of an installed package, or null if it is not
132123 * installed
133124 */
134- public static function packagePath (string $ package ): ?string
125+ public static function getPackagePath (string $ package ): ?string
135126 {
136127 if (!self ::isInstalled ($ package )) {
137128 return null ;
@@ -153,7 +144,7 @@ public static function packagePath(string $package): ?string
153144 *
154145 * @see Package::namespacePath()
155146 */
156- public static function classPath (string $ class ): ?string
147+ public static function getClassPath (string $ class ): ?string
157148 {
158149 $ class = ltrim ($ class , '\\' );
159150 foreach (self ::getRegisteredLoaders () as $ loader ) {
@@ -181,27 +172,24 @@ public static function classPath(string $class): ?string
181172 * namespace already exists. If no such prefix exists, preference is given
182173 * to the longest prefix.
183174 */
184- public static function namespacePath (string $ namespace ): ?string
175+ public static function getNamespacePath (string $ namespace ): ?string
185176 {
186177 $ namespace = trim ($ namespace , '\\' );
187178
188179 $ prefixes = [];
189180 foreach (self ::getRegisteredLoaders () as $ loader ) {
190- $ prefixes = array_merge_recursive (
191- self ::filterData (
192- $ loader ->getPrefixesPsr4 (),
193- Loader::class,
194- 'getPrefixesPsr4 ' ,
195- ),
196- $ prefixes
181+ $ loaderPrefixes = self ::filterData (
182+ $ loader ->getPrefixesPsr4 (),
183+ Loader::class,
184+ 'getPrefixesPsr4 ' ,
197185 );
186+ $ prefixes = array_merge_recursive ($ loaderPrefixes , $ prefixes );
198187 }
199188
200189 // Sort prefixes from longest to shortest
201190 uksort (
202191 $ prefixes ,
203- fn (string $ p1 , string $ p2 ): int =>
204- strlen ($ p2 ) <=> strlen ($ p1 )
192+ fn (string $ p1 , string $ p2 ): int => strlen ($ p2 ) <=> strlen ($ p1 )
205193 );
206194
207195 foreach ($ prefixes as $ prefix => $ dirs ) {
@@ -292,14 +280,12 @@ private static function getRegisteredLoaders(): array
292280 * @param mixed ...$args
293281 * @return TData
294282 */
295- private static function filterData (
296- $ data ,
297- string $ class ,
298- string $ method ,
299- ...$ args
300- ) {
283+ private static function filterData ($ data , string $ class , string $ method , ...$ args )
284+ {
301285 if (!class_exists (Event::class) || !Event::isLoaded ()) {
286+ // @codeCoverageIgnoreStart
302287 return $ data ;
288+ // @codeCoverageIgnoreEnd
303289 }
304290 $ event = new PackageDataReceivedEvent ($ data , $ class , $ method , ...$ args );
305291 return Event::getInstance ()->dispatch ($ event )->getData ();
@@ -330,10 +316,8 @@ private static function formatVersion(
330316 return $ version ;
331317 }
332318
333- private static function formatReference (
334- ?string $ ref ,
335- bool $ short
336- ): ?string {
319+ private static function formatRef (?string $ ref , bool $ short ): ?string
320+ {
337321 if ($ ref === null || !$ short ) {
338322 return $ ref ;
339323 }
0 commit comments