@@ -69,10 +69,8 @@ public function __construct()
6969
7070 /**
7171 * Register autoloader.
72- * @param bool $prepend
73- * @return static
7472 */
75- public function register ($ prepend = false )
73+ public function register (bool $ prepend = false ): self
7674 {
7775 $ this ->loadCache ();
7876 spl_autoload_register ([$ this , 'tryLoad ' ], true , $ prepend );
@@ -82,10 +80,8 @@ public function register($prepend = false)
8280
8381 /**
8482 * Handles autoloading of classes, interfaces or traits.
85- * @param string $type
86- * @return void
8783 */
88- public function tryLoad ($ type )
84+ public function tryLoad (string $ type ): void
8985 {
9086 $ type = ltrim ($ type , '\\' ); // PHP namespace bug #49143
9187 $ info = isset ($ this ->classes [$ type ]) ? $ this ->classes [$ type ] : null ;
@@ -120,20 +116,16 @@ public function tryLoad($type)
120116
121117 /**
122118 * Add path or paths to list.
123- * @param string|string[] $path absolute path
124- * @return static
119+ * @param string|string[] $path absolute path
125120 */
126- public function addDirectory ($ path )
121+ public function addDirectory ($ path ): self
127122 {
128123 $ this ->scanPaths = array_merge ($ this ->scanPaths , (array ) $ path );
129124 return $ this ;
130125 }
131126
132127
133- /**
134- * @return static
135- */
136- public function reportParseErrors ($ on = true )
128+ public function reportParseErrors (bool $ on = true ): self
137129 {
138130 $ this ->reportParseErrors = (bool ) $ on ;
139131 return $ this ;
@@ -142,10 +134,9 @@ public function reportParseErrors($on = true)
142134
143135 /**
144136 * Excludes path or paths from list.
145- * @param string|string[] $path absolute path
146- * @return static
137+ * @param string|string[] $path absolute path
147138 */
148- public function excludeDirectory ($ path )
139+ public function excludeDirectory ($ path ): self
149140 {
150141 $ this ->excludeDirs = array_merge ($ this ->excludeDirs , (array ) $ path );
151142 return $ this ;
@@ -155,7 +146,7 @@ public function excludeDirectory($path)
155146 /**
156147 * @return array of class => filename
157148 */
158- public function getIndexedClasses ()
149+ public function getIndexedClasses (): array
159150 {
160151 $ res = [];
161152 foreach ($ this ->classes as $ class => $ info ) {
@@ -167,9 +158,8 @@ public function getIndexedClasses()
167158
168159 /**
169160 * Rebuilds class list cache.
170- * @return void
171161 */
172- public function rebuild ()
162+ public function rebuild (): void
173163 {
174164 $ this ->classes = $ this ->missing = [];
175165 $ this ->refreshClasses ();
@@ -181,9 +171,8 @@ public function rebuild()
181171
182172 /**
183173 * Refreshes class list cache.
184- * @return void
185174 */
186- public function refresh ()
175+ public function refresh (): void
187176 {
188177 $ this ->loadCache ();
189178 if (!$ this ->refreshed ) {
@@ -195,9 +184,8 @@ public function refresh()
195184
196185 /**
197186 * Refreshes $classes.
198- * @return void
199187 */
200- private function refreshClasses ()
188+ private function refreshClasses (): void
201189 {
202190 $ this ->refreshed = true ; // prevents calling refreshClasses() or updateFile() in tryLoad()
203191 $ files = [];
@@ -233,10 +221,9 @@ private function refreshClasses()
233221
234222 /**
235223 * Creates an iterator scaning directory for PHP files, subdirectories and 'netterobots.txt' files.
236- * @return Nette\Utils\Finder
237224 * @throws Nette\IOException if path is not found
238225 */
239- private function createFileIterator ($ dir )
226+ private function createFileIterator (string $ dir ): Nette \ Utils \ Finder
240227 {
241228 if (!is_dir ($ dir )) {
242229 throw new Nette \IOException ("File or directory ' $ dir' not found. " );
@@ -274,10 +261,7 @@ private function createFileIterator($dir)
274261 }
275262
276263
277- /**
278- * @return void
279- */
280- private function updateFile ($ file )
264+ private function updateFile (string $ file ): void
281265 {
282266 foreach ($ this ->classes as $ class => $ info ) {
283267 if (isset ($ info ['file ' ]) && $ info ['file ' ] === $ file ) {
@@ -302,10 +286,9 @@ private function updateFile($file)
302286
303287 /**
304288 * Searches classes, interfaces and traits in PHP file.
305- * @param string $file
306289 * @return string[]
307290 */
308- private function scanPhp ($ file )
291+ private function scanPhp (string $ file ): array
309292 {
310293 $ code = file_get_contents ($ file );
311294 $ expected = false ;
@@ -394,9 +377,8 @@ private function scanPhp($file)
394377
395378 /**
396379 * Sets auto-refresh mode.
397- * @return static
398380 */
399- public function setAutoRefresh ($ on = true )
381+ public function setAutoRefresh (bool $ on = true ): self
400382 {
401383 $ this ->autoRebuild = (bool ) $ on ;
402384 return $ this ;
@@ -405,9 +387,8 @@ public function setAutoRefresh($on = true)
405387
406388 /**
407389 * Sets path to temporary directory.
408- * @return static
409390 */
410- public function setTempDirectory ($ dir )
391+ public function setTempDirectory (string $ dir ): self
411392 {
412393 Nette \Utils \FileSystem::createDir ($ dir );
413394 $ this ->tempDirectory = $ dir ;
@@ -417,9 +398,8 @@ public function setTempDirectory($dir)
417398
418399 /**
419400 * Loads class list from cache.
420- * @return void
421401 */
422- private function loadCache ()
402+ private function loadCache (): void
423403 {
424404 $ file = $ this ->getCacheFile ();
425405 list ($ this ->classes , $ this ->missing ) = @include $ file ; // @ file may not exist
@@ -445,9 +425,8 @@ private function loadCache()
445425
446426 /**
447427 * Writes class list to cache.
448- * @return void
449428 */
450- private function saveCache ()
429+ private function saveCache (): void
451430 {
452431 $ file = $ this ->getCacheFile ();
453432 $ tempFile = $ file . uniqid ('' , true ) . '.tmp ' ;
@@ -462,10 +441,7 @@ private function saveCache()
462441 }
463442
464443
465- /**
466- * @return string
467- */
468- private function getCacheFile ()
444+ private function getCacheFile (): string
469445 {
470446 if (!$ this ->tempDirectory ) {
471447 throw new \LogicException ('Set path to temporary directory using setTempDirectory(). ' );
@@ -474,10 +450,7 @@ private function getCacheFile()
474450 }
475451
476452
477- /**
478- * @return array
479- */
480- protected function getCacheKey ()
453+ protected function getCacheKey (): array
481454 {
482455 return [$ this ->ignoreDirs , $ this ->acceptFiles , $ this ->scanPaths , $ this ->excludeDirs ];
483456 }
0 commit comments