Skip to content

Commit

Permalink
Fix PHP 8.1 deprecations (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolab committed Mar 22, 2022
1 parent 9fced0e commit 9a7a3b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,24 @@ Count the items in a directory :

```php
// count in the current directory
$total = $ftp->countItems();
// or alias
$total = $ftp->count();

// count in a given directory
$total = $ftp->count('/path/of/directory');
$total = $ftp->countItems('/path/of/directory');

// count only the "files" in the current directory
$total_file = $ftp->count('.', 'file');
$total_file = $ftp->countItems('.', 'file');

// count only the "files" in a given directory
$total_file = $ftp->count('/path/of/directory', 'file');
$total_file = $ftp->countItems('/path/of/directory', 'file');

// count only the "directories" in a given directory
$total_dir = $ftp->count('/path/of/directory', 'directory');
$total_dir = $ftp->countItems('/path/of/directory', 'directory');

// count only the "symbolic links" in a given directory
$total_link = $ftp->count('/path/of/directory', 'link');
$total_link = $ftp->countItems('/path/of/directory', 'link');
```

Detailed list of all files and directories :
Expand Down
23 changes: 17 additions & 6 deletions src/FtpClient/FtpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,15 @@ public function remove($path, $recursive = false)

try {
if (@$this->ftp->delete($path)
or ($this->isDir($path)
or ($this->isDir($path)
and $this->rmdir($path, $recursive))) {
return true;
} else {
// in special cases the delete can fail (for example, at Symfony's "r+e.gex[c]a(r)s" directory)
$newPath = preg_replace('/[^A-Za-z0-9\/]/', '', $path);
if ($this->rename($path, $newPath)) {
if (@$this->ftp->delete($newPath)
or ($this->isDir($newPath)
if (@$this->ftp->delete($newPath)
or ($this->isDir($newPath)
and $this->rmdir($newPath, $recursive))) {
return true;
}
Expand Down Expand Up @@ -507,7 +507,7 @@ public function isDir($directory)
*/
public function isEmpty($directory)
{
return $this->count($directory, null, false) === 0 ? true : false;
return $this->countItems($directory, null, false) === 0 ? true : false;
}

/**
Expand Down Expand Up @@ -553,8 +553,7 @@ public function dirSize($directory = '.', $recursive = true)
* @param bool $recursive true by default
* @return int
*/
#[\ReturnTypeWillChange]
public function count($directory = '.', $type = null, $recursive = true)
public function countItems($directory = '.', $type = null, $recursive = true)
{
$items = (null === $type ? $this->nlist($directory, $recursive)
: $this->scanDir($directory, $recursive));
Expand All @@ -569,6 +568,18 @@ public function count($directory = '.', $type = null, $recursive = true)
return $count;
}

/**
* Count the items (file, directory, link, unknown).
* This method call `countItems()` with the default arguments.
*
* @see countItems
* @return int
*/
public function count()
{
return $this->countItems();
}

/**
* Downloads a file from the FTP server into a string
*
Expand Down

0 comments on commit 9a7a3b5

Please sign in to comment.