From e6fbd8ba8da735f3237e1f73c881c809ed4f0ab9 Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Wed, 26 Oct 2022 20:15:09 +0200 Subject: [PATCH] more modern properties --- src/AwsS3V3/PortableVisibilityConverter.php | 8 +- src/Ftp/FtpAdapter.php | 5 +- src/Ftp/FtpConnectionOptions.php | 117 +++--------------- .../GoogleCloudStorageAdapter.php | 8 +- src/Local/LocalFilesystemAdapter.php | 41 +----- src/PathPrefixing/PathPrefixedAdapter.php | 4 +- src/PhpseclibV3/SftpAdapter.php | 25 +--- src/PhpseclibV3/SftpConnectionProvider.php | 87 ++----------- src/PhpseclibV3/SftpStub.php | 2 +- .../StubSftpConnectionProvider.php | 32 +---- 10 files changed, 48 insertions(+), 281 deletions(-) diff --git a/src/AwsS3V3/PortableVisibilityConverter.php b/src/AwsS3V3/PortableVisibilityConverter.php index ba8db9046..41ec164c5 100644 --- a/src/AwsS3V3/PortableVisibilityConverter.php +++ b/src/AwsS3V3/PortableVisibilityConverter.php @@ -13,14 +13,8 @@ class PortableVisibilityConverter implements VisibilityConverter private const PUBLIC_ACL = 'public-read'; private const PRIVATE_ACL = 'private'; - /** - * @var string - */ - private $defaultForDirectories; - - public function __construct(string $defaultForDirectories = Visibility::PUBLIC) + public function __construct(private string $defaultForDirectories = Visibility::PUBLIC) { - $this->defaultForDirectories = $defaultForDirectories; } public function visibilityToAcl(string $visibility): string diff --git a/src/Ftp/FtpAdapter.php b/src/Ftp/FtpAdapter.php index b78ba8ba8..0496824ca 100644 --- a/src/Ftp/FtpAdapter.php +++ b/src/Ftp/FtpAdapter.php @@ -47,8 +47,8 @@ class FtpAdapter implements FilesystemAdapter private PathPrefixer $prefixer; private VisibilityConverter $visibilityConverter; private ?bool $isPureFtpdServer = null; - private ?bool $useRawListOptions = null; - private ?string $systemType = null; + private ?bool $useRawListOptions; + private ?string $systemType; private MimeTypeDetector $mimeTypeDetector; private ?string $rootDirectory = null; @@ -60,6 +60,7 @@ public function __construct( VisibilityConverter $visibilityConverter = null, MimeTypeDetector $mimeTypeDetector = null ) { + $this->systemType = $this->connectionOptions->systemType(); $this->connectionProvider = $connectionProvider ?: new FtpConnectionProvider(); $this->connectivityChecker = $connectivityChecker ?: new NoopCommandConnectivityChecker(); $this->visibilityConverter = $visibilityConverter ?: new PortableVisibilityConverter(); diff --git a/src/Ftp/FtpConnectionOptions.php b/src/Ftp/FtpConnectionOptions.php index df18f1a93..61d21a945 100644 --- a/src/Ftp/FtpConnectionOptions.php +++ b/src/Ftp/FtpConnectionOptions.php @@ -8,110 +8,23 @@ class FtpConnectionOptions { - /** - * @var string - */ - private $host; - - /** - * @var string - */ - private $root; - - /** - * @var string - */ - private $username; - - /** - * @var string - */ - private $password; - - /** - * @var int - */ - private $port; - - /** - * @var bool - */ - private $ssl; - - /** - * @var int - */ - private $timeout; - - /** - * @var bool - */ - private $utf8; - - /** - * @var bool - */ - private $passive; - - /** - * @var int - */ - private $transferMode; - - /** - * @var string|null - */ - private $systemType; - - /** - * @var bool|null - */ - private $ignorePassiveAddress; - - /** - * @var bool - */ - private $enableTimestampsOnUnixListings; - - /** - * @var bool - */ - private $recurseManually; - - private ?bool $useRawListOptions; - public function __construct( - string $host, - string $root, - string $username, - string $password, - int $port = 21, - bool $ssl = false, - int $timeout = 90, - bool $utf8 = false, - bool $passive = true, - int $transferMode = FTP_BINARY, - ?string $systemType = null, - ?bool $ignorePassiveAddress = null, - bool $enableTimestampsOnUnixListings = false, - bool $recurseManually = false, - ?bool $useRawListOptions = null, + private string $host, + private string $root, + private string $username, + private string $password, + private int $port = 21, + private bool $ssl = false, + private int $timeout = 90, + private bool $utf8 = false, + private bool $passive = true, + private int $transferMode = FTP_BINARY, + private ?string $systemType = null, + private ?bool $ignorePassiveAddress = null, + private bool $enableTimestampsOnUnixListings = false, + private bool $recurseManually = false, + private ?bool $useRawListOptions = null, ) { - $this->host = $host; - $this->root = $root; - $this->username = $username; - $this->password = $password; - $this->port = $port; - $this->ssl = $ssl; - $this->timeout = $timeout; - $this->utf8 = $utf8; - $this->passive = $passive; - $this->transferMode = $transferMode; - $this->systemType = $systemType; - $this->ignorePassiveAddress = $ignorePassiveAddress; - $this->enableTimestampsOnUnixListings = $enableTimestampsOnUnixListings; - $this->recurseManually = $recurseManually; - $this->useRawListOptions = $useRawListOptions; } public function host(): string diff --git a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php index f3dfc4fc9..74613a2b5 100644 --- a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php +++ b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php @@ -46,10 +46,8 @@ class GoogleCloudStorageAdapter implements FilesystemAdapter, PublicUrlGenerator, ChecksumProvider, TemporaryUrlGenerator { - private Bucket $bucket; private PathPrefixer $prefixer; private VisibilityHandler $visibilityHandler; - private string $defaultVisibility; private MimeTypeDetector $mimeTypeDetector; private static array $algoToInfoMap = [ @@ -59,16 +57,14 @@ class GoogleCloudStorageAdapter implements FilesystemAdapter, PublicUrlGenerator ]; public function __construct( - Bucket $bucket, + private Bucket $bucket, string $prefix = '', VisibilityHandler $visibilityHandler = null, - string $defaultVisibility = Visibility::PRIVATE, + private string $defaultVisibility = Visibility::PRIVATE, MimeTypeDetector $mimeTypeDetector = null ) { - $this->bucket = $bucket; $this->prefixer = new PathPrefixer($prefix); $this->visibilityHandler = $visibilityHandler ?: new PortableVisibilityHandler(); - $this->defaultVisibility = $defaultVisibility; $this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector(); } diff --git a/src/Local/LocalFilesystemAdapter.php b/src/Local/LocalFilesystemAdapter.php index bf6ffec90..a25d73339 100644 --- a/src/Local/LocalFilesystemAdapter.php +++ b/src/Local/LocalFilesystemAdapter.php @@ -58,35 +58,9 @@ class LocalFilesystemAdapter implements FilesystemAdapter, ChecksumProvider */ public const DISALLOW_LINKS = 0002; - /** - * @var PathPrefixer - */ - private $prefixer; - - /** - * @var int - */ - private $writeFlags; - - /** - * @var int - */ - private $linkHandling; - - /** - * @var VisibilityConverter - */ - private $visibility; - - /** - * @var MimeTypeDetector - */ - private $mimeTypeDetector; - - /** - * @var string - */ - private $rootLocation; + private PathPrefixer $prefixer; + private VisibilityConverter $visibility; + private MimeTypeDetector $mimeTypeDetector; /** * @var bool @@ -96,16 +70,13 @@ class LocalFilesystemAdapter implements FilesystemAdapter, ChecksumProvider public function __construct( string $location, VisibilityConverter $visibility = null, - int $writeFlags = LOCK_EX, - int $linkHandling = self::DISALLOW_LINKS, + private int $writeFlags = LOCK_EX, + private int $linkHandling = self::DISALLOW_LINKS, MimeTypeDetector $mimeTypeDetector = null, bool $lazyRootCreation = false, ) { $this->prefixer = new PathPrefixer($location, DIRECTORY_SEPARATOR); - $this->writeFlags = $writeFlags; - $this->linkHandling = $linkHandling; $this->visibility = $visibility ?: new PortableVisibilityConverter(); - $this->rootLocation = $location; $this->mimeTypeDetector = $mimeTypeDetector ?: new FallbackMimeTypeDetector(new FinfoMimeTypeDetector()); if ( ! $lazyRootCreation) { @@ -119,7 +90,7 @@ private function ensureRootDirectoryExists(): void return; } - $this->ensureDirectoryExists($this->rootLocation, $this->visibility->defaultForDirectories()); + $this->ensureDirectoryExists($this->prefixer->prefixPath('/'), $this->visibility->defaultForDirectories()); } public function write(string $path, string $contents, Config $config): void diff --git a/src/PathPrefixing/PathPrefixedAdapter.php b/src/PathPrefixing/PathPrefixedAdapter.php index 617c6c3d7..bcc11bfaa 100644 --- a/src/PathPrefixing/PathPrefixedAdapter.php +++ b/src/PathPrefixing/PathPrefixedAdapter.php @@ -31,16 +31,14 @@ class PathPrefixedAdapter implements FilesystemAdapter, PublicUrlGenerator, Chec { use CalculateChecksumFromStream; - protected FilesystemAdapter $adapter; private PathPrefixer $prefix; - public function __construct(FilesystemAdapter $adapter, string $prefix) + public function __construct(private FilesystemAdapter $adapter, string $prefix) { if ($prefix === '') { throw new \InvalidArgumentException('The prefix must not be empty.'); } - $this->adapter = $adapter; $this->prefix = new PathPrefixer($prefix); } diff --git a/src/PhpseclibV3/SftpAdapter.php b/src/PhpseclibV3/SftpAdapter.php index 94d2fcbcc..d7a1035de 100644 --- a/src/PhpseclibV3/SftpAdapter.php +++ b/src/PhpseclibV3/SftpAdapter.php @@ -31,33 +31,16 @@ class SftpAdapter implements FilesystemAdapter { - /** - * @var ConnectionProvider - */ - private $connectionProvider; - - /** - * @var VisibilityConverter - */ - private $visibilityConverter; - - /** - * @var PathPrefixer - */ - private $prefixer; - - /** - * @var MimeTypeDetector - */ - private $mimeTypeDetector; + private VisibilityConverter $visibilityConverter; + private PathPrefixer $prefixer; + private MimeTypeDetector $mimeTypeDetector; public function __construct( - ConnectionProvider $connectionProvider, + private ConnectionProvider $connectionProvider, string $root, VisibilityConverter $visibilityConverter = null, MimeTypeDetector $mimeTypeDetector = null ) { - $this->connectionProvider = $connectionProvider; $this->prefixer = new PathPrefixer($root); $this->visibilityConverter = $visibilityConverter ?: new PortableVisibilityConverter(); $this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector(); diff --git a/src/PhpseclibV3/SftpConnectionProvider.php b/src/PhpseclibV3/SftpConnectionProvider.php index 5cd3f5f8d..7aee44865 100644 --- a/src/PhpseclibV3/SftpConnectionProvider.php +++ b/src/PhpseclibV3/SftpConnectionProvider.php @@ -18,35 +18,6 @@ class SftpConnectionProvider implements ConnectionProvider { - /** - * @var string - */ - private $host; - - /** - * @var string - */ - private $username; - - /** - * @var string|null - */ - private $password; - - /** - * @var bool - */ - private $useAgent; - - /** - * @var int - */ - private $port; - - /** - * @var int - */ - private $timeout; /** * @var SFTP|null @@ -58,57 +29,21 @@ class SftpConnectionProvider implements ConnectionProvider */ private $connectivityChecker; - /** - * @var string|null - */ - private $hostFingerprint; - - /** - * @var string|null - */ - private $privateKey; - - /** - * @var string|null - */ - private $passphrase; - - /** - * @var int - */ - private $maxTries; - - /** - * @var array - */ - private $preferredAlgorithms; - public function __construct( - string $host, - string $username, - string $password = null, - string $privateKey = null, - string $passphrase = null, - int $port = 22, - bool $useAgent = false, - int $timeout = 10, - int $maxTries = 4, - string $hostFingerprint = null, + private string $host, + private string $username, + private ?string $password = null, + private ?string $privateKey = null, + private ?string $passphrase = null, + private int $port = 22, + private bool $useAgent = false, + private int $timeout = 10, + private int $maxTries = 4, + private ?string $hostFingerprint = null, ConnectivityChecker $connectivityChecker = null, - array $preferredAlgorithms = [] + private array $preferredAlgorithms = [] ) { - $this->host = $host; - $this->username = $username; - $this->password = $password; - $this->privateKey = $privateKey; - $this->passphrase = $passphrase; - $this->useAgent = $useAgent; - $this->port = $port; - $this->timeout = $timeout; - $this->hostFingerprint = $hostFingerprint; $this->connectivityChecker = $connectivityChecker ?: new SimpleConnectivityChecker(); - $this->maxTries = $maxTries; - $this->preferredAlgorithms = $preferredAlgorithms; } public function provideConnection(): SFTP diff --git a/src/PhpseclibV3/SftpStub.php b/src/PhpseclibV3/SftpStub.php index 91d291c09..a1c590106 100644 --- a/src/PhpseclibV3/SftpStub.php +++ b/src/PhpseclibV3/SftpStub.php @@ -14,7 +14,7 @@ class SftpStub extends SFTP /** * @var array */ - private $tripWires = []; + private array $tripWires = []; public function failOnChmod(string $filename): void { diff --git a/src/PhpseclibV3/StubSftpConnectionProvider.php b/src/PhpseclibV3/StubSftpConnectionProvider.php index c01834cd2..e75dc15c2 100644 --- a/src/PhpseclibV3/StubSftpConnectionProvider.php +++ b/src/PhpseclibV3/StubSftpConnectionProvider.php @@ -8,41 +8,17 @@ class StubSftpConnectionProvider implements ConnectionProvider { - /** - * @var string - */ - private $host; - - /** - * @var string - */ - private $username; - - /** - * @var string|null - */ - private $password; - - /** - * @var int - */ - private $port; - /** * @var SftpStub */ private $connection; public function __construct( - string $host, - string $username, - string $password = null, - int $port = 22 + private string $host, + private string $username, + private ?string $password = null, + private int $port = 22 ) { - $this->host = $host; - $this->username = $username; - $this->password = $password; - $this->port = $port; } public function provideConnection(): SFTP