Skip to content

Commit

Permalink
Add missing return types (#3622)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman authored Jun 4, 2024
1 parent db82891 commit 1272f88
Show file tree
Hide file tree
Showing 21 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/Conversions/Actions/PerformConversionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function execute(
Conversion $conversion,
Media $media,
string $copiedOriginalFile
) {
): void {
$imageGenerator = ImageGeneratorFactory::forMedia($media);

$copiedOriginalFile = $imageGenerator->convert($copiedOriginalFile, $conversion);
Expand Down
2 changes: 1 addition & 1 deletion src/Conversions/Commands/RegenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RegenerateCommand extends Command

protected array $errorMessages = [];

public function handle(MediaRepository $mediaRepository, FileManipulator $fileManipulator)
public function handle(MediaRepository $mediaRepository, FileManipulator $fileManipulator): void
{
$this->mediaRepository = $mediaRepository;

Expand Down
2 changes: 1 addition & 1 deletion src/Conversions/ConversionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getConversions(string $collectionName = ''): self
return $this->filter(fn (Conversion $conversion) => $conversion->shouldBePerformedOn($collectionName));
}

protected function addManipulationToConversion(Manipulations $manipulations, string $conversionName)
protected function addManipulationToConversion(Manipulations $manipulations, string $conversionName): void
{
/** @var Conversion|null $conversion */
$conversion = $this->first(function (Conversion $conversion) use ($conversionName) {
Expand Down
8 changes: 3 additions & 5 deletions src/InteractsWithMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ trait InteractsWithMedia

protected array $unAttachedMediaLibraryItems = [];

public static function bootInteractsWithMedia()
public static function bootInteractsWithMedia(): void
{
static::deleting(function (HasMedia $model) {
if ($model->shouldDeletePreservingMedia()) {
Expand Down Expand Up @@ -181,7 +181,6 @@ public function addMediaFromString(string $text): FileAdder
/**
* Add a base64 encoded file to the media library.
*
*
* @throws \Spatie\MediaLibrary\MediaCollections\Exceptions\FileCannotBeAdded
* @throws InvalidBase64Data
*/
Expand All @@ -200,7 +199,7 @@ public function addMediaFromBase64(string $base64data, array|string ...$allowedM
throw InvalidBase64Data::create();
}

// decoding and then reencoding should not change the data
// decoding and then re-encoding should not change the data
if (base64_encode($binaryData) !== $base64data) {
throw InvalidBase64Data::create();
}
Expand Down Expand Up @@ -477,7 +476,6 @@ public function clearMediaCollectionExcept(
* Delete the associated media with the given id.
* You may also pass a media object.
*
*
* @throws \Spatie\MediaLibrary\MediaCollections\Exceptions\MediaCannotBeDeleted
*/
public function deleteMedia(int|string|Media $mediaId): void
Expand Down Expand Up @@ -558,7 +556,7 @@ public function processUnattachedMedia(callable $callable): void
$this->unAttachedMediaLibraryItems = [];
}

protected function guardAgainstInvalidMimeType(string $file, ...$allowedMimeTypes)
protected function guardAgainstInvalidMimeType(string $file, ...$allowedMimeTypes): void
{
$allowedMimeTypes = Arr::flatten($allowedMimeTypes);

Expand Down
2 changes: 1 addition & 1 deletion src/MediaCollections/Commands/CleanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function handle(
MediaRepository $mediaRepository,
FileManipulator $fileManipulator,
Factory $fileSystem,
) {
): void {
$this->mediaRepository = $mediaRepository;
$this->fileManipulator = $fileManipulator;
$this->fileSystem = $fileSystem;
Expand Down
2 changes: 1 addition & 1 deletion src/MediaCollections/Commands/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ClearCommand extends Command

protected MediaRepository $mediaRepository;

public function handle(MediaRepository $mediaRepository)
public function handle(MediaRepository $mediaRepository): void
{
$this->mediaRepository = $mediaRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class FunctionalityNotAvailable extends Exception
{
public static function mediaLibraryProRequired()
public static function mediaLibraryProRequired(): self
{
return new static('You need to have media library pro installed to make this work.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/MediaCollections/Exceptions/InvalidUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class InvalidUrl extends Exception
{
public static function doesNotStartWithProtocol(string $url)
public static function doesNotStartWithProtocol(string $url): self
{
return new static("Could not add `{$url}` because it does not start with either `http://` or `https://`");
}
Expand Down
2 changes: 1 addition & 1 deletion src/MediaCollections/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class File implements \Stringable
{
public static function createFromMedia($media)
public static function createFromMedia($media): self
{
return new static($media->file_name, $media->size, $media->mime_type);
}
Expand Down
10 changes: 5 additions & 5 deletions src/MediaCollections/FileAdder.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ protected function determineConversionsDiskName(string $originalsDiskName, strin
return $originalsDiskName;
}

protected function ensureDiskExists(string $diskName)
protected function ensureDiskExists(string $diskName): void
{
if (is_null(config("filesystems.disks.{$diskName}"))) {
throw DiskDoesNotExist::create($diskName);
Expand All @@ -401,7 +401,7 @@ public function sanitizingFileName(callable $fileNameSanitizer): self
return $this;
}

protected function attachMedia(Media $media)
protected function attachMedia(Media $media): void
{
if (! $this->subject->exists) {
$this->subject->prepareToAttachMedia($media, $this);
Expand All @@ -420,7 +420,7 @@ protected function attachMedia(Media $media)
$this->processMediaItem($this->subject, $media, $this);
}

protected function processMediaItem(HasMedia $model, Media $media, self $fileAdder)
protected function processMediaItem(HasMedia $model, Media $media, self $fileAdder): void
{
$this->guardAgainstDisallowedFileAdditions($media);

Expand Down Expand Up @@ -487,7 +487,7 @@ protected function getMediaCollection(string $collectionName): ?MediaCollection
->first(fn (MediaCollection $collection) => $collection->name === $collectionName);
}

protected function guardAgainstDisallowedFileAdditions(Media $media)
protected function guardAgainstDisallowedFileAdditions(Media $media): void
{
$file = PendingFile::createFromMedia($media);

Expand All @@ -504,7 +504,7 @@ protected function guardAgainstDisallowedFileAdditions(Media $media)
}
}

protected function checkGenerateResponsiveImages(Media $media)
protected function checkGenerateResponsiveImages(Media $media): void
{
$collection = optional($this->getMediaCollection($media->collection_name))->generateResponsiveImages;

Expand Down
2 changes: 1 addition & 1 deletion src/MediaCollections/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function streamFileToDisk($stream, string $destination, string $disk,
);
}

public function copyToMediaLibrary(string $pathToFile, Media $media, ?string $type = null, ?string $targetFileName = null)
public function copyToMediaLibrary(string $pathToFile, Media $media, ?string $type = null, ?string $targetFileName = null): void
{
$destinationFileName = $targetFileName ?: pathinfo($pathToFile, PATHINFO_BASENAME);

Expand Down
2 changes: 1 addition & 1 deletion src/MediaCollections/HtmlableMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function lazy(): self
return $this;
}

public function toHtml()
public function toHtml(): string
{
$imageGenerator = ImageGeneratorFactory::forMedia($this->media) ?? new Image();

Expand Down
4 changes: 2 additions & 2 deletions src/MediaCollections/MediaCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(
$this->acceptsFile = fn () => true;
}

public static function create($name)
public static function create($name): self
{
return new static($name);
}
Expand Down Expand Up @@ -94,7 +94,7 @@ public function onlyKeepLatest(int $maximumNumberOfItemsInCollection): self
return $this;
}

public function registerMediaConversions(callable $mediaConversionRegistrations)
public function registerMediaConversions(callable $mediaConversionRegistrations): void
{
$this->mediaConversionRegistrations = $mediaConversionRegistrations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function totalSizeInBytes(): int
return $this->sum('size');
}

public function toHtml()
public function toHtml(): string
{
return e(json_encode(old($this->formFieldName ?? $this->collectionName) ?? $this->map(function (Media $media) {
return [
Expand Down
2 changes: 1 addition & 1 deletion src/MediaCollections/Models/Concerns/HasUuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

trait HasUuid
{
public static function bootHasUuid()
public static function bootHasUuid(): void
{
static::creating(function (Model $model) {
/** @var \Spatie\MediaLibrary\MediaCollections\Models\Media $model */
Expand Down
16 changes: 9 additions & 7 deletions src/MediaCollections/Models/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
Expand All @@ -32,6 +33,7 @@
use Spatie\MediaLibrary\Support\UrlGenerator\UrlGenerator;
use Spatie\MediaLibrary\Support\UrlGenerator\UrlGeneratorFactory;
use Spatie\MediaLibraryPro\Models\TemporaryUpload;
use Symfony\Component\HttpFoundation\StreamedResponse;

/**
* @property string $uuid
Expand Down Expand Up @@ -80,7 +82,7 @@ class Media extends Model implements Attachable, Htmlable, Responsable

protected int $streamChunkSize = (1024 * 1024); // default to 1MB chunks.

public function newCollection(array $models = [])
public function newCollection(array $models = []): MediaCollection
{
return new MediaCollection($models);
}
Expand Down Expand Up @@ -311,24 +313,24 @@ public function hasGeneratedConversion(string $conversionName): bool
return Arr::get($generatedConversions, $conversionName, false);
}

public function setStreamChunkSize(int $chunkSize)
public function setStreamChunkSize(int $chunkSize): self
{
$this->streamChunkSize = $chunkSize;

return $this;
}

public function toResponse($request)
public function toResponse($request): StreamedResponse
{
return $this->buildResponse($request, 'attachment');
}

public function toInlineResponse($request)
public function toInlineResponse($request): StreamedResponse
{
return $this->buildResponse($request, 'inline');
}

private function buildResponse($request, string $contentDispositionType)
private function buildResponse($request, string $contentDispositionType): StreamedResponse
{
$filename = str_replace('"', '\'', Str::ascii($this->getDownloadFilename()));

Expand Down Expand Up @@ -433,7 +435,7 @@ public function stream()
return $filesystem->getStream($this);
}

public function toHtml()
public function toHtml(): string
{
return $this->img()->toHtml();
}
Expand All @@ -457,7 +459,7 @@ public function temporaryUpload(): BelongsTo
return $this->belongsTo(TemporaryUpload::class);
}

public static function findWithTemporaryUploadInCurrentSession(array $uuids)
public static function findWithTemporaryUploadInCurrentSession(array $uuids): EloquentCollection
{
MediaLibraryPro::ensureInstalled();

Expand Down
8 changes: 4 additions & 4 deletions src/MediaCollections/Models/Observers/MediaObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class MediaObserver
{
public function creating(Media $media)
public function creating(Media $media): void
{
if ($media->shouldSortWhenCreating()) {
if (is_null($media->order_column)) {
Expand All @@ -17,7 +17,7 @@ public function creating(Media $media)
}
}

public function updating(Media $media)
public function updating(Media $media): void
{
/** @var Filesystem $filesystem */
$filesystem = app(Filesystem::class);
Expand All @@ -31,7 +31,7 @@ public function updating(Media $media)
}
}

public function updated(Media $media)
public function updated(Media $media): void
{
if (is_null($media->getOriginal('model_id'))) {
return;
Expand All @@ -52,7 +52,7 @@ public function updated(Media $media)
}
}

public function deleted(Media $media)
public function deleted(Media $media): void
{
if (method_exists($media, 'isForceDeleting') && ! $media->isForceDeleting()) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/MediaLibraryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public function configurePackage(Package $package): void
]);
}

public function packageBooted()
public function packageBooted(): void
{
$mediaClass = config('media-library.media_model', Media::class);

$mediaClass::observe(new MediaObserver());
}

public function packageRegistered()
public function packageRegistered(): void
{
$this->app->bind(WidthCalculator::class, config('media-library.responsive_images.width_calculator'));
$this->app->bind(TinyPlaceholderGenerator::class, config('media-library.responsive_images.tiny_placeholder_generator'));
Expand Down
2 changes: 1 addition & 1 deletion src/ResponsiveImages/RegisteredResponsiveImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getPlaceholderSvg(): ?string
return $this->media->responsive_images[$this->generatedFor]['base64svg'] ?? null;
}

public function delete()
public function delete(): void
{
$this->files->each->delete();

Expand Down
4 changes: 2 additions & 2 deletions src/ResponsiveImages/ResponsiveImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class ResponsiveImage
{
public static function register(Media $media, $fileName, $conversionName)
public static function register(Media $media, $fileName, $conversionName): void
{
$responsiveImages = $media->responsive_images;

Expand All @@ -20,7 +20,7 @@ public static function register(Media $media, $fileName, $conversionName)
$media->save();
}

public static function registerTinySvg(Media $media, string $base64Svg, string $conversionName)
public static function registerTinySvg(Media $media, string $base64Svg, string $conversionName): void
{
$responsiveImages = $media->responsive_images;

Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,23 +295,23 @@ public function renderView($view, $parameters): string
return trim((string) ($view));
}

protected function assertFileExistsInZip(string $zipPath, string $filename)
protected function assertFileExistsInZip(string $zipPath, string $filename): void
{
$this->assertTrue(
$this->fileExistsInZip($zipPath, $filename),
"Failed to assert that {$zipPath} contains a file name {$filename}"
);
}

protected function assertFileExistsInZipRecognizeFolder(string $zipPath, string $filename)
protected function assertFileExistsInZipRecognizeFolder(string $zipPath, string $filename): void
{
$this->assertTrue(
$this->fileExistsInZipRecognizeFolder($zipPath, $filename),
"Failed to assert that {$zipPath} contains a file name {$filename} by recognizing folders"
);
}

protected function assertFileDoesntExistsInZip(string $zipPath, string $filename)
protected function assertFileDoesntExistsInZip(string $zipPath, string $filename): void
{
$this->assertFalse(
$this->fileExistsInZip($zipPath, $filename),
Expand Down

0 comments on commit 1272f88

Please sign in to comment.