Skip to content

Commit 8e41ddb

Browse files
authored
Merge pull request #118 from kbond/phpstan-improvements
PHPStan improvements
2 parents db758f6 + e3601d0 commit 8e41ddb

30 files changed

+74
-73
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"league/flysystem-ziparchive": "^3.12",
3030
"league/glide": "^2.2",
3131
"league/mime-type-detection": ">=1.8",
32-
"phpstan/phpstan": "^1.4",
32+
"phpstan/phpstan": "^2.0",
3333
"phpunit/phpunit": "^9.6.18",
3434
"srwiez/thumbhash": "^1.2",
3535
"symfony/browser-kit": "^6.4|^7.0",

src/Filesystem/Attribute/PendingUploadedFile.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020

2121
/**
2222
* @author Jakub Caban <kuba.iluvatar@gmail.com>
23-
*
24-
* @phpstan-consistent-constructor
25-
* @readonly
2623
*/
2724
#[\Attribute(\Attribute::TARGET_PARAMETER | \Attribute::TARGET_PROPERTY)]
2825
class PendingUploadedFile
@@ -48,7 +45,7 @@ public static function forArgument(ArgumentMetadata $argument): self
4845
$attribute = $attributes[0];
4946
\assert($attribute instanceof self);
5047
} else {
51-
$attribute = new static();
48+
$attribute = new self();
5249
}
5350

5451
$attribute->path ??= $argument->getName();

src/Filesystem/Doctrine/Mapping/Stateless.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public function __construct(string $filesystem, string|Namer $namer)
2727

2828
public function filesystem(): string
2929
{
30-
return parent::filesystem(); // @phpstan-ignore-line
30+
return parent::filesystem(); // @phpstan-ignore return.type
3131
}
3232

3333
public function namer(): Namer
3434
{
35-
return parent::namer(); // @phpstan-ignore-line
35+
return parent::namer(); // @phpstan-ignore return.type
3636
}
3737
}

src/Filesystem/Doctrine/Mapping/StoreAsPath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public function __construct(
3131

3232
public function filesystem(): string
3333
{
34-
return parent::filesystem(); // @phpstan-ignore-line
34+
return parent::filesystem(); // @phpstan-ignore return.type
3535
}
3636
}

src/Filesystem/Doctrine/Types/JsonType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
5454
throw InvalidType::new($value, SerializableFile::class, [SerializableFile::class, 'null']);
5555
}
5656

57-
throw ConversionException::conversionFailedInvalidType($value, SerializableFile::class, [SerializableFile::class, 'null']); // @phpstan-ignore-line
57+
throw ConversionException::conversionFailedInvalidType($value, SerializableFile::class, [SerializableFile::class, 'null']); // @phpstan-ignore staticMethod.notFound
5858
}
5959

6060
public function convertToPHPValue($value, AbstractPlatform $platform): ?LazyFile
@@ -72,7 +72,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?LazyFile
7272
throw InvalidType::new($value, File::class, ['array', 'null']);
7373
}
7474

75-
throw ConversionException::conversionFailedFormat($value, File::class, 'array|null'); // @phpstan-ignore-line
75+
throw ConversionException::conversionFailedFormat($value, File::class, 'array|null'); // @phpstan-ignore staticMethod.notFound
7676
}
7777

7878
final public function requiresSQLCommentHint(AbstractPlatform $platform): bool

src/Filesystem/Doctrine/Types/StringType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final public function convertToDatabaseValue($value, AbstractPlatform $platform)
4545
throw InvalidType::new($value, File::class, [File::class, 'null']);
4646
}
4747

48-
throw ConversionException::conversionFailedInvalidType($value, File::class, [File::class, 'null']); // @phpstan-ignore-line
48+
throw ConversionException::conversionFailedInvalidType($value, File::class, [File::class, 'null']); // @phpstan-ignore staticMethod.notFound
4949
}
5050

5151
final public function convertToPHPValue($value, AbstractPlatform $platform): ?LazyFile

src/Filesystem/Flysystem/AdapterFactory.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private static function createRealAdapter(string $dsn): FilesystemAdapter
6767
};
6868
}
6969

70-
private static function createLocalAdapter(string $dsn, array $parsed): LocalFilesystemAdapter // @phpstan-ignore-line
70+
private static function createLocalAdapter(string $dsn, array $parsed): LocalFilesystemAdapter // @phpstan-ignore missingType.iterableValue
7171
{
7272
$parsed = self::normalizeQuery($parsed);
7373
$visibility = $parsed['query']['visibility'] ?? [];
@@ -81,7 +81,7 @@ private static function createLocalAdapter(string $dsn, array $parsed): LocalFil
8181
);
8282
}
8383

84-
private static function parse(string $dsn): array // @phpstan-ignore-line
84+
private static function parse(string $dsn): array // @phpstan-ignore missingType.iterableValue
8585
{
8686
$parsed = \parse_url($dsn);
8787

@@ -105,7 +105,7 @@ private static function parse(string $dsn): array // @phpstan-ignore-line
105105
return $parsed;
106106
}
107107

108-
private static function normalizeQuery(array $parts): array // @phpstan-ignore-line
108+
private static function normalizeQuery(array $parts): array // @phpstan-ignore missingType.iterableValue, missingType.iterableValue
109109
{
110110
$query = [];
111111

@@ -116,7 +116,7 @@ private static function normalizeQuery(array $parts): array // @phpstan-ignore-l
116116
return $parts;
117117
}
118118

119-
private static function createInMemoryAdapter(array $parsed): InMemoryFilesystemAdapter // @phpstan-ignore-line
119+
private static function createInMemoryAdapter(array $parsed): InMemoryFilesystemAdapter // @phpstan-ignore missingType.iterableValue
120120
{
121121
if ($name = $parsed['path'] ?? null) {
122122
return StaticInMemoryAdapterRegistry::get($name);
@@ -125,7 +125,7 @@ private static function createInMemoryAdapter(array $parsed): InMemoryFilesystem
125125
return new InMemoryFilesystemAdapter();
126126
}
127127

128-
private static function createSftpAdapter(array $parsed): FilesystemAdapter // @phpstan-ignore-line
128+
private static function createSftpAdapter(array $parsed): FilesystemAdapter // @phpstan-ignore missingType.iterableValue
129129
{
130130
if (!\class_exists(SftpAdapter::class)) {
131131
throw new \LogicException('league/flysystem-sftp-v3 is required to use the SFTP adapter. Install with "composer require league/flysystem-sftp-v3".');
@@ -146,7 +146,7 @@ private static function createSftpAdapter(array $parsed): FilesystemAdapter // @
146146
);
147147
}
148148

149-
private static function createFtpAdapter(array $parsed): FilesystemAdapter // @phpstan-ignore-line
149+
private static function createFtpAdapter(array $parsed): FilesystemAdapter // @phpstan-ignore missingType.iterableValue
150150
{
151151
if (!\class_exists(FtpAdapter::class)) {
152152
throw new \LogicException('league/flysystem-ftp is required to use the FTP adapter. Install with "composer require league/flysystem-ftp".');
@@ -164,7 +164,7 @@ private static function createFtpAdapter(array $parsed): FilesystemAdapter // @p
164164
])));
165165
}
166166

167-
private static function createS3Adapter(array $parsed): FilesystemAdapter // @phpstan-ignore-line
167+
private static function createS3Adapter(array $parsed): FilesystemAdapter // @phpstan-ignore missingType.iterableValue
168168
{
169169
$parsed = self::normalizeQuery($parsed);
170170

@@ -181,8 +181,8 @@ private static function createS3Adapter(array $parsed): FilesystemAdapter // @ph
181181
}
182182

183183
if (\class_exists(AwsS3V3Adapter::class)) {
184-
return new AwsS3V3Adapter( // @phpstan-ignore-line
185-
new S3Client([ // @phpstan-ignore-line
184+
return new AwsS3V3Adapter( // @phpstan-ignore return.type
185+
new S3Client([ // @phpstan-ignore class.notFound
186186
'region' => $parsed['query']['region'] ?? $parsed['fragment'] ?? throw new \InvalidArgumentException('A region must be set in the query (ie ?region=us-east-1) or as the fragment (ie #us-east-1).'),
187187
'credentials' => [
188188
'key' => $parsed['user'] ?? null,

src/Filesystem/Flysystem/Operator.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function name(): string
5151
return $this->name;
5252
}
5353

54-
public function publicUrl(string $path, array $config = []): string // @phpstan-ignore-line
54+
public function publicUrl(string $path, array $config = []): string // @phpstan-ignore missingType.iterableValue
5555
{
5656
try {
5757
return $this->feature(PublicUrlGenerator::class)->publicUrl($path, new Config($config));
@@ -60,7 +60,7 @@ public function publicUrl(string $path, array $config = []): string // @phpstan-
6060
}
6161
}
6262

63-
public function temporaryUrl(string $path, \DateTimeInterface $expiresAt, array $config = []): string // @phpstan-ignore-line
63+
public function temporaryUrl(string $path, \DateTimeInterface $expiresAt, array $config = []): string // @phpstan-ignore missingType.iterableValue
6464
{
6565
try {
6666
return $this->feature(TemporaryUrlGenerator::class)->temporaryUrl($path, $expiresAt, new Config($config));
@@ -69,7 +69,7 @@ public function temporaryUrl(string $path, \DateTimeInterface $expiresAt, array
6969
}
7070
}
7171

72-
public function checksum(string $path, array $config = []): string // @phpstan-ignore-line
72+
public function checksum(string $path, array $config = []): string // @phpstan-ignore missingType.iterableValue
7373
{
7474
return $this->inner->checksum($path, $config);
7575
}
@@ -124,12 +124,12 @@ public function visibility(string $path): string
124124
return $this->inner->visibility($path);
125125
}
126126

127-
public function write(string $location, string $contents, array $config = []): void // @phpstan-ignore-line
127+
public function write(string $location, string $contents, array $config = []): void // @phpstan-ignore missingType.iterableValue
128128
{
129129
$this->inner->write($location, $contents, $config);
130130
}
131131

132-
public function writeStream(string $location, $contents, array $config = []): void // @phpstan-ignore-line
132+
public function writeStream(string $location, $contents, array $config = []): void // @phpstan-ignore missingType.iterableValue
133133
{
134134
$this->inner->writeStream($location, $contents, $config);
135135
}
@@ -149,17 +149,17 @@ public function deleteDirectory(string $location): void
149149
$this->inner->deleteDirectory($location);
150150
}
151151

152-
public function createDirectory(string $location, array $config = []): void // @phpstan-ignore-line
152+
public function createDirectory(string $location, array $config = []): void // @phpstan-ignore missingType.iterableValue
153153
{
154154
$this->inner->createDirectory($location, $config);
155155
}
156156

157-
public function move(string $source, string $destination, array $config = []): void // @phpstan-ignore-line
157+
public function move(string $source, string $destination, array $config = []): void // @phpstan-ignore missingType.iterableValue
158158
{
159159
$this->inner->move($source, $destination, $config);
160160
}
161161

162-
public function copy(string $source, string $destination, array $config = []): void // @phpstan-ignore-line
162+
public function copy(string $source, string $destination, array $config = []): void // @phpstan-ignore missingType.iterableValue
163163
{
164164
$this->inner->copy($source, $destination, $config);
165165
}
@@ -183,7 +183,7 @@ private function feature(string $feature): object
183183
}
184184

185185
if (\is_array($this->features) && isset($this->features[$feature])) {
186-
return $this->features[$feature]; // @phpstan-ignore-line
186+
return $this->features[$feature]; // @phpstan-ignore return.type
187187
}
188188

189189
throw new UnsupportedFeature($feature, $this->name(), $e ?? null);

src/Filesystem/FlysystemFilesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function mkdir(string $path, Directory|\SplFileInfo|null $content = null,
142142
$progress = $config['progress'] ?? static fn() => null;
143143

144144
foreach ($content->files() as $file) {
145-
$file = $this->write($prefixer->prefixPath(\mb_substr($file->path(), $prefixLength)), $file, $config); // @phpstan-ignore-line
145+
$file = $this->write($prefixer->prefixPath(\mb_substr($file->path(), $prefixLength)), $file, $config); // @phpstan-ignore argument.type
146146
$progress($file);
147147
}
148148

src/Filesystem/Glide/GlideTransformUrlGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function transformUrl(string $path, array|string $filter, Config $config)
2828
{
2929
$filter = match (true) {
3030
\is_string($filter) => ['p' => $filter], // is glide "preset"
31-
\is_array($filter) && !\array_is_list($filter) => $filter, // is standard glide parameters
32-
\is_array($filter) => ['p' => \implode(',', $filter)], // is array of "presets"
31+
!\array_is_list($filter) => $filter, // is standard glide parameters
32+
default => ['p' => \implode(',', $filter)], // is array of "presets"
3333
};
3434

3535
return $this->urlBuilder->getUrl($path, $filter);

0 commit comments

Comments
 (0)