2121use Config \Autoload ;
2222use Config \Kint as KintConfig ;
2323use Config \Modules ;
24- use Kint ;
24+ use Kint \ Kint ;
2525use Kint \Renderer \CliRenderer ;
2626use Kint \Renderer \RichRenderer ;
2727
@@ -67,29 +67,29 @@ class Autoloader
6767 /**
6868 * Stores namespaces as key, and path as values.
6969 *
70- * @var array<string, list<string>>
70+ * @var array<non-empty- string, list<non-empty- string>>
7171 */
7272 protected $ prefixes = [];
7373
7474 /**
7575 * Stores class name as key, and path as values.
7676 *
77- * @var array<class-string, string>
77+ * @var array<class-string, non-empty- string>
7878 */
7979 protected $ classmap = [];
8080
8181 /**
8282 * Stores files as a list.
8383 *
84- * @var list<string>
84+ * @var list<non-empty- string>
8585 */
8686 protected $ files = [];
8787
8888 /**
8989 * Stores helper list.
9090 * Always load the URL helper, it should be used in most apps.
9191 *
92- * @var list<string>
92+ * @var list<non-empty- string>
9393 */
9494 protected $ helpers = ['url ' ];
9595
@@ -147,36 +147,35 @@ private function loadComposerAutoloader(Modules $modules): void
147147
148148 // Should we load through Composer's namespaces, also?
149149 if ($ modules ->discoverInComposer ) {
150- // @phpstan-ignore-next-line
151- $ this ->loadComposerNamespaces ($ composer , $ modules -> composerPackages ?? []);
150+ $ composerPackages = $ modules -> composerPackages ;
151+ $ this ->loadComposerNamespaces ($ composer , $ composerPackages ?? []);
152152 }
153153
154154 unset($ composer );
155155 }
156156
157157 /**
158- * Register the loader with the SPL autoloader stack.
158+ * Register the loader with the SPL autoloader stack
159+ * in the following order:
160+ *
161+ * 1. Classmap loader
162+ * 2. PSR-4 autoloader
163+ * 3. Non-class files
159164 *
160165 * @return void
161166 */
162167 public function register ()
163168 {
164- // Register classmap loader for the files in our class map.
165169 spl_autoload_register ($ this ->loadClassmap (...), true );
166-
167- // Register the PSR-4 autoloader.
168170 spl_autoload_register ($ this ->loadClass (...), true );
169171
170- // Load our non-class files
171172 foreach ($ this ->files as $ file ) {
172173 $ this ->includeFile ($ file );
173174 }
174175 }
175176
176177 /**
177- * Unregister autoloader.
178- *
179- * This method is for testing.
178+ * Unregisters the autoloader from the SPL autoload stack.
180179 */
181180 public function unregister (): void
182181 {
@@ -187,7 +186,7 @@ public function unregister(): void
187186 /**
188187 * Registers namespaces with the autoloader.
189188 *
190- * @param array<string, list<string>|string>|string $namespace
189+ * @param array<non-empty- string, list<non-empty- string>|non-empty- string>|non-empty- string $namespace
191190 *
192191 * @return $this
193192 */
@@ -219,7 +218,7 @@ public function addNamespace($namespace, ?string $path = null)
219218 *
220219 * If a prefix param is set, returns only paths to the given prefix.
221220 *
222- * @return ($prefix is null ? array<string, list<string>> : list<string>)
221+ * @return ($prefix is null ? array<non-empty- string, list<non-empty- string>> : list<non-empty- string>)
223222 */
224223 public function getNamespace (?string $ prefix = null )
225224 {
@@ -247,6 +246,8 @@ public function removeNamespace(string $namespace)
247246 /**
248247 * Load a class using available class mapping.
249248 *
249+ * @param class-string $class The fully qualified class name.
250+ *
250251 * @internal For `spl_autoload_register` use.
251252 */
252253 public function loadClassmap (string $ class ): void
@@ -261,9 +262,9 @@ public function loadClassmap(string $class): void
261262 /**
262263 * Loads the class file for a given class name.
263264 *
264- * @internal For `spl_autoload_register` use .
265+ * @param class-string $class The fully qualified class name .
265266 *
266- * @param string $class The fully qualified class name .
267+ * @internal For `spl_autoload_register` use .
267268 */
268269 public function loadClass (string $ class ): void
269270 {
@@ -273,9 +274,9 @@ public function loadClass(string $class): void
273274 /**
274275 * Loads the class file for a given class name.
275276 *
276- * @param string $class The fully- qualified class name
277+ * @param class- string $class The fully qualified class name.
277278 *
278- * @return false|string The mapped file name on success, or boolean false on fail
279+ * @return false|non-empty- string The mapped file name on success, or boolean false on fail
279280 */
280281 protected function loadInNamespace (string $ class )
281282 {
@@ -293,21 +294,20 @@ protected function loadInNamespace(string $class)
293294 $ filePath = $ directory . $ relativeClassPath . '.php ' ;
294295 $ filename = $ this ->includeFile ($ filePath );
295296
296- if ($ filename ) {
297+ if ($ filename !== false ) {
297298 return $ filename ;
298299 }
299300 }
300301 }
301302 }
302303
303- // never found a mapped file
304304 return false ;
305305 }
306306
307307 /**
308308 * A central way to include a file. Split out primarily for testing purposes.
309309 *
310- * @return false|string The filename on success, false if the file is not loaded
310+ * @return false|non-empty- string The filename on success, false if the file is not loaded
311311 */
312312 protected function includeFile (string $ file )
313313 {
0 commit comments