Skip to content

Commit

Permalink
Merge pull request thephpleague#1582 from thephpleague/codeops/modern…
Browse files Browse the repository at this point in the history
…-property-types

[CODE-OPS] modern property types
  • Loading branch information
frankdejonge authored Oct 26, 2022
2 parents b9bd194 + e964362 commit fde17dd
Show file tree
Hide file tree
Showing 30 changed files with 132 additions and 705 deletions.
33 changes: 5 additions & 28 deletions src/AsyncAwsS3/AsyncAwsS3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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;
Expand Down
73 changes: 10 additions & 63 deletions src/AwsS3V3/AwsS3V3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/AwsS3V3/PortableVisibilityConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 5 additions & 15 deletions src/AzureBlobStorage/AzureBlobStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
39 changes: 8 additions & 31 deletions src/DirectoryAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,7 +25,7 @@ public function path(): string

public function type(): string
{
return StorageAttributes::TYPE_DIRECTORY;
return $this->type;
}

public function visibility(): ?string
Expand Down
8 changes: 1 addition & 7 deletions src/DirectoryListing.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@
*/
class DirectoryListing implements IteratorAggregate
{
/**
* @var iterable<T>
*/
private $listing;

/**
* @param iterable<T> $listing
*/
public function __construct(iterable $listing)
public function __construct(private iterable $listing)
{
$this->listing = $listing;
}

public function filter(callable $filter): DirectoryListing
Expand Down
55 changes: 8 additions & 47 deletions src/FileAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions src/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions src/Ftp/ConnectivityCheckerThatCanFail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit fde17dd

Please sign in to comment.