Skip to content

Commit

Permalink
refactor: change method name
Browse files Browse the repository at this point in the history
  • Loading branch information
papac committed Dec 13, 2024
1 parent 5ba2a2f commit 04edbf8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions src/Storage/Service/FTPService.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function connect()
$this->connection = $connection;

$this->login();
$this->setConnectionRoot();
$this->changePath();
$this->setConnectionPassiveMode();
}

Expand Down Expand Up @@ -165,21 +165,18 @@ private function login(): bool
}

/**
* Set the connection root.
* Change path.
*
* @param string $path
* @return void
*/
public function setConnectionRoot(string $path = '')
public function changePath(?string $path = null)
{
$base_path = $path ?: $this->config['root'];

if ($base_path && (!@ftp_chdir($this->connection, $base_path))) {
throw new RuntimeException('Root is invalid or does not exist: ' . $base_path);
}

// Store absolute path for further reference.
ftp_pwd($this->connection);
}

/**
Expand Down Expand Up @@ -359,13 +356,13 @@ public function makeDirectory(string $dirname, int $mode = 0777): bool

foreach ($directories as $directory) {
if (false === $this->makeActualDirectory($directory)) {
$this->setConnectionRoot();
$this->changePath();
return false;
}
ftp_chdir($connection, $directory);
}

$this->setConnectionRoot();
$this->changePath();

return true;
}
Expand Down Expand Up @@ -567,7 +564,7 @@ protected function listDirectoryContents($directory = '.')

$listing = @ftp_rawlist($this->getConnection(), '.') ?: [];

$this->setConnectionRoot();
$this->changePath();

return $this->normalizeDirectoryListing($listing);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Filesystem/FTPServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function setUp(): void

protected function tearDown(): void
{
$this->ftp_service->setConnectionRoot();
$this->ftp_service->changePath();
}

public function test_the_connection()
Expand Down

0 comments on commit 04edbf8

Please sign in to comment.