8000 [Filesystem] Replace remaing docblocks by type-hints by ro0NL · Pull Request #24926 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Filesystem] Replace remaing docblocks by type-hints #24926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 28 additions & 46 deletions src/Symfony/Component/Filesystem/Filesystem.php
8000 8000 8000
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
/**
* Creates a directory recursively.
*
* @param string|array|\Traversable $dirs The directory path
* @param int $mode The directory mode
* @param string|iterable $dirs The directory path
* @param int $mode The directory mode
*
* @throws IOException On any directory creation failure
*/
public function mkdir($dirs, $mode = 0777)
{
foreach ($this->toIterator($dirs) as $dir) {
foreach ($this->toIterable($dirs) as $dir) {
if (is_dir($dir)) {
continue;
}
Expand All @@ -112,15 +112,15 @@ public function mkdir($dirs, $mode = 0777)
/**
* Checks the existence of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to check
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to check
*
* @return bool true if the file exists, false otherwise
*/
public function exists($files)
{
$maxPathLength = PHP_MAXPATHLEN - 2;

foreach ($this->toIterator($files) as $file) {
foreach ($this->toIterable($files) as $file) {
if (strlen($file) > $maxPathLength) {
throw new IOException(sprintf('Could not check if file exist because path length exceeds %d characters.', $maxPathLength), 0, null, $file);
}
Expand All @@ -136,15 +136,15 @@ public function exists($files)
/**
* Sets access and modification time of file.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to create
* @param int $time The touch time as a Unix timestamp
* @param int $atime The access time as a Unix timestamp
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to create
* @param int $time The touch time as a Unix timestamp
* @param int $atime The access time as a Unix timestamp
*
* @throws IOException When touch fails
*/
public function touch($files, $time = null, $atime = null)
{
foreach ($this->toIterator($files) as $file) {
foreach ($this->toIterable( 8000 $files) as $file) {
$touch = $time ? @touch($file, $time, $atime) : @touch($file);
if (true !== $touch) {
throw new IOException(sprintf('Failed to touch "%s".', $file), 0, null, $file);
Expand All @@ -155,7 +155,7 @@ public function touch($files, $time = null, $atime = null)
/**
* Removes files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to remove
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to remove
*
* @throws IOException When removal fails
*/
Expand Down Expand Up @@ -191,16 +191,16 @@ public function remove($files)
/**
* Change mode for an array of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to change mode
* @param int $mode The new mode (octal)
* @param int $umask The mode mask (octal)
* @param bool $recursive Whether change the mod recursively or not
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to change mode
* @param int $mode The new mode (octal)
* @param int $umask The mode mask (octal)
* @param bool $recursive Whether change the mod recursively or not
*
* @throws IOException When the change fail
*/
public function chmod($files, $mode, $umask = 0000, $recursive = false)
{
foreach ($this->toIterator($files) as $file) {
foreach ($this->toIterable($files) as $file) {
if (true !== @chmod($file, $mode & ~$umask)) {
throw new IOException(sprintf('Failed to chmod file "%s".', $file), 0, null, $file);
}
Expand All @@ -213,15 +213,15 @@ public function chmod($files, $mode, $umask = 0000, $recursive = false)
/**
* Change the owner of an array of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to change owner
* @param string $user The new owner user name
* @param bool $recursive Whether change the owner recursively or not
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to change owner
* @param string $user The new owner user name
* @param bool $recursive Whether change the owner recursively or not
*
* @throws IOException When the change fail
*/
public function chown($files, $user, $recursive = false)
{
foreach ($this->toIterator($files) as $file) {
foreach ($this->toIterable($files) as $file) {
if ($recursive && is_dir($file) && !is_link($file)) {
$this->chown(new \FilesystemIterator($file), $user, true);
}
Expand All @@ -240,15 +240,15 @@ public function chown($files, $user, $recursive = false)
/**
* Change the group of an array of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to change group
* @param string $group The group name
* @param bool $recursive Whether change the group recursively or not
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to change group
* @param string $group The group name
* @param bool $recursive Whether change the group recursively or not
*
* @throws IOException When the change fail
*/
public function chgrp($files, $group, $recursive = false)
{
foreach ($this->toIterator($files) as $file) {
foreach ($this->toIterable($files) as $file) {
if ($recursive && is_dir($file) && !is_link($file)) {
$this->chgrp(new \FilesystemIterator($file), $group, true);
}
Expand Down Expand Up @@ -296,13 +296,9 @@ public function rename($origin, $target, $overwrite = false)
/**
* Tells whether a file exists and is readable.
*
* @param string $filename Path to the file
*
* @return bool
*
* @throws IOException When windows path is longer than 258 characters
*/
private function isReadable($filename)
private function isReadable(string $filename): bool
{
$maxPathLength = PHP_MAXPATHLEN - 2;

Expand Down Expand Up @@ -370,7 +366,7 @@ public function hardlink($originFile, $targetFiles)
throw new FileNotFoundException(sprintf('Origin file "%s" is not a file', $originFile));
}

foreach ($this->toIterator($targetFiles) as $targetFile) {
foreach ($this->toIterable($targetFiles) as $targetFile) {
if (is_file($targetFile)) {
if (fileinode($originFile) === fileinode($targetFile)) {
continue;
Expand All @@ -384,12 +380,7 @@ public function hardlink($originFile, $targetFiles)
}
}

/**
* @param string $origin
* @param string $target
* @param string $linkType Name of the link type, typically 'symbolic' or 'hard'
*/
private function linkException($origin, $target, $linkType)
private function linkException(string $origin, string $target, string $linkType): void
{
$report = error_get_last();
if (is_array($report)) {
Expand Down Expand Up @@ -724,18 +715,9 @@ public function appendToFile($filename, $content)
}
}

/**
* @param mixed $files
*
* @return \Traversable
*/
private function toIterator($files)
private function toIterable($files): iterable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name change is debatable, and creates useless diff lines, thus won't help merges
should be reverted IMHO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hence #24928 :)

{
if (!$files instanceof \Traversable) {
$files = new \ArrayObject(is_array($files) ? $files : array($files));
}

return $files;
return is_iterable($files) ? $files : array($files);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this implementation is not compatible with the previous, won't it create BC breaks f the return is forwarded as return value of a public method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private API :) checked all usages; they truly rely on a foreachable value.

}

/**
Expand Down
0