8000 [Filesystem] toIterable() in favor of toIterator() · symfony/symfony@36462d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 36462d6

Browse files
ro0NLfabpot
authored andcommitted
[Filesystem] toIterable() in favor of toIterator()
1 parent 23ab29f commit 36462d6

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
9090
*/
9191
public function mkdir($dirs, $mode = 0777)
9292
{
93-
foreach ($this->toIterator($dirs) as $dir) {
93+
foreach ($this->toIterable($dirs) as $dir) {
9494
if (is_dir($dir)) {
9595
continue;
9696
}
@@ -119,7 +119,7 @@ public function exists($files)
119119
{
120120
$maxPathLength = PHP_MAXPATHLEN - 2;
121121

122-
foreach ($this->toIterator($files) as $file) {
122+
foreach ($this->toIterable($files) as $file) {
123123
if (strlen($file) > $maxPathLength) {
124124
throw new IOException(sprintf('Could not check if file exist because path length exceeds %d characters.', $maxPathLength), 0, null, $file);
125125
}
@@ -143,7 +143,7 @@ public function exists($files)
143143
*/
144144
public function touch($files, $time = null, $atime = null)
145145
{
146-
foreach ($this->toIterator($files) as $file) {
146+
foreach ($this->toIterable($files) as $file) {
147147
$touch = $time ? @touch($file, $time, $atime) : @touch($file);
148148
if (true !== $touch) {
149149
throw new IOException(sprintf('Failed to touch "%s".', $file), 0, null, $file);
@@ -199,7 +199,7 @@ public function remove($files)
199199
*/
200200
public function chmod($files, $mode, $umask = 0000, $recursive = false)
201201
{
202-
foreach ($this->toIterator($files) as $file) {
202+
foreach ($this->toIterable($files) as $file) {
203203
if (true !== @chmod($file, $mode & ~$umask)) {
204204
throw new IOException(sprintf('Failed to chmod file "%s".', $file), 0, null, $file);
205205
}
@@ -220,7 +220,7 @@ public function chmod($files, $mode, $umask = 0000, $recursive = false)
220220
*/
221221
public function chown($files, $user, $recursive = false)
222222
{
223-
foreach ($this->toIterator($files) as $file) {
223+
foreach ($this->toIterable($files) as $file) {
224224
if ($recursive && is_dir($file) && !is_link($file)) {
225225
$this->chown(new \FilesystemIterator($file), $user, true);
226226
}
@@ -247,7 +247,7 @@ public function chown($files, $user, $recursive = false)
247247
*/
248248
public function chgrp($files, $group, $recursive = false)
249249
{
250-
foreach ($this->toIterator($files) as $file) {
250+
foreach ($this->toIterable($files) as $file) {
251251
if ($recursive && is_dir($file) && !is_link($file)) {
252252
$this->chgrp(new \FilesystemIterator($file), $group, true);
253253
}
@@ -369,7 +369,7 @@ public function hardlink($originFile, $targetFiles)
369369
throw new FileNotFoundException(sprintf('Origin file "%s" is not a file', $originFile));
370370
}
371371

372-
foreach ($this->toIterator($targetFiles) as $targetFile) {
372+
foreach ($this->toIterable($targetFiles) as $targetFile) {
373373
if (is_file($targetFile)) {
374374
if (fileinode($originFile) === fileinode($targetFile)) {
375375
continue;
@@ -722,15 +722,11 @@ public function appendToFile($filename, $content)
722722
/**
723723
* @param mixed $files
724724
*
725-
* @return \Traversable
725+
* @return array|\Traversable
726726
*/
727-
private function toIterator($files)
727+
private function toIterable($files)
728728
{
729-
if (!$files instanceof \Traversable) {
730-
$files = new \ArrayObject(is_array($files) ? $files : array($files));
731-
}
732-
733-
return $files;
729+
return is_array($files) || $files instanceof \Traversable ? $files : array($files);
734730
}
735731

736732
/**

0 commit comments

Comments
 (0)
0