From 13eab2521a96a1e9437e23092c262a4cf9ac878e Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Wed, 26 Oct 2022 19:39:04 +0200 Subject: [PATCH 1/4] Property types for GCS --- .../GoogleCloudStorageAdapter.php | 29 ++++--------------- .../GoogleCloudStorageAdapterTest.php | 2 -- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php index cce5d2ad8..f3dfc4fc9 100644 --- a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php +++ b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php @@ -46,30 +46,11 @@ class GoogleCloudStorageAdapter implements FilesystemAdapter, PublicUrlGenerator, ChecksumProvider, TemporaryUrlGenerator { - /** - * @var Bucket - */ - private $bucket; - - /** - * @var PathPrefixer - */ - private $prefixer; - - /** - * @var VisibilityHandler - */ - private $visibilityHandler; - - /** - * @var string - */ - private $defaultVisibility; - - /** - * @var MimeTypeDetector - */ - private $mimeTypeDetector; + private Bucket $bucket; + private PathPrefixer $prefixer; + private VisibilityHandler $visibilityHandler; + private string $defaultVisibility; + private MimeTypeDetector $mimeTypeDetector; private static array $algoToInfoMap = [ 'md5' => 'md5Hash', diff --git a/src/GoogleCloudStorage/GoogleCloudStorageAdapterTest.php b/src/GoogleCloudStorage/GoogleCloudStorageAdapterTest.php index 6fd96df39..7433c1b39 100644 --- a/src/GoogleCloudStorage/GoogleCloudStorageAdapterTest.php +++ b/src/GoogleCloudStorage/GoogleCloudStorageAdapterTest.php @@ -13,8 +13,6 @@ use League\Flysystem\UnableToRetrieveMetadata; use League\Flysystem\UnableToWriteFile; -use function file_get_contents; - /** * @group gcs */ From 07dc5ab28140f08cf151967b76bc1fc519818f62 Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Wed, 26 Oct 2022 20:03:44 +0200 Subject: [PATCH 2/4] Convert properties to model ones --- src/AsyncAwsS3/AsyncAwsS3Adapter.php | 33 ++-------- src/AwsS3V3/AwsS3V3Adapter.php | 73 +++------------------- src/Ftp/ConnectivityCheckerThatCanFail.php | 13 +--- src/Ftp/FtpAdapter.php | 52 +++------------ 4 files changed, 26 insertions(+), 145 deletions(-) diff --git a/src/AsyncAwsS3/AsyncAwsS3Adapter.php b/src/AsyncAwsS3/AsyncAwsS3Adapter.php index 750509a03..9fdbde8c4 100644 --- a/src/AsyncAwsS3/AsyncAwsS3Adapter.php +++ b/src/AsyncAwsS3/AsyncAwsS3Adapter.php @@ -84,30 +84,9 @@ class AsyncAwsS3Adapter implements FilesystemAdapter, PublicUrlGenerator, Checks 'VersionId', ]; - /** - * @var S3Client - */ - private $client; - - /** - * @var PathPrefixer - */ - private $prefixer; - - /** - * @var string - */ - private $bucket; - - /** - * @var VisibilityConverter - */ - private $visibility; - - /** - * @var MimeTypeDetector - */ - private $mimeTypeDetector; + private PathPrefixer $prefixer; + private VisibilityConverter $visibility; + private MimeTypeDetector $mimeTypeDetector; /** * @var array|string[] @@ -123,17 +102,15 @@ class AsyncAwsS3Adapter implements FilesystemAdapter, PublicUrlGenerator, Checks * @param S3Client|SimpleS3Client $client Uploading of files larger than 5GB is only supported with SimpleS3Client */ public function __construct( - S3Client $client, - string $bucket, + private S3Client $client, + private string $bucket, string $prefix = '', VisibilityConverter $visibility = null, MimeTypeDetector $mimeTypeDetector = null, array $forwardedOptions = self::AVAILABLE_OPTIONS, array $metadataFields = self::EXTRA_METADATA_FIELDS, ) { - $this->client = $client; $this->prefixer = new PathPrefixer($prefix); - $this->bucket = $bucket; $this->visibility = $visibility ?: new PortableVisibilityConverter(); $this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector(); $this->forwardedOptions = $forwardedOptions; diff --git a/src/AwsS3V3/AwsS3V3Adapter.php b/src/AwsS3V3/AwsS3V3Adapter.php index b329acc39..60f634282 100644 --- a/src/AwsS3V3/AwsS3V3Adapter.php +++ b/src/AwsS3V3/AwsS3V3Adapter.php @@ -91,78 +91,25 @@ class AwsS3V3Adapter implements FilesystemAdapter, PublicUrlGenerator, ChecksumP 'VersionId', ]; - /** - * @var S3ClientInterface - */ - private $client; - - /** - * @var PathPrefixer - */ - private $prefixer; - - /** - * @var string - */ - private $bucket; - - /** - * @var VisibilityConverter - */ - private $visibility; - - /** - * @var MimeTypeDetector - */ - private $mimeTypeDetector; - - /** - * @var array - */ - private $options; - - /** - * @var bool - */ - private $streamReads; - - /** - * @var string[] - */ - private array $forwardedOptions; - - /** - * @var string[] - */ - private array $metadataFields; - - /** - * @var string[] - */ - private array $multipartUploadOptions; + private PathPrefixer $prefixer; + private VisibilityConverter $visibility; + private MimeTypeDetector $mimeTypeDetector; public function __construct( - S3ClientInterface $client, - string $bucket, + private S3ClientInterface $client, + private string $bucket, string $prefix = '', VisibilityConverter $visibility = null, MimeTypeDetector $mimeTypeDetector = null, - array $options = [], - bool $streamReads = true, - array $forwardedOptions = self::AVAILABLE_OPTIONS, - array $metadataFields = self::EXTRA_METADATA_FIELDS, - array $multipartUploadOptions = self::MUP_AVAILABLE_OPTIONS, + private array $options = [], + private bool $streamReads = true, + private array $forwardedOptions = self::AVAILABLE_OPTIONS, + private array $metadataFields = self::EXTRA_METADATA_FIELDS, + private array $multipartUploadOptions = self::MUP_AVAILABLE_OPTIONS, ) { - $this->client = $client; $this->prefixer = new PathPrefixer($prefix); - $this->bucket = $bucket; $this->visibility = $visibility ?: new PortableVisibilityConverter(); $this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector(); - $this->options = $options; - $this->streamReads = $streamReads; - $this->forwardedOptions = $forwardedOptions; - $this->metadataFields = $metadataFields; - $this->multipartUploadOptions = $multipartUploadOptions; } public function fileExists(string $path): bool diff --git a/src/Ftp/ConnectivityCheckerThatCanFail.php b/src/Ftp/ConnectivityCheckerThatCanFail.php index a373b007a..3bdbf264d 100644 --- a/src/Ftp/ConnectivityCheckerThatCanFail.php +++ b/src/Ftp/ConnectivityCheckerThatCanFail.php @@ -6,19 +6,10 @@ class ConnectivityCheckerThatCanFail implements ConnectivityChecker { - /** - * @var bool - */ - private $failNextCall = false; - - /** - * @var ConnectivityChecker - */ - private $connectivityChecker; + private bool $failNextCall = false; - public function __construct(ConnectivityChecker $connectivityChecker) + public function __construct(private ConnectivityChecker $connectivityChecker) { - $this->connectivityChecker = $connectivityChecker; } public function failNextCall(): void diff --git a/src/Ftp/FtpAdapter.php b/src/Ftp/FtpAdapter.php index e0a9fd517..b78ba8ba8 100644 --- a/src/Ftp/FtpAdapter.php +++ b/src/Ftp/FtpAdapter.php @@ -37,63 +37,29 @@ class FtpAdapter implements FilesystemAdapter private const SYSTEM_TYPE_WINDOWS = 'windows'; private const SYSTEM_TYPE_UNIX = 'unix'; - /** - * @var FtpConnectionOptions - */ - private $connectionOptions; - - /** - * @var FtpConnectionProvider - */ - private $connectionProvider; - - /** - * @var ConnectivityChecker - */ - private $connectivityChecker; + private FtpConnectionProvider $connectionProvider; + private ConnectivityChecker $connectivityChecker; /** * @var resource|false|\FTP\Connection */ - private $connection = false; - - /** - * @var PathPrefixer - */ - private $prefixer; - - /** - * @var VisibilityConverter - */ - private $visibilityConverter; - - /** - * @var bool|null - */ - private $isPureFtpdServer; - + private mixed $connection = false; + private PathPrefixer $prefixer; + private VisibilityConverter $visibilityConverter; + private ?bool $isPureFtpdServer = null; private ?bool $useRawListOptions = null; - - /** - * @var null|string - */ - private $systemType; - - /** - * @var MimeTypeDetector - */ - private $mimeTypeDetector; + private ?string $systemType = null; + private MimeTypeDetector $mimeTypeDetector; private ?string $rootDirectory = null; public function __construct( - FtpConnectionOptions $connectionOptions, + private FtpConnectionOptions $connectionOptions, FtpConnectionProvider $connectionProvider = null, ConnectivityChecker $connectivityChecker = null, VisibilityConverter $visibilityConverter = null, MimeTypeDetector $mimeTypeDetector = null ) { - $this->connectionOptions = $connectionOptions; $this->connectionProvider = $connectionProvider ?: new FtpConnectionProvider(); $this->connectivityChecker = $connectivityChecker ?: new NoopCommandConnectivityChecker(); $this->visibilityConverter = $visibilityConverter ?: new PortableVisibilityConverter(); From e6fbd8ba8da735f3237e1f73c881c809ed4f0ab9 Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Wed, 26 Oct 2022 20:15:09 +0200 Subject: [PATCH 3/4] 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 From e964362ba390c3e9fb916270810cc15c6c4a1abf Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Wed, 26 Oct 2022 20:30:26 +0200 Subject: [PATCH 4/4] Upgrade properties --- .../AzureBlobStorageAdapter.php | 20 ++----- src/Config.php | 8 +-- src/DirectoryAttributes.php | 39 +++---------- src/DirectoryListing.php | 8 +-- src/FileAttributes.php | 55 +++---------------- src/Filesystem.php | 12 +--- src/InMemory/InMemoryFile.php | 17 +----- src/InMemory/InMemoryFilesystemAdapter.php | 20 ++----- src/PathPrefixer.php | 14 +---- src/PathTraversalDetected.php | 5 +- src/SymbolicLinkEncountered.php | 5 +- .../PortableVisibilityConverter.php | 40 ++------------ .../FilesystemZipArchiveProvider.php | 14 +---- src/ZipArchive/StubZipArchive.php | 29 ++-------- src/ZipArchive/StubZipArchiveProvider.php | 12 +--- src/ZipArchive/ZipArchiveAdapter.php | 14 ++--- 16 files changed, 56 insertions(+), 256 deletions(-) diff --git a/src/AzureBlobStorage/AzureBlobStorageAdapter.php b/src/AzureBlobStorage/AzureBlobStorageAdapter.php index ec21b146f..7842a5879 100644 --- a/src/AzureBlobStorage/AzureBlobStorageAdapter.php +++ b/src/AzureBlobStorage/AzureBlobStorageAdapter.php @@ -56,30 +56,20 @@ class AzureBlobStorageAdapter implements FilesystemAdapter, PublicUrlGenerator, const ON_VISIBILITY_THROW_ERROR = 'throw'; const ON_VISIBILITY_IGNORE = 'ignore'; - private BlobRestProxy $client; private MimeTypeDetector $mimeTypeDetector; - private int $maxResultsForContentsListing; - private string $container; private PathPrefixer $prefixer; - private string $visibilityHandling; - private ?StorageServiceSettings $serviceSettings; public function __construct( - BlobRestProxy $client, - string $container, + private BlobRestProxy $client, + private string $container, string $prefix = '', MimeTypeDetector $mimeTypeDetector = null, - int $maxResultsForContentsListing = 5000, - string $visibilityHandling = self::ON_VISIBILITY_THROW_ERROR, - StorageServiceSettings $serviceSettings = null, + private int $maxResultsForContentsListing = 5000, + private string $visibilityHandling = self::ON_VISIBILITY_THROW_ERROR, + private ?StorageServiceSettings $serviceSettings = null, ) { - $this->client = $client; - $this->container = $container; $this->prefixer = new PathPrefixer($prefix); $this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector(); - $this->maxResultsForContentsListing = $maxResultsForContentsListing; - $this->visibilityHandling = $visibilityHandling; - $this->serviceSettings = $serviceSettings; } public function copy(string $source, string $destination, Config $config): void diff --git a/src/Config.php b/src/Config.php index 77c3b5a1d..ace07099b 100644 --- a/src/Config.php +++ b/src/Config.php @@ -11,14 +11,8 @@ class Config public const OPTION_VISIBILITY = 'visibility'; public const OPTION_DIRECTORY_VISIBILITY = 'directory_visibility'; - /** - * @var array - */ - private $options; - - public function __construct(array $options = []) + public function __construct(private array $options = []) { - $this->options = $options; } /** diff --git a/src/DirectoryAttributes.php b/src/DirectoryAttributes.php index 3eb1ced61..7841b3cc1 100644 --- a/src/DirectoryAttributes.php +++ b/src/DirectoryAttributes.php @@ -7,38 +7,15 @@ class DirectoryAttributes implements StorageAttributes { use ProxyArrayAccessToProperties; + private string $type = StorageAttributes::TYPE_DIRECTORY; - /** - * @var string - */ - private $type = StorageAttributes::TYPE_DIRECTORY; - - /** - * @var string - */ - private $path; - - /** - * @var string|null - */ - private $visibility; - - /** - * @var int|null - */ - private $lastModified; - - /** - * @var array - */ - private $extraMetadata; - - public function __construct(string $path, ?string $visibility = null, ?int $lastModified = null, array $extraMetadata = []) + public function __construct( + private string $path, + private ?string $visibility = null, + private ?int $lastModified = null, + private array $extraMetadata = []) { - $this->path = trim($path, '/'); - $this->visibility = $visibility; - $this->lastModified = $lastModified; - $this->extraMetadata = $extraMetadata; + $this->path = trim($this->path, '/'); } public function path(): string @@ -48,7 +25,7 @@ public function path(): string public function type(): string { - return StorageAttributes::TYPE_DIRECTORY; + return $this->type; } public function visibility(): ?string diff --git a/src/DirectoryListing.php b/src/DirectoryListing.php index 0f429a875..ab73a5467 100644 --- a/src/DirectoryListing.php +++ b/src/DirectoryListing.php @@ -14,17 +14,11 @@ */ class DirectoryListing implements IteratorAggregate { - /** - * @var iterable - */ - private $listing; - /** * @param iterable $listing */ - public function __construct(iterable $listing) + public function __construct(private iterable $listing) { - $this->listing = $listing; } public function filter(callable $filter): DirectoryListing diff --git a/src/FileAttributes.php b/src/FileAttributes.php index 35ccc7c1f..42172f8c4 100644 --- a/src/FileAttributes.php +++ b/src/FileAttributes.php @@ -7,56 +7,17 @@ class FileAttributes implements StorageAttributes { use ProxyArrayAccessToProperties; - - /** - * @var string - */ - private $type = StorageAttributes::TYPE_FILE; - - /** - * @var string - */ - private $path; - - /** - * @var int|null - */ - private $fileSize; - - /** - * @var string|null - */ - private $visibility; - - /** - * @var int|null - */ - private $lastModified; - - /** - * @var string|null - */ - private $mimeType; - - /** - * @var array - */ - private $extraMetadata; + private string $type = StorageAttributes::TYPE_FILE; public function __construct( - string $path, - ?int $fileSize = null, - ?string $visibility = null, - ?int $lastModified = null, - ?string $mimeType = null, - array $extraMetadata = [] + private string $path, + private ?int $fileSize = null, + private ?string $visibility = null, + private ?int $lastModified = null, + private ?string $mimeType = null, + private array $extraMetadata = [] ) { - $this->path = ltrim($path, '/'); - $this->fileSize = $fileSize; - $this->visibility = $visibility; - $this->lastModified = $lastModified; - $this->mimeType = $mimeType; - $this->extraMetadata = $extraMetadata; + $this->path = ltrim($this->path, '/'); } public function type(): string diff --git a/src/Filesystem.php b/src/Filesystem.php index 216a5f7bc..94fae15ef 100644 --- a/src/Filesystem.php +++ b/src/Filesystem.php @@ -18,24 +18,18 @@ class Filesystem implements FilesystemOperator { use CalculateChecksumFromStream; - private FilesystemAdapter $adapter; private Config $config; private PathNormalizer $pathNormalizer; - private ?PublicUrlGenerator $publicUrlGenerator; - private ?TemporaryUrlGenerator $temporaryUrlGenerator; public function __construct( - FilesystemAdapter $adapter, + private FilesystemAdapter $adapter, array $config = [], PathNormalizer $pathNormalizer = null, - PublicUrlGenerator $publicUrlGenerator = null, - TemporaryUrlGenerator $temporaryUrlGenerator = null, + private ?PublicUrlGenerator $publicUrlGenerator = null, + private ?TemporaryUrlGenerator $temporaryUrlGenerator = null, ) { - $this->adapter = $adapter; $this->config = new Config($config); $this->pathNormalizer = $pathNormalizer ?: new WhitespacePathNormalizer(); - $this->publicUrlGenerator = $publicUrlGenerator; - $this->temporaryUrlGenerator = $temporaryUrlGenerator; } public function fileExists(string $location): bool diff --git a/src/InMemory/InMemoryFile.php b/src/InMemory/InMemoryFile.php index 9e7e46b44..f9d90ac5a 100644 --- a/src/InMemory/InMemoryFile.php +++ b/src/InMemory/InMemoryFile.php @@ -12,20 +12,9 @@ */ class InMemoryFile { - /** - * @var string - */ - private $contents; - - /** - * @var int - */ - private $lastModified; - - /** - * @var string - */ - private $visibility; + private string $contents = ''; + private int $lastModified = 0; + private ?string $visibility = null; public function updateContents(string $contents, ?int $timestamp): void { diff --git a/src/InMemory/InMemoryFilesystemAdapter.php b/src/InMemory/InMemoryFilesystemAdapter.php index b744c0f48..fb6d18d23 100644 --- a/src/InMemory/InMemoryFilesystemAdapter.php +++ b/src/InMemory/InMemoryFilesystemAdapter.php @@ -28,21 +28,13 @@ class InMemoryFilesystemAdapter implements FilesystemAdapter /** * @var InMemoryFile[] */ - private $files = []; + private array $files = []; + private MimeTypeDetector $mimeTypeDetector; - /** - * @var string - */ - private $defaultVisibility; - - /** - * @var MimeTypeDetector - */ - private $mimeTypeDetector; - - public function __construct(string $defaultVisibility = Visibility::PUBLIC, MimeTypeDetector $mimeTypeDetector = null) - { - $this->defaultVisibility = $defaultVisibility; + public function __construct( + private string $defaultVisibility = Visibility::PUBLIC, + MimeTypeDetector $mimeTypeDetector = null + ) { $this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector(); } diff --git a/src/PathPrefixer.php b/src/PathPrefixer.php index 2a9cd45d0..ca4f007fc 100644 --- a/src/PathPrefixer.php +++ b/src/PathPrefixer.php @@ -10,25 +10,15 @@ final class PathPrefixer { - /** - * @var string - */ - private $prefix = ''; + private string $prefix = ''; - /** - * @var string - */ - private $separator = '/'; - - public function __construct(string $prefix, string $separator = '/') + public function __construct(string $prefix, private string $separator = '/') { $this->prefix = rtrim($prefix, '\\/'); if ($this->prefix !== '' || $prefix === $separator) { $this->prefix .= $separator; } - - $this->separator = $separator; } public function prefixPath(string $path): string diff --git a/src/PathTraversalDetected.php b/src/PathTraversalDetected.php index d149997f7..fef3edf18 100644 --- a/src/PathTraversalDetected.php +++ b/src/PathTraversalDetected.php @@ -8,10 +8,7 @@ class PathTraversalDetected extends RuntimeException implements FilesystemException { - /** - * @var string - */ - private $path; + private string $path; public function path(): string { diff --git a/src/SymbolicLinkEncountered.php b/src/SymbolicLinkEncountered.php index 8091f5904..e4e0a5334 100644 --- a/src/SymbolicLinkEncountered.php +++ b/src/SymbolicLinkEncountered.php @@ -8,10 +8,7 @@ final class SymbolicLinkEncountered extends RuntimeException implements FilesystemException { - /** - * @var string - */ - private $location; + private string $location; public function location(): string { diff --git a/src/UnixVisibility/PortableVisibilityConverter.php b/src/UnixVisibility/PortableVisibilityConverter.php index 5cc1eb232..117b4d966 100644 --- a/src/UnixVisibility/PortableVisibilityConverter.php +++ b/src/UnixVisibility/PortableVisibilityConverter.php @@ -9,43 +9,13 @@ class PortableVisibilityConverter implements VisibilityConverter { - /** - * @var int - */ - private $filePublic; - - /** - * @var int - */ - private $filePrivate; - - /** - * @var int - */ - private $directoryPublic; - - /** - * @var int - */ - private $directoryPrivate; - - /** - * @var string - */ - private $defaultForDirectories; - public function __construct( - int $filePublic = 0644, - int $filePrivate = 0600, - int $directoryPublic = 0755, - int $directoryPrivate = 0700, - string $defaultForDirectories = Visibility::PRIVATE + private int $filePublic = 0644, + private int $filePrivate = 0600, + private int $directoryPublic = 0755, + private int $directoryPrivate = 0700, + private string $defaultForDirectories = Visibility::PRIVATE ) { - $this->filePublic = $filePublic; - $this->filePrivate = $filePrivate; - $this->directoryPublic = $directoryPublic; - $this->directoryPrivate = $directoryPrivate; - $this->defaultForDirectories = $defaultForDirectories; } public function forFile(string $visibility): int diff --git a/src/ZipArchive/FilesystemZipArchiveProvider.php b/src/ZipArchive/FilesystemZipArchiveProvider.php index 93da27cac..1ceb51516 100644 --- a/src/ZipArchive/FilesystemZipArchiveProvider.php +++ b/src/ZipArchive/FilesystemZipArchiveProvider.php @@ -8,25 +8,13 @@ class FilesystemZipArchiveProvider implements ZipArchiveProvider { - /** - * @var string - */ - private $filename; - - /** - * @var int - */ - private $localDirectoryPermissions; - /** * @var bool */ private $parentDirectoryCreated = false; - public function __construct(string $filename, int $localDirectoryPermissions = 0700) + public function __construct(private string $filename, private int $localDirectoryPermissions = 0700) { - $this->filename = $filename; - $this->localDirectoryPermissions = $localDirectoryPermissions; } public function createZipArchive(): ZipArchive diff --git a/src/ZipArchive/StubZipArchive.php b/src/ZipArchive/StubZipArchive.php index 28670ee3d..5fb6ec2f2 100644 --- a/src/ZipArchive/StubZipArchive.php +++ b/src/ZipArchive/StubZipArchive.php @@ -8,30 +8,11 @@ class StubZipArchive extends ZipArchive { - /** - * @var bool - */ - private $failNextDirectoryCreation = false; - - /** - * @var bool - */ - private $failNextWrite = false; - - /** - * @var bool - */ - private $failNextDeleteName = false; - - /** - * @var bool - */ - private $failWhenSettingVisibility = false; - - /** - * @var bool - */ - private $failWhenDeletingAnIndex = false; + private bool $failNextDirectoryCreation = false; + private bool $failNextWrite = false; + private bool $failNextDeleteName = false; + private bool $failWhenSettingVisibility = false; + private bool $failWhenDeletingAnIndex = false; public function failNextDirectoryCreation(): void { diff --git a/src/ZipArchive/StubZipArchiveProvider.php b/src/ZipArchive/StubZipArchiveProvider.php index 914e0438d..a8e8f68f4 100644 --- a/src/ZipArchive/StubZipArchiveProvider.php +++ b/src/ZipArchive/StubZipArchiveProvider.php @@ -8,25 +8,17 @@ class StubZipArchiveProvider implements ZipArchiveProvider { - /** - * @var FilesystemZipArchiveProvider - */ - private $provider; + private FilesystemZipArchiveProvider $provider; - /** - * @var string - */ - private $filename; /** * @var StubZipArchive */ private $archive; - public function __construct(string $filename, int $localDirectoryPermissions = 0700) + public function __construct(private string $filename, int $localDirectoryPermissions = 0700) { $this->provider = new FilesystemZipArchiveProvider($filename, $localDirectoryPermissions); - $this->filename = $filename; } public function createZipArchive(): ZipArchive diff --git a/src/ZipArchive/ZipArchiveAdapter.php b/src/ZipArchive/ZipArchiveAdapter.php index 9b0ba0bf3..3c3b4db5d 100644 --- a/src/ZipArchive/ZipArchiveAdapter.php +++ b/src/ZipArchive/ZipArchiveAdapter.php @@ -33,17 +33,12 @@ final class ZipArchiveAdapter implements FilesystemAdapter { - /** @var PathPrefixer */ - private $pathPrefixer; - /** @var MimeTypeDetector */ - private $mimeTypeDetector; - /** @var VisibilityConverter */ - private $visibility; - /** @var ZipArchiveProvider */ - private $zipArchiveProvider; + private PathPrefixer $pathPrefixer; + private MimeTypeDetector$mimeTypeDetector; + private VisibilityConverter $visibility; public function __construct( - ZipArchiveProvider $zipArchiveProvider, + private ZipArchiveProvider $zipArchiveProvider, string $root = '', ?MimeTypeDetector $mimeTypeDetector = null, ?VisibilityConverter $visibility = null @@ -51,7 +46,6 @@ public function __construct( $this->pathPrefixer = new PathPrefixer(ltrim($root, '/')); $this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector(); $this->visibility = $visibility ?? new PortableVisibilityConverter(); - $this->zipArchiveProvider = $zipArchiveProvider; } public function fileExists(string $path): bool