@@ -91,7 +91,7 @@ public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
9191 */
9292 public function mkdir ($ dirs , $ mode = 0777 )
9393 {
94- foreach ($ this ->toIterator ($ dirs ) as $ dir ) {
94+ foreach ($ this ->toIterable ($ dirs ) as $ dir ) {
9595 if (is_dir ($ dir )) {
9696 continue ;
9797 }
@@ -120,7 +120,7 @@ public function exists($files)
120120 {
121121 $ maxPathLength = PHP_MAXPATHLEN - 2 ;
122122
123- foreach ($ this ->toIterator ($ files ) as $ file ) {
123+ foreach ($ this ->toIterable ($ files ) as $ file ) {
124124 if (strlen ($ file ) > $ maxPathLength ) {
125125 throw new IOException (sprintf ('Could not check if file exist because path length exceeds %d characters. ' , $ maxPathLength ), 0 , null , $ file );
126126 }
@@ -144,7 +144,7 @@ public function exists($files)
144144 */
145145 public function touch ($ files , $ time = null , $ atime = null )
146146 {
147- foreach ($ this ->toIterator ($ files ) as $ file ) {
147+ foreach ($ this ->toIterable ($ files ) as $ file ) {
148148 $ touch = $ time ? @touch ($ file , $ time , $ atime ) : @touch ($ file );
149149 if (true !== $ touch ) {
150150 throw new IOException (sprintf ('Failed to touch "%s". ' , $ file ), 0 , null , $ file );
@@ -200,7 +200,7 @@ public function remove($files)
200200 */
201201 public function chmod ($ files , $ mode , $ umask = 0000 , $ recursive = false )
202202 {
203- foreach ($ this ->toIterator ($ files ) as $ file ) {
203+ foreach ($ this ->toIterable ($ files ) as $ file ) {
204204 if (true !== @chmod ($ file , $ mode & ~$ umask )) {
205205 throw new IOException (sprintf ('Failed to chmod file "%s". ' , $ file ), 0 , null , $ file );
206206 }
@@ -221,7 +221,7 @@ public function chmod($files, $mode, $umask = 0000, $recursive = false)
221221 */
222222 public function chown ($ files , $ user , $ recursive = false )
223223 {
224- foreach ($ this ->toIterator ($ files ) as $ file ) {
224+ foreach ($ this ->toIterable ($ files ) as $ file ) {
225225 if ($ recursive && is_dir ($ file ) && !is_link ($ file )) {
226226 $ this ->chown (new \FilesystemIterator ($ file ), $ user , true );
227227 }
@@ -248,7 +248,7 @@ public function chown($files, $user, $recursive = false)
248248 */
249249 public function chgrp ($ files , $ group , $ recursive = false )
250250 {
251- foreach ($ this ->toIterator ($ files ) as $ file ) {
251+ foreach ($ this ->toIterable ($ files ) as $ file ) {
252252 if ($ recursive && is_dir ($ file ) && !is_link ($ file )) {
253253 $ this ->chgrp (new \FilesystemIterator ($ file ), $ group , true );
254254 }
@@ -370,7 +370,7 @@ public function hardlink($originFile, $targetFiles)
370370 throw new FileNotFoundException (sprintf ('Origin file "%s" is not a file ' , $ originFile ));
371371 }
372372
373- foreach ($ this ->toIterator ($ targetFiles ) as $ targetFile ) {
373+ foreach ($ this ->toIterable ($ targetFiles ) as $ targetFile ) {
374374 if (is_file ($ targetFile )) {
375375 if (fileinode ($ originFile ) === fileinode ($ targetFile )) {
376376 continue ;
@@ -724,18 +724,9 @@ public function appendToFile($filename, $content)
724724 }
725725 }
726726
727- /**
728- * @param mixed $files
729- *
730- * @return \Traversable
731- */
732- private function toIterator ($ files )
727+ private function toIterable ($ files ): iterable
733728 {
734- if (!$ files instanceof \Traversable) {
735- $ files = new \ArrayObject (is_array ($ files ) ? $ files : array ($ files ));
736- }
737-
738- return $ files ;
729+ return is_array ($ files ) || $ files instanceof \Traversable ? $ files : array ($ files );
739730 }
740731
741732 /**
0 commit comments