Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PhpStan test #2910

Merged
merged 1 commit into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ phpunit.xml
.phpunit.result.cache
.php-cs-fixer.cache
phpstan.neon
tests/Support/temp/
79 changes: 2 additions & 77 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,6 @@ parameters:
count: 1
path: src/Conversions/Commands/RegenerateCommand.php

-
message: "#^Parameter \\#1 \\$modelType of method Spatie\\\\MediaLibrary\\\\MediaCollections\\\\MediaRepository\\:\\:getByModelType\\(\\) expects string, array\\|string given\\.$#"
count: 1
path: src/Conversions/Commands/RegenerateCommand.php

-
message: "#^Parameter \\#2 \\$excludeStartingId of method Spatie\\\\MediaLibrary\\\\MediaCollections\\\\MediaRepository\\:\\:getByIdGreaterThan\\(\\) expects bool, array\\|bool\\|string given\\.$#"
count: 1
path: src/Conversions/Commands/RegenerateCommand.php

-
message: "#^Parameter \\#2 \\$string of function explode expects string, bool\\|string\\|null given\\.$#"
count: 1
path: src/Conversions/Commands/RegenerateCommand.php

-
message: "#^Parameter \\#3 \\$modelType of method Spatie\\\\MediaLibrary\\\\MediaCollections\\\\MediaRepository\\:\\:getByIdGreaterThan\\(\\) expects string, array\\|string given\\.$#"
count: 1
path: src/Conversions/Commands/RegenerateCommand.php

-
message: "#^Parameter \\#3 \\$onlyMissing of method Spatie\\\\MediaLibrary\\\\Conversions\\\\FileManipulator\\:\\:createDerivedFiles\\(\\) expects bool, array\\|bool\\|string\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -275,11 +255,6 @@ parameters:
count: 1
path: src/Conversions/ImageGenerators/ImageGeneratorFactory.php

-
message: "#^Unable to resolve the template type TMapValue in call to method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:map\\(\\)$#"
count: 1
path: src/Conversions/ImageGenerators/ImageGeneratorFactory.php

-
message: "#^Unable to resolve the template type TValue in call to function collect$#"
count: 1
Expand Down Expand Up @@ -465,11 +440,6 @@ parameters:
count: 1
path: src/MediaCollections/Commands/CleanCommand.php

-
message: "#^Parameter \\#1 \\$collectionName of method Spatie\\\\MediaLibrary\\\\MediaCollections\\\\MediaRepository\\:\\:getByCollectionName\\(\\) expects string, array\\|string given\\.$#"
count: 1
path: src/MediaCollections/Commands/CleanCommand.php

-
message: "#^Parameter \\#1 \\$microseconds of function usleep expects int, float\\|int\\<min, \\-1000000\\>\\|int\\<1000000, max\\> given\\.$#"
count: 1
Expand All @@ -480,21 +450,6 @@ parameters:
count: 1
path: src/MediaCollections/Commands/CleanCommand.php

-
message: "#^Parameter \\#1 \\$modelType of method Spatie\\\\MediaLibrary\\\\MediaCollections\\\\MediaRepository\\:\\:getByModelType\\(\\) expects string, array\\|string given\\.$#"
count: 1
path: src/MediaCollections/Commands/CleanCommand.php

-
message: "#^Parameter \\#1 \\$modelType of method Spatie\\\\MediaLibrary\\\\MediaCollections\\\\MediaRepository\\:\\:getByModelTypeAndCollectionName\\(\\) expects string, array\\|string given\\.$#"
count: 1
path: src/MediaCollections/Commands/CleanCommand.php

-
message: "#^Parameter \\#2 \\$collectionName of method Spatie\\\\MediaLibrary\\\\MediaCollections\\\\MediaRepository\\:\\:getByModelTypeAndCollectionName\\(\\) expects string, array\\|string given\\.$#"
count: 1
path: src/MediaCollections/Commands/CleanCommand.php

-
message: "#^Property Spatie\\\\MediaLibrary\\\\MediaCollections\\\\Commands\\\\CleanCommand\\:\\:\\$isDryRun \\(bool\\) does not accept array\\|bool\\|string\\|null\\.$#"
count: 1
Expand All @@ -505,26 +460,6 @@ parameters:
count: 1
path: src/MediaCollections/Commands/ClearCommand.php

-
message: "#^Parameter \\#1 \\$collectionName of method Spatie\\\\MediaLibrary\\\\MediaCollections\\\\MediaRepository\\:\\:getByCollectionName\\(\\) expects string, array\\|string given\\.$#"
count: 1
path: src/MediaCollections/Commands/ClearCommand.php

-
message: "#^Parameter \\#1 \\$modelType of method Spatie\\\\MediaLibrary\\\\MediaCollections\\\\MediaRepository\\:\\:getByModelType\\(\\) expects string, array\\|string given\\.$#"
count: 1
path: src/MediaCollections/Commands/ClearCommand.php

-
message: "#^Parameter \\#1 \\$modelType of method Spatie\\\\MediaLibrary\\\\MediaCollections\\\\MediaRepository\\:\\:getByModelTypeAndCollectionName\\(\\) expects string, array\\|string given\\.$#"
count: 1
path: src/MediaCollections/Commands/ClearCommand.php

-
message: "#^Parameter \\#2 \\$collectionName of method Spatie\\\\MediaLibrary\\\\MediaCollections\\\\MediaRepository\\:\\:getByModelTypeAndCollectionName\\(\\) expects string, array\\|string given\\.$#"
count: 1
path: src/MediaCollections/Commands/ClearCommand.php

-
message: "#^Method Spatie\\\\MediaLibrary\\\\MediaCollections\\\\Contracts\\\\MediaLibraryRequest\\:\\:mediaLibraryRequestItems\\(\\) return type with generic class Illuminate\\\\Support\\\\Collection does not specify its types\\: TKey, TValue$#"
count: 1
Expand Down Expand Up @@ -1230,11 +1165,6 @@ parameters:
count: 1
path: src/MediaCollections/Models/Media.php

-
message: "#^Access to an undefined property Spatie\\\\MediaLibrary\\\\MediaCollections\\\\Models\\\\Media\\:\\:\\$conversions_disk\\.$#"
count: 1
path: src/MediaCollections/Models/Media.php

-
message: "#^Access to an undefined property Spatie\\\\MediaLibrary\\\\MediaCollections\\\\Models\\\\Media\\:\\:\\$custom_properties\\.$#"
count: 7
Expand All @@ -1252,7 +1182,7 @@ parameters:

-
message: "#^Access to an undefined property Spatie\\\\MediaLibrary\\\\MediaCollections\\\\Models\\\\Media\\:\\:\\$generated_conversions\\.$#"
count: 5
count: 4
path: src/MediaCollections/Models/Media.php

-
Expand Down Expand Up @@ -1285,11 +1215,6 @@ parameters:
count: 2
path: src/MediaCollections/Models/Media.php

-
message: "#^Access to an undefined property Spatie\\\\MediaLibrary\\\\MediaCollections\\\\Models\\\\Media\\:\\:\\$sortable\\.$#"
count: 2
path: src/MediaCollections/Models/Media.php

-
message: "#^Cannot call method determineOrderColumnName\\(\\) on Illuminate\\\\Database\\\\Eloquent\\\\Collection\\<int, Spatie\\\\MediaLibrary\\\\MediaCollections\\\\Models\\\\Media\\>\\|Spatie\\\\MediaLibrary\\\\MediaCollections\\\\Models\\\\Media\\|null\\.$#"
count: 1
Expand Down Expand Up @@ -1557,7 +1482,7 @@ parameters:

-
message: "#^Access to an undefined property Spatie\\\\MediaLibrary\\\\MediaCollections\\\\Models\\\\Media\\:\\:\\$responsive_images\\.$#"
count: 4
count: 2
path: src/ResponsiveImages/RegisteredResponsiveImages.php

-
Expand Down
12 changes: 6 additions & 6 deletions src/Conversions/Commands/RegenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ public function handle(MediaRepository $mediaRepository, FileManipulator $fileMa
public function getMediaToBeRegenerated(): Collection
{
// Get this arg first as it can also be passed to the greater-than-id branch
$modelType = $this->argument('modelType') ?? '';
$modelType = $this->argument('modelType');

$startingFromId = (int)$this->option('starting-from-id');
if ($startingFromId !== 0) {
$excludeStartingId = $this->option('exclude-starting-id') ?? false;
$excludeStartingId = (bool) $this->option('exclude-starting-id') ?: false;

return $this->mediaRepository->getByIdGreaterThan($startingFromId, $excludeStartingId, $modelType);
return $this->mediaRepository->getByIdGreaterThan($startingFromId, $excludeStartingId, is_string($modelType) ? $modelType : '');
}

if ($modelType !== '') {
if (is_string($modelType)) {
return $this->mediaRepository->getByModelType($modelType);
}

Expand All @@ -103,11 +103,11 @@ protected function getMediaIds(): array
$mediaIds = $this->option('ids');

if (! is_array($mediaIds)) {
$mediaIds = explode(',', $mediaIds);
$mediaIds = explode(',', (string) $mediaIds);
}

if (count($mediaIds) === 1 && Str::contains($mediaIds[0], ',')) {
$mediaIds = explode(',', $mediaIds[0]);
$mediaIds = explode(',', (string) $mediaIds[0]);
}

return $mediaIds;
Expand Down
6 changes: 3 additions & 3 deletions src/MediaCollections/Commands/CleanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ public function getMediaItems(): Collection
$modelType = $this->argument('modelType');
$collectionName = $this->argument('collectionName');

if (! is_null($modelType) && ! is_null($collectionName)) {
if (is_string($modelType) && is_string($collectionName)) {
return $this->mediaRepository->getByModelTypeAndCollectionName(
$modelType,
$collectionName
);
}

if (! is_null($modelType)) {
if (is_string($modelType)) {
return $this->mediaRepository->getByModelType($modelType);
}

if (! is_null($collectionName)) {
if (is_string($collectionName)) {
return $this->mediaRepository->getByCollectionName($collectionName);
}

Expand Down
6 changes: 3 additions & 3 deletions src/MediaCollections/Commands/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ public function getMediaItems(): Collection
$modelType = $this->argument('modelType');
$collectionName = $this->argument('collectionName');

if (! is_null($modelType) && ! is_null($collectionName)) {
if (is_string($modelType) && is_string($collectionName)) {
return $this->mediaRepository->getByModelTypeAndCollectionName(
$modelType,
$collectionName
);
}

if (! is_null($modelType)) {
if (is_string($modelType)) {
return $this->mediaRepository->getByModelType($modelType);
}

if (! is_null($collectionName)) {
if (is_string($collectionName)) {
return $this->mediaRepository->getByCollectionName($collectionName);
}

Expand Down