Skip to content

Commit

Permalink
24-increase-phpstan-level-to-10
Browse files Browse the repository at this point in the history
  • Loading branch information
jgivoni committed Feb 12, 2025
1 parent 9cc9e95 commit b3b7d6b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
6 changes: 6 additions & 0 deletions aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Source this file with `. ./aliases` to use the following shortcuts when developing:
alias d='docker compose exec -it php "$@"'
alias php='d php "$@"'
alias composer='d composer "$@"'
alias phpstan='d vendor/bin/phpstan analyze "$@"'
alias phpunit='d vendor/bin/phpunit "$@"'
2 changes: 0 additions & 2 deletions composer.sh

This file was deleted.

8 changes: 1 addition & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
parameters:
level: 9
level: 10

paths:
- src
- tests

# ignoreErrors:
# - "/no value type specified in iterable type array\\.$/"
# - "/is always (true|false)\\.$/"

reportUnmatchedIgnoredErrors: false
2 changes: 0 additions & 2 deletions phpstan.sh

This file was deleted.

2 changes: 0 additions & 2 deletions phpunit.sh

This file was deleted.

36 changes: 21 additions & 15 deletions src/CacheAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ public function visibility(string $path): FileAttributes
try {
return $this->getFileAttributes(
path: $path,
loader: function () use ($path) {
loader: function () use ($path): FileAttributes {
return $this->adapter->visibility($path);
},
attributeAccessor: function (FileAttributes $fileAttributes) {
attributeAccessor: function (FileAttributes $fileAttributes): ?string {
return $fileAttributes->visibility();
},
);
Expand All @@ -266,10 +266,10 @@ public function mimeType(string $path): FileAttributes
try {
return $this->getFileAttributes(
path: $path,
loader: function () use ($path) {
loader: function () use ($path): FileAttributes {
return $this->adapter->mimeType($path);
},
attributeAccessor: function (FileAttributes $fileAttributes) {
attributeAccessor: function (FileAttributes $fileAttributes): ?string {
return $fileAttributes->mimeType();
},
);
Expand All @@ -286,10 +286,10 @@ public function lastModified(string $path): FileAttributes
try {
return $this->getFileAttributes(
path: $path,
loader: function () use ($path) {
loader: function () use ($path): FileAttributes {
return $this->adapter->lastModified($path);
},
attributeAccessor: function (FileAttributes $fileAttributes) {
attributeAccessor: function (FileAttributes $fileAttributes): ?int {
return $fileAttributes->lastModified();
},
);
Expand All @@ -306,10 +306,10 @@ public function fileSize(string $path): FileAttributes
try {
return $this->getFileAttributes(
path: $path,
loader: function () use ($path) {
loader: function () use ($path): FileAttributes {
return $this->adapter->fileSize($path);
},
attributeAccessor: function (FileAttributes $fileAttributes) {
attributeAccessor: function (FileAttributes $fileAttributes): ?int {
return $fileAttributes->fileSize();
},
);
Expand All @@ -331,22 +331,28 @@ public function checksum(string $path, Config $config): string

$metadataKey = isset($algo) ? 'checksum_' . $algo : 'checksum';

$attributeAccessor = function (StorageAttributes $storageAttributes) use ($metadataKey) {
$attributeAccessor = function (StorageAttributes $storageAttributes) use ($metadataKey): ?string {
if (\is_a($this->adapter, 'League\Flysystem\AwsS3V3\AwsS3V3Adapter')) {
// Special optimization for AWS S3, but won't break if adapter not installed
$etag = $storageAttributes->extraMetadata()['ETag'] ?? \null;
if (isset($etag)) {
$checksum = trim($etag, '" ');
if (is_string($etag)) {
return trim($etag, '" ');
}
}

return $checksum ?? $storageAttributes->extraMetadata()[$metadataKey] ?? \null;
$checksum = $storageAttributes->extraMetadata()[$metadataKey] ?? \null;

if (isset($checksum) && !is_string($checksum)) {
throw new RuntimeException('Checksum must be a string.');
}

return $checksum;
};

try {
$fileAttributes = $this->getFileAttributes(
path: $path,
loader: function () use ($path, $config, $metadataKey) {
loader: function () use ($path, $config, $metadataKey): FileAttributes {
// This part is "mirrored" from FileSystem class to provide the fallback mechanism
// and be able to cache the result
try {
Expand All @@ -363,11 +369,11 @@ public function checksum(string $path, Config $config): string
},
attributeAccessor: $attributeAccessor
);

return $attributeAccessor($fileAttributes) ?? '';
} catch (RuntimeException $e) {
throw new UnableToProvideChecksum($e->getMessage(), $path, $e);
}

return $attributeAccessor($fileAttributes);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/CacheItemsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ protected static function mergeDirectoryAttributes(
* Returns FileAttributes from cache if desired attribute is found,
* or loads the desired missing attribute from the adapter and merges it with the cached attributes.
*
* @param Closure $loader Returns FileAttributes with the desired attribute loaded from adapter
* @param Closure $attributeAccessor Returns value of desired attribute from cached item
* @param Closure(): FileAttributes $loader Returns FileAttributes with the desired attribute loaded from adapter
* @param Closure(FileAttributes): mixed $attributeAccessor Returns value of desired attribute from cached item
*/
protected function getFileAttributes(
string $path,
Expand Down

0 comments on commit b3b7d6b

Please sign in to comment.