Skip to content

Commit

Permalink
Upgrade properties
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Oct 26, 2022
1 parent e6fbd8b commit e964362
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 256 deletions.
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
17 changes: 3 additions & 14 deletions src/InMemory/InMemoryFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
20 changes: 6 additions & 14 deletions src/InMemory/InMemoryFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
14 changes: 2 additions & 12 deletions src/PathPrefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/PathTraversalDetected.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class PathTraversalDetected extends RuntimeException implements FilesystemException
{
/**
* @var string
*/
private $path;
private string $path;

public function path(): string
{
Expand Down
5 changes: 1 addition & 4 deletions src/SymbolicLinkEncountered.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

final class SymbolicLinkEncountered extends RuntimeException implements FilesystemException
{
/**
* @var string
*/
private $location;
private string $location;

public function location(): string
{
Expand Down
40 changes: 5 additions & 35 deletions src/UnixVisibility/PortableVisibilityConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 1 addition & 13 deletions src/ZipArchive/FilesystemZipArchiveProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit e964362

Please sign in to comment.