From b65a3e03bc7391fc7bb54c52b5783894df8feb49 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Fri, 8 Dec 2023 15:44:25 +0000 Subject: [PATCH] Fix styling --- config/media-library.php | 2 +- .../Commands/RegenerateCommand.php | 2 +- src/Conversions/FileManipulator.php | 2 +- .../FromImagePackage/OldManipulations.php | 105 ++++++++++++------ src/Conversions/ImageGenerators/Avif.php | 2 +- src/Conversions/ImageGenerators/Image.php | 2 +- .../ImageGenerators/ImageGenerator.php | 2 +- src/Conversions/ImageGenerators/Pdf.php | 2 +- src/Conversions/ImageGenerators/Svg.php | 2 +- src/Conversions/ImageGenerators/Video.php | 2 +- src/Conversions/ImageGenerators/Webp.php | 2 +- .../Jobs/PerformConversionsJob.php | 2 +- src/Conversions/Manipulations.php | 2 +- src/Downloaders/DefaultDownloader.php | 4 +- src/HasMedia.php | 4 +- src/InteractsWithMedia.php | 26 +---- .../Exceptions/FileIsTooBig.php | 2 +- .../Exceptions/FunctionalityNotAvailable.php | 2 +- src/MediaCollections/FileAdder.php | 2 +- src/MediaCollections/Filesystem.php | 6 +- src/MediaCollections/HtmlableMedia.php | 2 +- src/MediaCollections/MediaRepository.php | 8 -- .../Models/Concerns/IsSorted.php | 4 +- src/MediaCollections/Models/Media.php | 21 ++-- .../Jobs/GenerateResponsiveImagesJob.php | 2 +- .../ResponsiveImageGenerator.php | 2 +- .../FileRemover/FileBaseFileRemover.php | 2 +- src/Support/FileRemover/FileRemover.php | 1 - .../PathGenerator/DefaultPathGenerator.php | 2 +- .../PathGenerator/PathGeneratorFactory.php | 2 +- src/Support/UrlGenerator/UrlGenerator.php | 5 +- .../Conversions/Commands/CleanCommandTest.php | 15 +-- tests/Conversions/ConversionFileNamerTest.php | 8 +- .../TestImageGeneratorWithConfigTest.php | 2 +- tests/Feature/FileAdder/IntegrationTest.php | 11 +- .../MediaConversions/AddMediaTest.php | 10 +- .../MediaConversions/MediaCollectionTest.php | 37 +++--- .../InteractsWithMedia/GetMediaTest.php | 4 +- .../InteractsWithMedia/HasMediaTest.php | 2 - .../InteractsWithMedia/UpdateMediaTest.php | 2 - tests/Feature/Media/CustomHeadersTest.php | 2 - tests/Feature/Media/CustomPropertyTest.php | 2 - tests/Feature/Media/DeleteTest.php | 18 +-- tests/Feature/Media/GetAvailableUrlTest.php | 8 +- .../Feature/Media/GetMediaConversionsTest.php | 2 - .../Media/GetOriginalUrlAttributeTest.php | 2 - tests/Feature/Media/GetPathTest.php | 8 +- .../Media/GetPreviewUrlAttributeTest.php | 2 - tests/Feature/Media/GetTypeTest.php | 2 - tests/Feature/Media/RenameTest.php | 2 - tests/Feature/Media/ResponsableTest.php | 2 - tests/Feature/Media/ToHtmlTest.php | 4 +- .../Feature/Media/UpdateManipulationsTest.php | 10 +- .../S3Integration/S3TestPathGenerator.php | 2 +- .../ResponsiveImageFileNamerTest.php | 6 +- .../ResponsiveImageGeneratorFileNamerTest.php | 4 +- .../ResponsiveImageGeneratorTest.php | 42 +++---- .../ResponsiveImages/ResponsiveImageTest.php | 22 ++-- .../CustomDirectoryStructurePathGenerator.php | 4 +- tests/TestCase.php | 10 +- tests/TestSupport/TestImageGenerator.php | 2 +- .../TestImageGeneratorWithConfig.php | 2 +- .../TestModels/TestModelWithConversion.php | 2 +- .../TestModelWithConversionQueued.php | 2 +- ...tModelWithConversionUsingModelInstance.php | 2 +- .../TestModelWithConversionsOnOtherDisk.php | 2 +- .../TestModelWithCustomLoadingAttribute.php | 2 +- .../TestModelWithMultipleConversions.php | 2 +- .../TestModelWithPreviewConversion.php | 2 +- .../TestModelWithResponsiveImages.php | 12 +- .../TestModelWithoutMediaConversions.php | 2 + 71 files changed, 255 insertions(+), 248 deletions(-) diff --git a/config/media-library.php b/config/media-library.php index a5fc86764..e369db782 100644 --- a/config/media-library.php +++ b/config/media-library.php @@ -39,7 +39,7 @@ /* * When enabled, media collections will be serialised using the default * laravel model serialization behaviour. - * + * * Keep this option disabled if using Media Library Pro components (https://medialibrary.pro) */ 'use_default_collection_serialization' => false, diff --git a/src/Conversions/Commands/RegenerateCommand.php b/src/Conversions/Commands/RegenerateCommand.php index f2fa13448..50f583019 100644 --- a/src/Conversions/Commands/RegenerateCommand.php +++ b/src/Conversions/Commands/RegenerateCommand.php @@ -81,7 +81,7 @@ public function getMediaToBeRegenerated(): Collection // Get this arg first as it can also be passed to the greater-than-id branch $modelType = $this->argument('modelType'); - $startingFromId = (int)$this->option('starting-from-id'); + $startingFromId = (int) $this->option('starting-from-id'); if ($startingFromId !== 0) { $excludeStartingId = (bool) $this->option('exclude-starting-id') ?: false; diff --git a/src/Conversions/FileManipulator.php b/src/Conversions/FileManipulator.php index c7141ea69..840832215 100644 --- a/src/Conversions/FileManipulator.php +++ b/src/Conversions/FileManipulator.php @@ -54,7 +54,7 @@ public function performConversions( $copiedOriginalFile = app(Filesystem::class)->copyFromMediaLibrary( $media, - $temporaryDirectory->path(Str::random(32) . '.' . $media->extension) + $temporaryDirectory->path(Str::random(32).'.'.$media->extension) ); $conversions diff --git a/src/Conversions/FromImagePackage/OldManipulations.php b/src/Conversions/FromImagePackage/OldManipulations.php index 584598c01..7685b7ed6 100644 --- a/src/Conversions/FromImagePackage/OldManipulations.php +++ b/src/Conversions/FromImagePackage/OldManipulations.php @@ -9,58 +9,95 @@ class OldManipulations { public const CROP_TOP_LEFT = 'crop-top-left'; + public const CROP_TOP = 'crop-top'; + public const CROP_TOP_RIGHT = 'crop-top-right'; + public const CROP_LEFT = 'crop-left'; + public const CROP_CENTER = 'crop-center'; + public const CROP_RIGHT = 'crop-right'; + public const CROP_BOTTOM_LEFT = 'crop-bottom-left'; + public const CROP_BOTTOM = 'crop-bottom'; + public const CROP_BOTTOM_RIGHT = 'crop-bottom-right'; public const ORIENTATION_AUTO = 'auto'; + public const ORIENTATION_0 = 0; + public const ORIENTATION_90 = 90; + public const ORIENTATION_180 = 180; + public const ORIENTATION_270 = 270; public const FLIP_HORIZONTALLY = 'h'; + public const FLIP_VERTICALLY = 'v'; + public const FLIP_BOTH = 'both'; public const FIT_CONTAIN = 'contain'; + public const FIT_MAX = 'max'; + public const FIT_FILL = 'fill'; + public const FIT_FILL_MAX = 'fill-max'; + public const FIT_STRETCH = 'stretch'; + public const FIT_CROP = 'crop'; public const BORDER_OVERLAY = 'overlay'; + public const BORDER_SHRINK = 'shrink'; + public const BORDER_EXPAND = 'expand'; public const FORMAT_JPG = 'jpg'; + public const FORMAT_PJPG = 'pjpg'; + public const FORMAT_PNG = 'png'; + public const FORMAT_GIF = 'gif'; + public const FORMAT_WEBP = 'webp'; + public const FORMAT_AVIF = 'avif'; + public const FORMAT_TIFF = 'tiff'; public const FILTER_GREYSCALE = 'greyscale'; + public const FILTER_SEPIA = 'sepia'; public const UNIT_PIXELS = 'px'; + public const UNIT_PERCENT = '%'; public const POSITION_TOP_LEFT = 'top-left'; + public const POSITION_TOP = 'top'; + public const POSITION_TOP_RIGHT = 'top-right'; + public const POSITION_LEFT = 'left'; + public const POSITION_CENTER = 'center'; + public const POSITION_RIGHT = 'right'; + public const POSITION_BOTTOM_LEFT = 'bottom-left'; + public const POSITION_BOTTOM = 'bottom'; + public const POSITION_BOTTOM_RIGHT = 'bottom-right'; protected ManipulationSequence $manipulationSequence; @@ -133,8 +170,8 @@ public function crop(string $cropMethod, int $width, int $height): static } /** - * @param int $focalX Crop center X in percent - * @param int $focalY Crop center Y in percent + * @param int $focalX Crop center X in percent + * @param int $focalY Crop center Y in percent * * @throws InvalidManipulation */ @@ -175,7 +212,7 @@ public function width(int $width): static throw InvalidManipulation::invalidWidth($width); } - return $this->addManipulation('width', (string)$width); + return $this->addManipulation('width', (string) $width); } /** @@ -187,7 +224,7 @@ public function height(int $height): static throw InvalidManipulation::invalidHeight($height); } - return $this->addManipulation('height', (string)$height); + return $this->addManipulation('height', (string) $height); } /** @@ -219,7 +256,7 @@ public function fit(string $fitMethod, ?int $width = null, ?int $height = null): } /** - * @param int $ratio A value between 1 and 8 + * @param int $ratio A value between 1 and 8 * * @throws InvalidManipulation */ @@ -229,11 +266,11 @@ public function devicePixelRatio(int $ratio): static throw InvalidManipulation::valueNotInRange('ratio', $ratio, 1, 8); } - return $this->addManipulation('devicePixelRatio', (string)$ratio); + return $this->addManipulation('devicePixelRatio', (string) $ratio); } /** - * @param int $brightness A value between -100 and 100 + * @param int $brightness A value between -100 and 100 * * @throws InvalidManipulation */ @@ -243,11 +280,11 @@ public function brightness(int $brightness): static throw InvalidManipulation::valueNotInRange('brightness', $brightness, -100, 100); } - return $this->addManipulation('brightness', (string)$brightness); + return $this->addManipulation('brightness', (string) $brightness); } /** - * @param float $gamma A value between 0.01 and 9.99 + * @param float $gamma A value between 0.01 and 9.99 * * @throws InvalidManipulation */ @@ -257,11 +294,11 @@ public function gamma(float $gamma): static throw InvalidManipulation::valueNotInRange('gamma', $gamma, 0.01, 9.00); } - return $this->addManipulation('gamma', (string)$gamma); + return $this->addManipulation('gamma', (string) $gamma); } /** - * @param int $contrast A value between -100 and 100 + * @param int $contrast A value between -100 and 100 * * @throws InvalidManipulation */ @@ -271,11 +308,11 @@ public function contrast(int $contrast): static throw InvalidManipulation::valueNotInRange('contrast', $contrast, -100, 100); } - return $this->addManipulation('contrast', (string)$contrast); + return $this->addManipulation('contrast', (string) $contrast); } /** - * @param int $sharpen A value between 0 and 100 + * @param int $sharpen A value between 0 and 100 * * @throws InvalidManipulation */ @@ -285,11 +322,11 @@ public function sharpen(int $sharpen): static throw InvalidManipulation::valueNotInRange('sharpen', $sharpen, 0, 100); } - return $this->addManipulation('sharpen', (string)$sharpen); + return $this->addManipulation('sharpen', (string) $sharpen); } /** - * @param int $blur A value between 0 and 100 + * @param int $blur A value between 0 and 100 * * @throws InvalidManipulation */ @@ -299,11 +336,11 @@ public function blur(int $blur): static throw InvalidManipulation::valueNotInRange('blur', $blur, 0, 100); } - return $this->addManipulation('blur', (string)$blur); + return $this->addManipulation('blur', (string) $blur); } /** - * @param int $pixelate A value between 0 and 1000 + * @param int $pixelate A value between 0 and 1000 * * @throws InvalidManipulation */ @@ -313,7 +350,7 @@ public function pixelate(int $pixelate): static throw InvalidManipulation::valueNotInRange('pixelate', $pixelate, 0, 1000); } - return $this->addManipulation('pixelate', (string)$pixelate); + return $this->addManipulation('pixelate', (string) $pixelate); } /** @@ -366,7 +403,7 @@ public function quality(int $quality): static throw InvalidManipulation::valueNotInRange('quality', $quality, 0, 100); } - return $this->addManipulation('quality', (string)$quality); + return $this->addManipulation('quality', (string) $quality); } /** @@ -416,29 +453,29 @@ public function watermark(string $filePath): static } /** - * @param int $width The width of the watermark in pixels (default) or percent. - * @param string $unit The unit of the `$width` parameter. Use `Manipulations::UNIT_PERCENT` or `Manipulations::UNIT_PIXELS`. + * @param int $width The width of the watermark in pixels (default) or percent. + * @param string $unit The unit of the `$width` parameter. Use `Manipulations::UNIT_PERCENT` or `Manipulations::UNIT_PIXELS`. */ public function watermarkWidth(int $width, string $unit = 'px'): static { $width = ($unit === static::UNIT_PERCENT ? $width.'w' : $width); - return $this->addManipulation('watermarkWidth', (string)$width); + return $this->addManipulation('watermarkWidth', (string) $width); } /** - * @param int $height The height of the watermark in pixels (default) or percent. - * @param string $unit The unit of the `$height` parameter. Use `Manipulations::UNIT_PERCENT` or `Manipulations::UNIT_PIXELS`. + * @param int $height The height of the watermark in pixels (default) or percent. + * @param string $unit The unit of the `$height` parameter. Use `Manipulations::UNIT_PERCENT` or `Manipulations::UNIT_PIXELS`. */ public function watermarkHeight(int $height, string $unit = 'px'): static { $height = ($unit === static::UNIT_PERCENT ? $height.'h' : $height); - return $this->addManipulation('watermarkHeight', (string)$height); + return $this->addManipulation('watermarkHeight', (string) $height); } /** - * @param string $fitMethod How is the watermark fitted into the watermarkWidth and watermarkHeight properties. + * @param string $fitMethod How is the watermark fitted into the watermarkWidth and watermarkHeight properties. * * @throws InvalidManipulation */ @@ -456,19 +493,19 @@ public function watermarkFit(string $fitMethod): static } /** - * @param int $xPadding How far is the watermark placed from the left and right edges of the image. - * @param int|null $yPadding How far is the watermark placed from the top and bottom edges of the image. - * @param string $unit Unit of the padding values. Use `Manipulations::UNIT_PERCENT` or `Manipulations::UNIT_PIXELS`. + * @param int $xPadding How far is the watermark placed from the left and right edges of the image. + * @param int|null $yPadding How far is the watermark placed from the top and bottom edges of the image. + * @param string $unit Unit of the padding values. Use `Manipulations::UNIT_PERCENT` or `Manipulations::UNIT_PIXELS`. */ - public function watermarkPadding(int $xPadding, int $yPadding = null, string $unit = 'px'): static + public function watermarkPadding(int $xPadding, ?int $yPadding = null, string $unit = 'px'): static { $yPadding = $yPadding ?? $xPadding; $xPadding = ($unit === static::UNIT_PERCENT ? $xPadding.'w' : $xPadding); $yPadding = ($unit === static::UNIT_PERCENT ? $yPadding.'h' : $yPadding); - $this->addManipulation('watermarkPaddingX', (string)$xPadding); - $this->addManipulation('watermarkPaddingY', (string)$yPadding); + $this->addManipulation('watermarkPaddingX', (string) $xPadding); + $this->addManipulation('watermarkPaddingY', (string) $yPadding); return $this; } @@ -492,7 +529,7 @@ public function watermarkPosition(string $position): static /** * Sets the opacity of the watermark. Only works with the `imagick` driver. * - * @param int $opacity A value between 0 and 100. + * @param int $opacity A value between 0 and 100. * * @throws InvalidManipulation */ @@ -502,7 +539,7 @@ public function watermarkOpacity(int $opacity): static throw InvalidManipulation::valueNotInRange('opacity', $opacity, 0, 100); } - return $this->addManipulation('watermarkOpacity', (string)$opacity); + return $this->addManipulation('watermarkOpacity', (string) $opacity); } /** diff --git a/src/Conversions/ImageGenerators/Avif.php b/src/Conversions/ImageGenerators/Avif.php index a3c70361d..aec16a0a1 100644 --- a/src/Conversions/ImageGenerators/Avif.php +++ b/src/Conversions/ImageGenerators/Avif.php @@ -7,7 +7,7 @@ class Avif extends ImageGenerator { - public function convert(string $file, Conversion $conversion = null): string + public function convert(string $file, ?Conversion $conversion = null): string { $pathToImageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.png'; diff --git a/src/Conversions/ImageGenerators/Image.php b/src/Conversions/ImageGenerators/Image.php index c57402697..2b3add9c9 100644 --- a/src/Conversions/ImageGenerators/Image.php +++ b/src/Conversions/ImageGenerators/Image.php @@ -7,7 +7,7 @@ class Image extends ImageGenerator { - public function convert(string $path, Conversion $conversion = null): string + public function convert(string $path, ?Conversion $conversion = null): string { return $path; } diff --git a/src/Conversions/ImageGenerators/ImageGenerator.php b/src/Conversions/ImageGenerators/ImageGenerator.php index 6fc16b7e0..750a175cf 100644 --- a/src/Conversions/ImageGenerators/ImageGenerator.php +++ b/src/Conversions/ImageGenerators/ImageGenerator.php @@ -11,7 +11,7 @@ abstract class ImageGenerator /* * This function should return a path to an image representation of the given file. */ - abstract public function convert(string $file, Conversion $conversion = null): ?string; + abstract public function convert(string $file, ?Conversion $conversion = null): ?string; public function canConvert(Media $media): bool { diff --git a/src/Conversions/ImageGenerators/Pdf.php b/src/Conversions/ImageGenerators/Pdf.php index 8cde3736b..4fb86a654 100644 --- a/src/Conversions/ImageGenerators/Pdf.php +++ b/src/Conversions/ImageGenerators/Pdf.php @@ -7,7 +7,7 @@ class Pdf extends ImageGenerator { - public function convert(string $file, Conversion $conversion = null): string + public function convert(string $file, ?Conversion $conversion = null): string { $imageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.jpg'; diff --git a/src/Conversions/ImageGenerators/Svg.php b/src/Conversions/ImageGenerators/Svg.php index 7b512edf6..7963eb7c1 100644 --- a/src/Conversions/ImageGenerators/Svg.php +++ b/src/Conversions/ImageGenerators/Svg.php @@ -9,7 +9,7 @@ class Svg extends ImageGenerator { - public function convert(string $file, Conversion $conversion = null): string + public function convert(string $file, ?Conversion $conversion = null): string { $imageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.jpg'; diff --git a/src/Conversions/ImageGenerators/Video.php b/src/Conversions/ImageGenerators/Video.php index ff83bfa28..47d7c76c2 100644 --- a/src/Conversions/ImageGenerators/Video.php +++ b/src/Conversions/ImageGenerators/Video.php @@ -10,7 +10,7 @@ class Video extends ImageGenerator { - public function convert(string $file, Conversion $conversion = null): ?string + public function convert(string $file, ?Conversion $conversion = null): ?string { $ffmpeg = FFMpeg::create([ 'ffmpeg.binaries' => config('media-library.ffmpeg_path'), diff --git a/src/Conversions/ImageGenerators/Webp.php b/src/Conversions/ImageGenerators/Webp.php index 24b88529b..76b8ac188 100644 --- a/src/Conversions/ImageGenerators/Webp.php +++ b/src/Conversions/ImageGenerators/Webp.php @@ -7,7 +7,7 @@ class Webp extends ImageGenerator { - public function convert(string $file, Conversion $conversion = null): string + public function convert(string $file, ?Conversion $conversion = null): string { $pathToImageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.png'; diff --git a/src/Conversions/Jobs/PerformConversionsJob.php b/src/Conversions/Jobs/PerformConversionsJob.php index 8c94b7608..352b99c64 100644 --- a/src/Conversions/Jobs/PerformConversionsJob.php +++ b/src/Conversions/Jobs/PerformConversionsJob.php @@ -13,8 +13,8 @@ class PerformConversionsJob implements ShouldQueue { use InteractsWithQueue; - use SerializesModels; use Queueable; + use SerializesModels; public $deleteWhenMissingModels = true; diff --git a/src/Conversions/Manipulations.php b/src/Conversions/Manipulations.php index feb06312e..b83f80ba3 100644 --- a/src/Conversions/Manipulations.php +++ b/src/Conversions/Manipulations.php @@ -51,7 +51,7 @@ public function isEmpty(): bool public function apply(ImageDriver $image): void { - foreach($this->manipulations as $manipulationName => $parameters) { + foreach ($this->manipulations as $manipulationName => $parameters) { $image->$manipulationName(...$parameters); } } diff --git a/src/Downloaders/DefaultDownloader.php b/src/Downloaders/DefaultDownloader.php index c5dca09d2..24067e1b2 100644 --- a/src/Downloaders/DefaultDownloader.php +++ b/src/Downloaders/DefaultDownloader.php @@ -9,8 +9,8 @@ class DefaultDownloader implements Downloader public function getTempFile(string $url): string { $context = stream_context_create([ - "http" => [ - "header" => "User-Agent: Spatie MediaLibrary", + 'http' => [ + 'header' => 'User-Agent: Spatie MediaLibrary', ], ]); diff --git a/src/HasMedia.php b/src/HasMedia.php index d98c17dc3..9fe44fcbf 100644 --- a/src/HasMedia.php +++ b/src/HasMedia.php @@ -11,7 +11,9 @@ /** * @mixin \Illuminate\Database\Eloquent\Model + * * @method void prepareToAttachMedia(Media $media, FileAdder $fileAdder) + * * @property bool $registerMediaConversionsUsingModelInstance * @property ?\Spatie\MediaLibrary\MediaCollections\MediaCollection $mediaCollections */ @@ -37,7 +39,7 @@ public function loadMedia(string $collectionName); public function addMediaConversion(string $name): Conversion; - public function registerMediaConversions(Media $media = null): void; + public function registerMediaConversions(?Media $media = null): void; public function registerMediaCollections(): void; diff --git a/src/InteractsWithMedia.php b/src/InteractsWithMedia.php index 9393e995a..6a977cf8c 100644 --- a/src/InteractsWithMedia.php +++ b/src/InteractsWithMedia.php @@ -63,8 +63,6 @@ public function media(): MorphMany /** * Add a file to the media library. - * - * */ public function addMedia(string|UploadedFile $file): FileAdder { @@ -78,10 +76,8 @@ public function addMediaFromRequest(string $key): FileAdder /** * Add a file from the given disk. - * - * */ - public function addMediaFromDisk(string $key, string $disk = null): FileAdder + public function addMediaFromDisk(string $key, ?string $disk = null): FileAdder { return app(FileAdderFactory::class)->createFromDisk($this, $key, $disk ?: config('filesystems.default')); } @@ -111,8 +107,7 @@ public function syncFromMediaLibraryRequest(?array $mediaLibraryRequestItems): P /** * Add multiple files from a request by keys. * - * @param string[] $keys - * + * @param string[] $keys * @return \Spatie\MediaLibrary\MediaCollections\FileAdder[] */ public function addMultipleMediaFromRequest(array $keys): Collection @@ -165,7 +160,6 @@ public function addMediaFromUrl(string $url, array|string ...$allowedMimeTypes): ->usingFileName($filename); } - /** * Add a file to the media library that contains the given string. * @@ -189,7 +183,6 @@ public function addMediaFromString(string $text): FileAdder * * * @throws \Spatie\MediaLibrary\MediaCollections\Exceptions\FileCannotBeAdded - * * @throws InvalidBase64Data */ public function addMediaFromBase64(string $base64data, array|string ...$allowedMimeTypes): FileAdder @@ -203,7 +196,7 @@ public function addMediaFromBase64(string $base64data, array|string ...$allowedM // strict mode filters for non-base64 alphabet characters $binaryData = base64_decode($base64data, true); - if (false === $binaryData) { + if ($binaryData === false) { throw InvalidBase64Data::create(); } @@ -225,8 +218,6 @@ public function addMediaFromBase64(string $base64data, array|string ...$allowedM /** * Add a file to the media library from a stream. - * - * @param $stream */ public function addMediaFromStream($stream): FileAdder { @@ -243,8 +234,6 @@ public function addMediaFromStream($stream): FileAdder /** * Copy a file to the media library. - * - * */ public function copyMedia(string|UploadedFile $file): FileAdder { @@ -261,9 +250,6 @@ public function hasMedia(string $collectionName = 'default', array $filters = [] /** * Get media collection by its collectionName. - * - * @param array|callable $filters - * */ public function getMedia(string $collectionName = 'default', array|callable $filters = []): MediaCollections\Models\Collections\MediaCollection { @@ -577,7 +563,7 @@ protected function guardAgainstInvalidMimeType(string $file, ...$allowedMimeType $validation = Validator::make( ['file' => new File($file)], - ['file' => 'mimetypes:' . implode(',', $allowedMimeTypes)] + ['file' => 'mimetypes:'.implode(',', $allowedMimeTypes)] ); if ($validation->fails()) { @@ -585,7 +571,7 @@ protected function guardAgainstInvalidMimeType(string $file, ...$allowedMimeType } } - public function registerMediaConversions(Media $media = null): void + public function registerMediaConversions(?Media $media = null): void { } @@ -593,7 +579,7 @@ public function registerMediaCollections(): void { } - public function registerAllMediaConversions(Media $media = null): void + public function registerAllMediaConversions(?Media $media = null): void { $this->registerMediaCollections(); diff --git a/src/MediaCollections/Exceptions/FileIsTooBig.php b/src/MediaCollections/Exceptions/FileIsTooBig.php index de1569faa..ecb1e1509 100644 --- a/src/MediaCollections/Exceptions/FileIsTooBig.php +++ b/src/MediaCollections/Exceptions/FileIsTooBig.php @@ -6,7 +6,7 @@ class FileIsTooBig extends FileCannotBeAdded { - public static function create(string $path, int $size = null): self + public static function create(string $path, ?int $size = null): self { $fileSize = File::getHumanReadableSize($size ?: filesize($path)); diff --git a/src/MediaCollections/Exceptions/FunctionalityNotAvailable.php b/src/MediaCollections/Exceptions/FunctionalityNotAvailable.php index 91cac6ca2..18bc71ed4 100644 --- a/src/MediaCollections/Exceptions/FunctionalityNotAvailable.php +++ b/src/MediaCollections/Exceptions/FunctionalityNotAvailable.php @@ -8,6 +8,6 @@ class FunctionalityNotAvailable extends Exception { public static function mediaLibraryProRequired() { - return new static("You need to have media library pro installed to make this work."); + return new static('You need to have media library pro installed to make this work.'); } } diff --git a/src/MediaCollections/FileAdder.php b/src/MediaCollections/FileAdder.php index 4d02351e9..1e4d2e028 100644 --- a/src/MediaCollections/FileAdder.php +++ b/src/MediaCollections/FileAdder.php @@ -545,7 +545,7 @@ protected function toMediaCollectionFromTemporaryUpload(string $collectionName, protected function appendExtension(string $file, ?string $extension): string { return $extension - ? $file . '.' . $extension + ? $file.'.'.$extension : $file; } } diff --git a/src/MediaCollections/Filesystem.php b/src/MediaCollections/Filesystem.php index 58a63f54c..029f8401c 100644 --- a/src/MediaCollections/Filesystem.php +++ b/src/MediaCollections/Filesystem.php @@ -28,7 +28,7 @@ public function add(string $file, Media $media, ?string $targetFileName = null): { try { $this->copyToMediaLibrary($file, $media, null, $targetFileName); - } catch(DiskCannotBeAccessed $exception) { + } catch (DiskCannotBeAccessed $exception) { return false; } @@ -43,7 +43,7 @@ public function addRemote(RemoteFile $file, Media $media, ?string $targetFileNam { try { $this->copyToMediaLibraryFromRemote($file, $media, null, $targetFileName); - } catch(DiskCannotBeAccessed $exception) { + } catch (DiskCannotBeAccessed $exception) { return false; } @@ -185,7 +185,7 @@ public function addCustomRemoteHeaders(array $customRemoteHeaders): void public function getRemoteHeadersForFile( string $file, array $mediaCustomHeaders = [], - string $mimeType = null + ?string $mimeType = null ): array { $mimeTypeHeader = ['ContentType' => $mimeType ?: File::getMimeType($file)]; diff --git a/src/MediaCollections/HtmlableMedia.php b/src/MediaCollections/HtmlableMedia.php index a545ba091..e6e849854 100644 --- a/src/MediaCollections/HtmlableMedia.php +++ b/src/MediaCollections/HtmlableMedia.php @@ -8,7 +8,7 @@ use Spatie\MediaLibrary\Conversions\ImageGenerators\ImageGeneratorFactory; use Spatie\MediaLibrary\MediaCollections\Models\Media; -class HtmlableMedia implements Htmlable, \Stringable +class HtmlableMedia implements \Stringable, Htmlable { protected string $conversionName = ''; diff --git a/src/MediaCollections/MediaRepository.php b/src/MediaCollections/MediaRepository.php index 3601f15b6..f0b6d62f6 100644 --- a/src/MediaCollections/MediaRepository.php +++ b/src/MediaCollections/MediaRepository.php @@ -19,9 +19,6 @@ public function __construct( /** * Get all media in the collection. - * - * @param array|callable $filter - * */ public function getCollection( HasMedia $model, @@ -33,11 +30,6 @@ public function getCollection( /** * Apply given filters on media. - * - * @param Collection $media - * @param array|callable $filter - * - * @return Collection */ protected function applyFilterToMediaCollection( Collection $media, diff --git a/src/MediaCollections/Models/Concerns/IsSorted.php b/src/MediaCollections/Models/Concerns/IsSorted.php index 945fc3082..f3cbb1170 100644 --- a/src/MediaCollections/Models/Concerns/IsSorted.php +++ b/src/MediaCollections/Models/Concerns/IsSorted.php @@ -16,8 +16,8 @@ public function setHighestOrderNumber(): void public function getHighestOrderNumber(): int { return (int) static::where('model_type', $this->model_type) - ->where('model_id', $this->model_id) - ->max($this->determineOrderColumnName()); + ->where('model_id', $this->model_id) + ->max($this->determineOrderColumnName()); } public function scopeOrdered(Builder $query): Builder diff --git a/src/MediaCollections/Models/Media.php b/src/MediaCollections/Models/Media.php index 6978d676e..013e43fa2 100644 --- a/src/MediaCollections/Models/Media.php +++ b/src/MediaCollections/Models/Media.php @@ -56,11 +56,11 @@ * @property-read ?\Illuminate\Support\Carbon $created_at * @property-read ?\Illuminate\Support\Carbon $updated_at */ -class Media extends Model implements Responsable, Htmlable, Attachable +class Media extends Model implements Attachable, Htmlable, Responsable { - use IsSorted; use CustomMediaProperties; use HasUuid; + use IsSorted; protected $table = 'media'; @@ -225,10 +225,7 @@ public function hasCustomProperty(string $propertyName): bool /** * Get the value of custom property with the given name. * - * @param string $propertyName - * @param mixed $default - * - * @return mixed + * @param mixed $default */ public function getCustomProperty(string $propertyName, $default = null): mixed { @@ -236,8 +233,7 @@ public function getCustomProperty(string $propertyName, $default = null): mixed } /** - * @param mixed $value - * + * @param mixed $value * @return $this */ public function setCustomProperty(string $name, $value): self @@ -274,7 +270,6 @@ public function getGeneratedConversions(): Collection return collect($this->generated_conversions ?? []); } - public function markAsConversionGenerated(string $conversionName): self { $generatedConversions = $this->generated_conversions; @@ -324,7 +319,7 @@ private function buildResponse($request, string $contentDispositionType) 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Content-Type' => $this->mime_type, 'Content-Length' => $this->size, - 'Content-Disposition' => $contentDispositionType . '; filename="' . $this->file_name . '"', + 'Content-Disposition' => $contentDispositionType.'; filename="'.$this->file_name.'"', 'Pragma' => 'public', ]; @@ -366,7 +361,7 @@ protected function originalUrl(): Attribute return Attribute::get(fn () => $this->getUrl()); } - /** @param string $collectionName */ + /** @param string $collectionName */ public function move(HasMedia $model, $collectionName = 'default', string $diskName = '', string $fileName = ''): self { $newMedia = $this->copy($model, $collectionName, $diskName, $fileName); @@ -376,12 +371,12 @@ public function move(HasMedia $model, $collectionName = 'default', string $diskN return $newMedia; } - /** @param string $collectionName */ + /** @param string $collectionName */ public function copy(HasMedia $model, $collectionName = 'default', string $diskName = '', string $fileName = ''): self { $temporaryDirectory = TemporaryDirectory::create(); - $temporaryFile = $temporaryDirectory->path('/') . DIRECTORY_SEPARATOR . $this->file_name; + $temporaryFile = $temporaryDirectory->path('/').DIRECTORY_SEPARATOR.$this->file_name; /** @var Filesystem $filesystem */ $filesystem = app(Filesystem::class); diff --git a/src/ResponsiveImages/Jobs/GenerateResponsiveImagesJob.php b/src/ResponsiveImages/Jobs/GenerateResponsiveImagesJob.php index 011c58714..f7ea883c5 100644 --- a/src/ResponsiveImages/Jobs/GenerateResponsiveImagesJob.php +++ b/src/ResponsiveImages/Jobs/GenerateResponsiveImagesJob.php @@ -12,8 +12,8 @@ class GenerateResponsiveImagesJob implements ShouldQueue { use InteractsWithQueue; - use SerializesModels; use Queueable; + use SerializesModels; public function __construct(protected Media $media) { diff --git a/src/ResponsiveImages/ResponsiveImageGenerator.php b/src/ResponsiveImages/ResponsiveImageGenerator.php index 3934dc853..809d34844 100644 --- a/src/ResponsiveImages/ResponsiveImageGenerator.php +++ b/src/ResponsiveImages/ResponsiveImageGenerator.php @@ -144,7 +144,7 @@ public function generateTinyJpg( ResponsiveImage::registerTinySvg($media, $base64Svg, $conversionName); } - protected function appendToFileName(string $filePath, string $suffix, string $extensionFilePath = null): string + protected function appendToFileName(string $filePath, string $suffix, ?string $extensionFilePath = null): string { $baseName = pathinfo($filePath, PATHINFO_FILENAME); diff --git a/src/Support/FileRemover/FileBaseFileRemover.php b/src/Support/FileRemover/FileBaseFileRemover.php index 9119ab682..b69e5904c 100644 --- a/src/Support/FileRemover/FileBaseFileRemover.php +++ b/src/Support/FileRemover/FileBaseFileRemover.php @@ -14,7 +14,7 @@ public function __construct(protected Filesystem $mediaFileSystem, protected Fac public function removeAllFiles(Media $media): void { - $this->removeFile($this->mediaFileSystem->getMediaDirectory($media). $media->file_name, $media->disk); + $this->removeFile($this->mediaFileSystem->getMediaDirectory($media).$media->file_name, $media->disk); $this->removeConvertedImages($media); } diff --git a/src/Support/FileRemover/FileRemover.php b/src/Support/FileRemover/FileRemover.php index 46d80f46b..6d3e2e1ec 100644 --- a/src/Support/FileRemover/FileRemover.php +++ b/src/Support/FileRemover/FileRemover.php @@ -24,5 +24,4 @@ public function removeResponsiveImages(Media $media, string $conversionName): vo * Remove a file relating to the media model. */ public function removeFile(string $path, string $disk): void; - } diff --git a/src/Support/PathGenerator/DefaultPathGenerator.php b/src/Support/PathGenerator/DefaultPathGenerator.php index c7a6ef92f..0e6d1401d 100644 --- a/src/Support/PathGenerator/DefaultPathGenerator.php +++ b/src/Support/PathGenerator/DefaultPathGenerator.php @@ -38,7 +38,7 @@ protected function getBasePath(Media $media): string $prefix = config('media-library.prefix', ''); if ($prefix !== '') { - return $prefix . '/' . $media->getKey(); + return $prefix.'/'.$media->getKey(); } return $media->getKey(); diff --git a/src/Support/PathGenerator/PathGeneratorFactory.php b/src/Support/PathGenerator/PathGeneratorFactory.php index 63d770e6b..f59a61156 100644 --- a/src/Support/PathGenerator/PathGeneratorFactory.php +++ b/src/Support/PathGenerator/PathGeneratorFactory.php @@ -41,7 +41,7 @@ protected static function mediaBelongToModelClass(Media $media, string $modelCla return true; } // config is set via morphMap class name - if (is_a((string)Relation::getMorphedModel($media->model_type), $modelClass, true)) { + if (is_a((string) Relation::getMorphedModel($media->model_type), $modelClass, true)) { return true; } diff --git a/src/Support/UrlGenerator/UrlGenerator.php b/src/Support/UrlGenerator/UrlGenerator.php index c108e4fbf..f8d3e42f4 100644 --- a/src/Support/UrlGenerator/UrlGenerator.php +++ b/src/Support/UrlGenerator/UrlGenerator.php @@ -20,10 +20,7 @@ public function setConversion(Conversion $conversion): self; public function setPathGenerator(PathGenerator $pathGenerator): self; /** - * @param DateTimeInterface $expiration - * @param array $options - * - * @return string + * @param array $options */ public function getTemporaryUrl(DateTimeInterface $expiration, array $options = []): string; diff --git a/tests/Conversions/Commands/CleanCommandTest.php b/tests/Conversions/Commands/CleanCommandTest.php index 1ccadb75e..11c526c4d 100644 --- a/tests/Conversions/Commands/CleanCommandTest.php +++ b/tests/Conversions/Commands/CleanCommandTest.php @@ -184,9 +184,9 @@ it('can clean responsive images for active conversions without responsive images', function () { $media = $this->testModelWithConversion - ->addMedia($this->getTestJpg()) - ->preservingOriginal() - ->toMediaCollection(); + ->addMedia($this->getTestJpg()) + ->preservingOriginal() + ->toMediaCollection(); $thumbResponsiveImageFileName = "{$media->file_name}___thumb_340_280.jpg"; $thumbReponsiveImagesPath = $this->getMediaDirectory("{$media->id}/responsive-images/{$thumbResponsiveImageFileName}"); @@ -195,7 +195,7 @@ $originalResponsiveImagesContent = $media->responsive_images; $newResponsiveImages = $originalResponsiveImagesContent; - $newResponsiveImages['thumb']['base64svg'] = "data:image/svg+xml;base64,PCPg=="; + $newResponsiveImages['thumb']['base64svg'] = 'data:image/svg+xml;base64,PCPg=='; $newResponsiveImages['thumb']['urls'][0] = $thumbResponsiveImageFileName; $media->responsive_images = $newResponsiveImages; $media->save(); @@ -235,7 +235,7 @@ ->preservingOriginal() ->toMediaCollection(); - $deprecatedImage = $this->getMediaDirectory(md5($media->id) . "/c/test-deprecated.jpg"); + $deprecatedImage = $this->getMediaDirectory(md5($media->id).'/c/test-deprecated.jpg'); touch($deprecatedImage); expect($deprecatedImage)->toBeFile(); @@ -243,7 +243,7 @@ $this->artisan('media-library:clean'); $this->assertFileDoesNotExist($deprecatedImage); - expect($this->getMediaDirectory(md5($media->id) . "/c/test-thumb.jpg"))->toBeFile(); + expect($this->getMediaDirectory(md5($media->id).'/c/test-thumb.jpg'))->toBeFile(); }); it('can clean deprecated conversion files in same path as original image', function () { @@ -355,7 +355,8 @@ }); it('will not clean media items on soft deleted models', function () { - $testModelClass = new class () extends TestModel { + $testModelClass = new class() extends TestModel + { use SoftDeletes; }; diff --git a/tests/Conversions/ConversionFileNamerTest.php b/tests/Conversions/ConversionFileNamerTest.php index 62c0ab2c6..8003e863f 100644 --- a/tests/Conversions/ConversionFileNamerTest.php +++ b/tests/Conversions/ConversionFileNamerTest.php @@ -3,19 +3,19 @@ use Spatie\MediaLibrary\Tests\TestSupport\TestFileNamer; it('can use a custom file namer', function () { - $fileName = "prefix_test_suffix"; + $fileName = 'prefix_test_suffix'; - config()->set("media-library.file_namer", TestFileNamer::class); + config()->set('media-library.file_namer', TestFileNamer::class); $this ->testModelWithConversion ->addMedia($this->getTestJpg()) ->toMediaCollection(); - $path = $this->testModelWithConversion->refresh()->getFirstMediaPath("default", "thumb"); + $path = $this->testModelWithConversion->refresh()->getFirstMediaPath('default', 'thumb'); expect($path)->toEndWith("{$fileName}---thumb.jpg"); expect($path)->toBeFile(); - expect($this->testModelWithConversion->getFirstMediaUrl("default", "thumb"))->toEqual("/media/1/conversions/{$fileName}---thumb.jpg"); + expect($this->testModelWithConversion->getFirstMediaUrl('default', 'thumb'))->toEqual("/media/1/conversions/{$fileName}---thumb.jpg"); }); diff --git a/tests/Conversions/ImageGenerators/TestImageGeneratorWithConfigTest.php b/tests/Conversions/ImageGenerators/TestImageGeneratorWithConfigTest.php index a2626f21b..73f7fdaed 100644 --- a/tests/Conversions/ImageGenerators/TestImageGeneratorWithConfigTest.php +++ b/tests/Conversions/ImageGenerators/TestImageGeneratorWithConfigTest.php @@ -20,7 +20,7 @@ test('image generators will receive config parameters by name', function () { config()->set('media-library.image_generators', [ - TestImageGeneratorWithConfig::class => ['secondName' => 'secondValue', 'firstName' => 'firstValue', ], + TestImageGeneratorWithConfig::class => ['secondName' => 'secondValue', 'firstName' => 'firstValue'], ]); $imageGenerators = ImageGeneratorFactory::getImageGenerators(); diff --git a/tests/Feature/FileAdder/IntegrationTest.php b/tests/Feature/FileAdder/IntegrationTest.php index 9bc4f2182..110de499c 100644 --- a/tests/Feature/FileAdder/IntegrationTest.php +++ b/tests/Feature/FileAdder/IntegrationTest.php @@ -592,8 +592,8 @@ it('will throw an exception and revert database when file cannot be added', function () { $this->testModel - ->addMedia($this->getTestPng()) - ->toMediaCollection(); + ->addMedia($this->getTestPng()) + ->toMediaCollection(); expect(Media::count())->toBe(1); @@ -615,7 +615,8 @@ }); it('will throw an exception and revert database when file cannot be added and model uses softdeletes', function () { - $testModelClass = new class () extends TestModel { + $testModelClass = new class() extends TestModel + { use SoftDeletes; }; @@ -623,8 +624,8 @@ $testModel = $testModelClass::find($this->testModel->id); $testModel - ->addMedia($this->getTestPng()) - ->toMediaCollection(); + ->addMedia($this->getTestPng()) + ->toMediaCollection(); expect(Media::count())->toBe(1); diff --git a/tests/Feature/FileAdder/MediaConversions/AddMediaTest.php b/tests/Feature/FileAdder/MediaConversions/AddMediaTest.php index f393f811a..9a33996f9 100644 --- a/tests/Feature/FileAdder/MediaConversions/AddMediaTest.php +++ b/tests/Feature/FileAdder/MediaConversions/AddMediaTest.php @@ -44,8 +44,9 @@ }); it('will use the name of the conversion for naming the converted file', function () { - $modelClass = new class () extends TestModelWithConversion { - public function registerMediaConversions(Media $media = null): void + $modelClass = new class() extends TestModelWithConversion + { + public function registerMediaConversions(?Media $media = null): void { $this->addMediaConversion('my-conversion') ->setManipulations(function (Manipulations $manipulations) { @@ -97,7 +98,8 @@ class_exists(Imagick::class) }); it('will have access the model instance when register media conversions using model instance has been set', function () { - $modelClass = new class () extends TestModel { + $modelClass = new class() extends TestModel + { public bool $registerMediaConversionsUsingModelInstance = true; /** @@ -105,7 +107,7 @@ class_exists(Imagick::class) * * @return array */ - public function registerMediaConversions(Media $media = null): void + public function registerMediaConversions(?Media $media = null): void { $this->addMediaConversion('thumb') ->width($this->width) diff --git a/tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php b/tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php index ba4225096..22f803d80 100644 --- a/tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php +++ b/tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php @@ -7,7 +7,8 @@ use Spatie\MediaLibrary\Tests\TestSupport\TestModels\TestModelWithoutMediaConversions; it('will use the disk from a media collection', function () { - $testModel = new class () extends TestModelWithConversion { + $testModel = new class() extends TestModelWithConversion + { public function registerMediaCollections(): void { $this->addMediaCollection('images') @@ -29,7 +30,8 @@ public function registerMediaCollections(): void }); it('will not use the disk name of the collection if a diskname is specified while adding', function () { - $testModel = new class () extends TestModelWithConversion { + $testModel = new class() extends TestModelWithConversion + { public function registerMediaCollections(): void { $this->addMediaCollection('images') @@ -47,7 +49,8 @@ public function registerMediaCollections(): void }); it('can register media conversions when defining media collections', function () { - $testModel = new class () extends TestModelWithoutMediaConversions { + $testModel = new class() extends TestModelWithoutMediaConversions + { public function registerMediaCollections(): void { $this @@ -68,7 +71,8 @@ public function registerMediaCollections(): void }); it('will not use media conversions from an unrelated collection', function () { - $testModel = new class () extends TestModelWithoutMediaConversions { + $testModel = new class() extends TestModelWithoutMediaConversions + { public function registerMediaCollections(): void { $this @@ -89,8 +93,9 @@ public function registerMediaCollections(): void }); it('will use conversions defined in conversions and conversions defined in collections', function () { - $testModel = new class () extends TestModelWithoutMediaConversions { - public function registerMediaConversions(Media $media = null): void + $testModel = new class() extends TestModelWithoutMediaConversions + { + public function registerMediaConversions(?Media $media = null): void { $this ->addMediaConversion('another-thumb') @@ -101,7 +106,7 @@ public function registerMediaCollections(): void { $this ->addMediaCollection('images') - ->registerMediaConversions(function (Media $media = null) { + ->registerMediaConversions(function (?Media $media = null) { $this ->addMediaConversion('thumb') ->greyscale(); @@ -119,7 +124,8 @@ public function registerMediaCollections(): void }); it('can accept certain files', function () { - $testModel = new class () extends TestModelWithConversion { + $testModel = new class() extends TestModelWithConversion + { public function registerMediaCollections(): void { $this @@ -138,7 +144,8 @@ public function registerMediaCollections(): void }); it('can guard against invalid mimetypes', function () { - $testModel = new class () extends TestModelWithConversion { + $testModel = new class() extends TestModelWithConversion + { public function registerMediaCollections(): void { $this @@ -157,7 +164,8 @@ public function registerMediaCollections(): void }); it('can generate responsive images', function () { - $testModel = new class () extends TestModelWithConversion { + $testModel = new class() extends TestModelWithConversion + { public function registerMediaCollections(): void { $this @@ -182,7 +190,8 @@ public function registerMediaCollections(): void }); it('can generate responsive images on condition', function () { - $testModel = new class () extends TestModelWithConversion { + $testModel = new class() extends TestModelWithConversion + { public function registerMediaCollections(): void { $this @@ -207,7 +216,8 @@ public function registerMediaCollections(): void }); test('if the single file method is specified it will delete all other media and will only keep the new one', function () { - $testModel = new class () extends TestModelWithConversion { + $testModel = new class() extends TestModelWithConversion + { public function registerMediaCollections(): void { $this @@ -226,7 +236,8 @@ public function registerMediaCollections(): void }); test('if the only keeps latest method is specified it will delete all other media and will only keep the latest n ones', function () { - $testModel = new class () extends TestModelWithConversion { + $testModel = new class() extends TestModelWithConversion + { public function registerMediaCollections(): void { $this diff --git a/tests/Feature/InteractsWithMedia/GetMediaTest.php b/tests/Feature/InteractsWithMedia/GetMediaTest.php index 071967d03..08b2f15ae 100644 --- a/tests/Feature/InteractsWithMedia/GetMediaTest.php +++ b/tests/Feature/InteractsWithMedia/GetMediaTest.php @@ -274,7 +274,7 @@ ], $preloadedTestModel ->getMedia('images') ->pluck('order_column', 'id') - ->map(fn ($value) => (int)$value) + ->map(fn ($value) => (int) $value) ->toArray()); $firstMedia->order_column = 3; @@ -290,7 +290,7 @@ ], $preloadedTestModel ->getMedia('images') ->pluck('order_column', 'id') - ->map(fn ($value) => (int)$value) + ->map(fn ($value) => (int) $value) ->toArray()); }); diff --git a/tests/Feature/InteractsWithMedia/HasMediaTest.php b/tests/Feature/InteractsWithMedia/HasMediaTest.php index 47e6948cf..e5d5baf7f 100644 --- a/tests/Feature/InteractsWithMedia/HasMediaTest.php +++ b/tests/Feature/InteractsWithMedia/HasMediaTest.php @@ -1,7 +1,5 @@ testModel->hasMedia())->toBeFalse(); }); diff --git a/tests/Feature/InteractsWithMedia/UpdateMediaTest.php b/tests/Feature/InteractsWithMedia/UpdateMediaTest.php index 8fa5871e3..0c1d26294 100644 --- a/tests/Feature/InteractsWithMedia/UpdateMediaTest.php +++ b/tests/Feature/InteractsWithMedia/UpdateMediaTest.php @@ -1,7 +1,5 @@ testModel->addMedia($this->getTestJpg())->usingName('test1')->preservingOriginal()->toMediaCollection(); $this->testModel->addMedia($this->getTestJpg())->usingName('test2')->preservingOriginal()->toMediaCollection(); diff --git a/tests/Feature/Media/CustomHeadersTest.php b/tests/Feature/Media/CustomHeadersTest.php index 6cdcde455..20c3d7626 100644 --- a/tests/Feature/Media/CustomHeadersTest.php +++ b/tests/Feature/Media/CustomHeadersTest.php @@ -1,7 +1,5 @@ testModel ->addMedia($this->getTestJpg()) diff --git a/tests/Feature/Media/CustomPropertyTest.php b/tests/Feature/Media/CustomPropertyTest.php index 5ac9e4c50..ff7c4c162 100644 --- a/tests/Feature/Media/CustomPropertyTest.php +++ b/tests/Feature/Media/CustomPropertyTest.php @@ -1,7 +1,5 @@ media = $this->testModel ->addMedia($this->getTestJpg()) diff --git a/tests/Feature/Media/DeleteTest.php b/tests/Feature/Media/DeleteTest.php index 746552ea9..7588a084c 100644 --- a/tests/Feature/Media/DeleteTest.php +++ b/tests/Feature/Media/DeleteTest.php @@ -68,7 +68,6 @@ $media = $this->testModelWithConversion->addMedia($this->getTestJpg())->toMediaCollection('images'); - expect(File::exists($media->getPath()))->toBeTrue(); expect(File::exists($media->getPath('thumb')))->toBeTrue(); expect(File::exists($media->getPath('keep_original_format')))->toBeTrue(); @@ -88,12 +87,12 @@ $pathGenerator = new CustomDirectoryStructurePathGenerator(); expect(File::exists($media->getPath()))->toBeTrue(); - expect(Storage::disk($media->disk)->exists($pathGenerator->getPathForResponsiveImages($media). 'test___thumb_50_63.jpg'))->toBeTrue(); + expect(Storage::disk($media->disk)->exists($pathGenerator->getPathForResponsiveImages($media).'test___thumb_50_63.jpg'))->toBeTrue(); $media->delete(); expect(File::exists($media->getPath()))->toBeFalse(); - expect(Storage::disk($media->disk)->exists($pathGenerator->getPathForResponsiveImages($media). 'test___thumb_50_63.jpg'))->toBeFalse(); + expect(Storage::disk($media->disk)->exists($pathGenerator->getPathForResponsiveImages($media).'test___thumb_50_63.jpg'))->toBeFalse(); }); @@ -101,7 +100,6 @@ config(['media-library.path_generator' => CustomDirectoryStructurePathGenerator::class]); config(['media-library.file_remover_class' => FileBaseFileRemover::class]); - $media = $this->testModel->addMedia($this->getTestJpg())->toMediaCollection('images'); $media2 = $this->testModel->addMedia($this->getTestPng())->toMediaCollection('images'); @@ -115,7 +113,8 @@ }); it('will not remove the files when should delete preserving media returns true', function () { - $testModelClass = new class () extends TestModel { + $testModelClass = new class() extends TestModel + { public function shouldDeletePreservingMedia(): bool { return true; @@ -134,7 +133,8 @@ public function shouldDeletePreservingMedia(): bool }); it('will remove the files when should delete preserving media returns false', function () { - $testModelClass = new class () extends TestModel { + $testModelClass = new class() extends TestModel + { public function shouldDeletePreservingMedia(): bool { return false; @@ -153,7 +153,8 @@ public function shouldDeletePreservingMedia(): bool }); it('will not remove the file when model uses softdelete', function () { - $testModelClass = new class () extends TestModel { + $testModelClass = new class() extends TestModel + { use SoftDeletes; }; @@ -172,7 +173,8 @@ public function shouldDeletePreservingMedia(): bool }); it('will remove the file when model uses softdelete with force', function () { - $testModelClass = new class () extends TestModel { + $testModelClass = new class() extends TestModel + { use SoftDeletes; }; diff --git a/tests/Feature/Media/GetAvailableUrlTest.php b/tests/Feature/Media/GetAvailableUrlTest.php index 3cd7e877f..ad1edc7fd 100644 --- a/tests/Feature/Media/GetAvailableUrlTest.php +++ b/tests/Feature/Media/GetAvailableUrlTest.php @@ -9,19 +9,19 @@ expect($media->getAvailableUrl(['small', 'medium', 'large']))->toEqual("/media/{$media->id}/conversions/test-large.jpg"); expect($media->getAvailableFullUrl(['small', 'medium', 'large']))->toEqual("http://localhost/media/{$media->id}/conversions/test-large.jpg"); - expect($media->getAvailablePath(['small', 'medium', 'large']))->toEqual($this->makePathOsSafe($this->getMediaDirectory() . "/{$media->id}/conversions/test-large.jpg")); + expect($media->getAvailablePath(['small', 'medium', 'large']))->toEqual($this->makePathOsSafe($this->getMediaDirectory()."/{$media->id}/conversions/test-large.jpg")); $media->markAsConversionGenerated('medium'); expect($media->getAvailableUrl(['small', 'medium', 'large']))->toEqual("/media/{$media->id}/conversions/test-medium.jpg"); expect($media->getAvailableFullUrl(['small', 'medium', 'large']))->toEqual("http://localhost/media/{$media->id}/conversions/test-medium.jpg"); - expect($media->getAvailablePath(['small', 'medium', 'large']))->toEqual($this->makePathOsSafe($this->getMediaDirectory() . "/{$media->id}/conversions/test-medium.jpg")); + expect($media->getAvailablePath(['small', 'medium', 'large']))->toEqual($this->makePathOsSafe($this->getMediaDirectory()."/{$media->id}/conversions/test-medium.jpg")); $media->markAsConversionGenerated('small'); expect($media->getAvailableUrl(['small', 'medium', 'large']))->toEqual("/media/{$media->id}/conversions/test-small.jpg"); expect($media->getAvailableFullUrl(['small', 'medium', 'large']))->toEqual("http://localhost/media/{$media->id}/conversions/test-small.jpg"); - expect($media->getAvailablePath(['small', 'medium', 'large']))->toEqual($this->makePathOsSafe($this->getMediaDirectory() . "/{$media->id}/conversions/test-small.jpg")); + expect($media->getAvailablePath(['small', 'medium', 'large']))->toEqual($this->makePathOsSafe($this->getMediaDirectory()."/{$media->id}/conversions/test-small.jpg")); }); it('uses original url if no conversion has been generated yet', function () { @@ -32,5 +32,5 @@ expect($media->getAvailableUrl(['small', 'medium', 'large']))->toEqual("/media/{$media->id}/test.jpg"); expect($media->getAvailableFullUrl(['small', 'medium', 'large']))->toEqual("http://localhost/media/{$media->id}/test.jpg"); - expect($media->getAvailablePath(['small', 'medium', 'large']))->toEqual($this->makePathOsSafe($this->getMediaDirectory() . "/{$media->id}/test.jpg")); + expect($media->getAvailablePath(['small', 'medium', 'large']))->toEqual($this->makePathOsSafe($this->getMediaDirectory()."/{$media->id}/test.jpg")); }); diff --git a/tests/Feature/Media/GetMediaConversionsTest.php b/tests/Feature/Media/GetMediaConversionsTest.php index d0f7d5b0d..166e03cb1 100644 --- a/tests/Feature/Media/GetMediaConversionsTest.php +++ b/tests/Feature/Media/GetMediaConversionsTest.php @@ -1,7 +1,5 @@ testModel ->addMedia($this->getTestJpg()) diff --git a/tests/Feature/Media/GetOriginalUrlAttributeTest.php b/tests/Feature/Media/GetOriginalUrlAttributeTest.php index 74e2566e7..dfa26b4d2 100644 --- a/tests/Feature/Media/GetOriginalUrlAttributeTest.php +++ b/tests/Feature/Media/GetOriginalUrlAttributeTest.php @@ -1,7 +1,5 @@ testModelWithPreviewConversion->addMedia($this->getTestJpg())->toMediaCollection(); diff --git a/tests/Feature/Media/GetPathTest.php b/tests/Feature/Media/GetPathTest.php index 7f06c105d..1de1e417f 100644 --- a/tests/Feature/Media/GetPathTest.php +++ b/tests/Feature/Media/GetPathTest.php @@ -5,7 +5,7 @@ it('can get a path of an original item', function () { $media = $this->testModel->addMedia($this->getTestJpg())->toMediaCollection(); - $expected = $this->makePathOsSafe($this->getMediaDirectory() . "/{$media->id}/test.jpg"); + $expected = $this->makePathOsSafe($this->getMediaDirectory()."/{$media->id}/test.jpg"); $actual = $this->makePathOsSafe($media->getPath()); @@ -17,7 +17,7 @@ $conversionName = 'thumb'; - $expected = $this->makePathOsSafe($this->getMediaDirectory() . "/{$media->id}/conversions/test-{$conversionName}.jpg"); + $expected = $this->makePathOsSafe($this->getMediaDirectory()."/{$media->id}/conversions/test-{$conversionName}.jpg"); $actual = $this->makePathOsSafe($media->getPath($conversionName)); @@ -37,7 +37,7 @@ $media = $this->testModel->addMedia($this->getTestJpg())->toMediaCollection(); - $expected = $this->makePathOsSafe($this->getMediaDirectory() . "/prefix/{$media->id}/test.jpg"); + $expected = $this->makePathOsSafe($this->getMediaDirectory()."/prefix/{$media->id}/test.jpg"); $actual = $this->makePathOsSafe($media->getPath()); @@ -51,7 +51,7 @@ $conversionName = 'thumb'; - $expected = $this->makePathOsSafe($this->getMediaDirectory() . "/prefix/{$media->id}/conversions/test-{$conversionName}.jpg"); + $expected = $this->makePathOsSafe($this->getMediaDirectory()."/prefix/{$media->id}/conversions/test-{$conversionName}.jpg"); $actual = $this->makePathOsSafe($media->getPath($conversionName)); diff --git a/tests/Feature/Media/GetPreviewUrlAttributeTest.php b/tests/Feature/Media/GetPreviewUrlAttributeTest.php index 818c692f7..837cf8307 100644 --- a/tests/Feature/Media/GetPreviewUrlAttributeTest.php +++ b/tests/Feature/Media/GetPreviewUrlAttributeTest.php @@ -1,7 +1,5 @@ testModelWithPreviewConversion->addMedia($this->getTestJpg())->toMediaCollection(); diff --git a/tests/Feature/Media/GetTypeTest.php b/tests/Feature/Media/GetTypeTest.php index eb55275ae..6223054cd 100644 --- a/tests/Feature/Media/GetTypeTest.php +++ b/tests/Feature/Media/GetTypeTest.php @@ -1,7 +1,5 @@ testModel->addMedia($this->getTestJpg())->toMediaCollection(); diff --git a/tests/Feature/Media/RenameTest.php b/tests/Feature/Media/RenameTest.php index ee6565019..db02ab62e 100644 --- a/tests/Feature/Media/RenameTest.php +++ b/tests/Feature/Media/RenameTest.php @@ -1,7 +1,5 @@ getTestFilesDirectory('test.jpg'); diff --git a/tests/Feature/Media/ResponsableTest.php b/tests/Feature/Media/ResponsableTest.php index 23b1b11fc..1997d4bbd 100644 --- a/tests/Feature/Media/ResponsableTest.php +++ b/tests/Feature/Media/ResponsableTest.php @@ -1,7 +1,5 @@ get('/upload', fn () => $this->testModel ->addMedia($this->getTestJpg()) diff --git a/tests/Feature/Media/ToHtmlTest.php b/tests/Feature/Media/ToHtmlTest.php index fa6734ef2..c73a68b44 100644 --- a/tests/Feature/Media/ToHtmlTest.php +++ b/tests/Feature/Media/ToHtmlTest.php @@ -86,8 +86,8 @@ $image = $media->refresh()->img('thumb'); - expect((string)$image)->toContain('/media/2/responsive-images/'); - expect((string)$image)->toContain('data:image/svg+xml;base64,'); + expect((string) $image)->toContain('/media/2/responsive-images/'); + expect((string) $image)->toContain('data:image/svg+xml;base64,'); }); it('will not render extra javascript or include base64 svg when tiny placeholders are turned off', function () { diff --git a/tests/Feature/Media/UpdateManipulationsTest.php b/tests/Feature/Media/UpdateManipulationsTest.php index 1d3ef6455..4d6175de5 100644 --- a/tests/Feature/Media/UpdateManipulationsTest.php +++ b/tests/Feature/Media/UpdateManipulationsTest.php @@ -4,8 +4,9 @@ use Spatie\MediaLibrary\Tests\TestSupport\TestModels\TestModel; it('will create derived files when manipulations have changed', function () { - $testModelClass = new class () extends TestModel { - public function registerMediaConversions(Media $media = null): void + $testModelClass = new class() extends TestModel + { + public function registerMediaConversions(?Media $media = null): void { $this->addMediaConversion('update_test'); } @@ -35,8 +36,9 @@ public function registerMediaConversions(Media $media = null): void }); it('will not create derived files when manipulations have not changed', function () { - $testModelClass = new class () extends TestModel { - public function registerMediaConversions(Media $media = null): void + $testModelClass = new class() extends TestModel + { + public function registerMediaConversions(?Media $media = null): void { $this->addMediaConversion('update_test'); } diff --git a/tests/Feature/S3Integration/S3TestPathGenerator.php b/tests/Feature/S3Integration/S3TestPathGenerator.php index b77822097..e4bb5c6ff 100644 --- a/tests/Feature/S3Integration/S3TestPathGenerator.php +++ b/tests/Feature/S3Integration/S3TestPathGenerator.php @@ -33,6 +33,6 @@ public function getPathForResponsiveImages(Media $media): string */ protected function getBasePath(Media $media): string { - return (getS3BaseTestDirectory()).'/'.$media->getKey(); + return getS3BaseTestDirectory().'/'.$media->getKey(); } } diff --git a/tests/ResponsiveImages/ResponsiveImageFileNamerTest.php b/tests/ResponsiveImages/ResponsiveImageFileNamerTest.php index 6c30ce2a0..39d209551 100644 --- a/tests/ResponsiveImages/ResponsiveImageFileNamerTest.php +++ b/tests/ResponsiveImages/ResponsiveImageFileNamerTest.php @@ -3,8 +3,8 @@ use Spatie\MediaLibrary\Tests\TestSupport\TestFileNamer; beforeEach(function () { - config()->set("media-library.file_namer", TestFileNamer::class); + config()->set('media-library.file_namer', TestFileNamer::class); - $this->fileName = "prefix_test_suffix"; - $this->fileNameWithUnderscore = "prefix_test__suffix"; + $this->fileName = 'prefix_test_suffix'; + $this->fileNameWithUnderscore = 'prefix_test__suffix'; }); diff --git a/tests/ResponsiveImages/ResponsiveImageGeneratorFileNamerTest.php b/tests/ResponsiveImages/ResponsiveImageGeneratorFileNamerTest.php index d074f2753..5d11ced1c 100644 --- a/tests/ResponsiveImages/ResponsiveImageGeneratorFileNamerTest.php +++ b/tests/ResponsiveImages/ResponsiveImageGeneratorFileNamerTest.php @@ -3,7 +3,7 @@ use Spatie\MediaLibrary\Tests\TestSupport\TestFileNamer; beforeEach(function () { - config()->set("media-library.file_namer", TestFileNamer::class); + config()->set('media-library.file_namer', TestFileNamer::class); - $this->fileName = "prefix_test_suffix"; + $this->fileName = 'prefix_test_suffix'; }); diff --git a/tests/ResponsiveImages/ResponsiveImageGeneratorTest.php b/tests/ResponsiveImages/ResponsiveImageGeneratorTest.php index e559ff5a4..de03247db 100644 --- a/tests/ResponsiveImages/ResponsiveImageGeneratorTest.php +++ b/tests/ResponsiveImages/ResponsiveImageGeneratorTest.php @@ -9,9 +9,9 @@ it('can generate responsive images', function () { $this->testModel - ->addMedia($this->getTestJpg()) - ->withResponsiveImages() - ->toMediaCollection(); + ->addMedia($this->getTestJpg()) + ->withResponsiveImages() + ->toMediaCollection(); expect($this->getTempDirectory("media/1/responsive-images/{$this->fileName}___media_library_original_237_195.jpg"))->toBeFile(); expect($this->getTempDirectory("media/1/responsive-images/{$this->fileName}___media_library_original_284_234.jpg"))->toBeFile(); @@ -20,9 +20,9 @@ it('will generate responsive images if with responsive images if returns true', function () { $this->testModel - ->addMedia($this->getTestJpg()) - ->withResponsiveImagesIf(fn () => true) - ->toMediaCollection(); + ->addMedia($this->getTestJpg()) + ->withResponsiveImagesIf(fn () => true) + ->toMediaCollection(); expect($this->getTempDirectory("media/1/responsive-images/{$this->fileName}___media_library_original_237_195.jpg"))->toBeFile(); expect($this->getTempDirectory("media/1/responsive-images/{$this->fileName}___media_library_original_284_234.jpg"))->toBeFile(); @@ -31,18 +31,18 @@ it('will not generate responsive images if with responsive images if returns false', function () { $this->testModel - ->addMedia($this->getTestJpg()) - ->withResponsiveImagesIf(fn () => false) - ->toMediaCollection(); + ->addMedia($this->getTestJpg()) + ->withResponsiveImagesIf(fn () => false) + ->toMediaCollection(); $this->assertFileDoesNotExist($this->getTempDirectory("media/1/responsive-images/{$this->fileName}___media_library_original_237_195.jpg")); }); test('its conversions can have responsive images', function () { $this->testModelWithResponsiveImages - ->addMedia($this->getTestJpg()) - ->withResponsiveImages() - ->toMediaCollection(); + ->addMedia($this->getTestJpg()) + ->withResponsiveImages() + ->toMediaCollection(); expect($this->getTempDirectory("media/1/responsive-images/{$this->fileName}___thumb_50_41.jpg"))->toBeFile(); }); @@ -60,29 +60,29 @@ it('cleans the responsive images urls from the db before regeneration', function () { $media = $this->testModelWithResponsiveImages - ->addMedia($this->getTestFilesDirectory("test.jpg")) + ->addMedia($this->getTestFilesDirectory('test.jpg')) ->withResponsiveImages() ->toMediaCollection(); - expect($media->fresh()->responsive_images["thumb"]["urls"])->toHaveCount(1); + expect($media->fresh()->responsive_images['thumb']['urls'])->toHaveCount(1); - $this->artisan("media-library:regenerate"); - expect($media->fresh()->responsive_images["thumb"]["urls"])->toHaveCount(1); + $this->artisan('media-library:regenerate'); + expect($media->fresh()->responsive_images['thumb']['urls'])->toHaveCount(1); }); it('will add responsive image entries when there were none when regenerating', function () { $media = $this->testModelWithResponsiveImages - ->addMedia($this->getTestFilesDirectory("test.jpg")) + ->addMedia($this->getTestFilesDirectory('test.jpg')) ->withResponsiveImages() ->toMediaCollection(); // remove all responsive image db entries $responsiveImages = $media->responsive_images; - $responsiveImages["thumb"]["urls"] = []; + $responsiveImages['thumb']['urls'] = []; $media->responsive_images = $responsiveImages; $media->save(); - expect($media->fresh()->responsive_images["thumb"]["urls"])->toHaveCount(0); + expect($media->fresh()->responsive_images['thumb']['urls'])->toHaveCount(0); - $this->artisan("media-library:regenerate"); - expect($media->fresh()->responsive_images["thumb"]["urls"])->toHaveCount(1); + $this->artisan('media-library:regenerate'); + expect($media->fresh()->responsive_images['thumb']['urls'])->toHaveCount(1); }); diff --git a/tests/ResponsiveImages/ResponsiveImageTest.php b/tests/ResponsiveImages/ResponsiveImageTest.php index 77bdd15cc..66cf6e560 100644 --- a/tests/ResponsiveImages/ResponsiveImageTest.php +++ b/tests/ResponsiveImages/ResponsiveImageTest.php @@ -22,9 +22,9 @@ $this->assertEquals([ "/media/1/responsive-images/{$this->fileName}___thumb_50_41.jpg", - ], $media->getResponsiveImageUrls("thumb")); + ], $media->getResponsiveImageUrls('thumb')); - expect($media->getResponsiveImageUrls("non-existing-conversion"))->toEqual([]); + expect($media->getResponsiveImageUrls('non-existing-conversion'))->toEqual([]); }); test('a media instance can generate the contents of scrset', function () { @@ -39,13 +39,13 @@ "/media/1/responsive-images/{$this->fileName}___media_library_original_340_280.jpg 340w, /media/1/responsive-images/{$this->fileName}___media_library_original_284_234.jpg 284w, /media/1/responsive-images/{$this->fileName}___media_library_original_237_195.jpg 237w", $media->getSrcset() ); - expect($media->getSrcset())->toContain("data:image/svg+xml;base64"); + expect($media->getSrcset())->toContain('data:image/svg+xml;base64'); $this->assertStringContainsString( "/media/1/responsive-images/{$this->fileName}___thumb_50_41.jpg 50w", - $media->getSrcset("thumb") + $media->getSrcset('thumb') ); - expect($media->getSrcset("thumb"))->toContain("data:image/svg+xml;base64,"); + expect($media->getSrcset('thumb'))->toContain('data:image/svg+xml;base64,'); }); test('a responsive image can return some properties', function () { @@ -58,7 +58,7 @@ $responsiveImage = $media->responsiveImages()->files->first(); - expect($responsiveImage->generatedFor())->toEqual("media_library_original"); + expect($responsiveImage->generatedFor())->toEqual('media_library_original'); expect($responsiveImage->width())->toEqual(340); @@ -69,7 +69,7 @@ $this->testModelWithResponsiveImages ->addMedia($this->getTestJpg()) ->preservingOriginal() - ->toMediaCollection("default"); + ->toMediaCollection('default'); $standardQualityResponsiveConversion = $this->getTempDirectory("media/1/responsive-images/{$this->fileName}___standardQuality_340_280.jpg"); $lowerQualityResponsiveConversion = $this->getTempDirectory("media/1/responsive-images/{$this->fileName}___lowerQuality_340_280.jpg"); @@ -81,14 +81,14 @@ $this->testModelWithResponsiveImages ->addMedia($this->getTestJpg()) ->withResponsiveImages() - ->storingConversionsOnDisk("secondMediaDisk") + ->storingConversionsOnDisk('secondMediaDisk') ->toMediaCollection(); $media = $this->testModelWithResponsiveImages->getFirstMedia(); $this->assertEquals([ "/media2/1/responsive-images/{$this->fileName}___thumb_50_41.jpg", - ], $media->getResponsiveImageUrls("thumb")); + ], $media->getResponsiveImageUrls('thumb')); }); it('can handle file names with underscore', function () { @@ -108,7 +108,7 @@ $this->assertSame([ "/media/1/responsive-images/{$this->fileNameWithUnderscore}___thumb_50_41.jpg", - ], $media->getResponsiveImageUrls("thumb")); + ], $media->getResponsiveImageUrls('thumb')); - expect($media->getResponsiveImageUrls("non-existing-conversion"))->toBe([]); + expect($media->getResponsiveImageUrls('non-existing-conversion'))->toBe([]); }); diff --git a/tests/Support/PathGenerator/CustomDirectoryStructurePathGenerator.php b/tests/Support/PathGenerator/CustomDirectoryStructurePathGenerator.php index ad10b3d29..417bf62a9 100644 --- a/tests/Support/PathGenerator/CustomDirectoryStructurePathGenerator.php +++ b/tests/Support/PathGenerator/CustomDirectoryStructurePathGenerator.php @@ -14,11 +14,11 @@ public function getPath(Media $media): string public function getPathForConversions(Media $media): string { - return $this->getPath($media) . 'c/'; + return $this->getPath($media).'c/'; } public function getPathForResponsiveImages(Media $media): string { - return $this->getPath($media) . 'cri/'; + return $this->getPath($media).'cri/'; } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 7d2b9d7bf..13f4b1418 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -81,8 +81,7 @@ protected function loadEnvironmentVariables() } /** - * @param \Illuminate\Foundation\Application $app - * + * @param \Illuminate\Foundation\Application $app * @return array */ protected function getPackageProviders($app) @@ -95,7 +94,7 @@ protected function getPackageProviders($app) } /** - * @param \Illuminate\Foundation\Application $app + * @param \Illuminate\Foundation\Application $app */ public function getEnvironmentSetUp($app) { @@ -131,7 +130,7 @@ public function getEnvironmentSetUp($app) } /** - * @param \Illuminate\Foundation\Application $app + * @param \Illuminate\Foundation\Application $app */ protected function setUpDatabase($app) { @@ -144,13 +143,12 @@ protected function setUpDatabase($app) TestModel::create(['name' => 'test']); - if (MediaLibraryPro::isInstalled()) { include_once __DIR__.'/../vendor/spatie/laravel-medialibrary-pro/database/migrations/create_temporary_uploads_table.stub'; (new CreateTemporaryUploadsTable())->up(); } - $mediaTableMigration = require(__DIR__.'/../database/migrations/create_media_table.php.stub'); + $mediaTableMigration = require __DIR__.'/../database/migrations/create_media_table.php.stub'; $mediaTableMigration->up(); } diff --git a/tests/TestSupport/TestImageGenerator.php b/tests/TestSupport/TestImageGenerator.php index 5d3dbee3f..7506efaf6 100644 --- a/tests/TestSupport/TestImageGenerator.php +++ b/tests/TestSupport/TestImageGenerator.php @@ -36,7 +36,7 @@ public function shouldMatchBothExtensionsAndMimeTypes(): bool return $this->shouldMatchBothExtensionsAndMimeTypes; } - public function convert(string $path, Conversion $conversion = null): string + public function convert(string $path, ?Conversion $conversion = null): string { return $path; } diff --git a/tests/TestSupport/TestImageGeneratorWithConfig.php b/tests/TestSupport/TestImageGeneratorWithConfig.php index 365223b8c..f24d7c898 100644 --- a/tests/TestSupport/TestImageGeneratorWithConfig.php +++ b/tests/TestSupport/TestImageGeneratorWithConfig.php @@ -14,7 +14,7 @@ public function __construct( ) { } - public function convert(string $file, Conversion $conversion = null): string + public function convert(string $file, ?Conversion $conversion = null): string { // TODO: Implement convert() method. } diff --git a/tests/TestSupport/TestModels/TestModelWithConversion.php b/tests/TestSupport/TestModels/TestModelWithConversion.php index 098fbd8b9..fc99e5ce6 100644 --- a/tests/TestSupport/TestModels/TestModelWithConversion.php +++ b/tests/TestSupport/TestModels/TestModelWithConversion.php @@ -6,7 +6,7 @@ class TestModelWithConversion extends TestModel { - public function registerMediaConversions(Media $media = null): void + public function registerMediaConversions(?Media $media = null): void { $this->addMediaConversion('thumb') ->width(50) diff --git a/tests/TestSupport/TestModels/TestModelWithConversionQueued.php b/tests/TestSupport/TestModels/TestModelWithConversionQueued.php index 18a28688d..cc92224ea 100644 --- a/tests/TestSupport/TestModels/TestModelWithConversionQueued.php +++ b/tests/TestSupport/TestModels/TestModelWithConversionQueued.php @@ -6,7 +6,7 @@ class TestModelWithConversionQueued extends TestModel { - public function registerMediaConversions(Media $media = null): void + public function registerMediaConversions(?Media $media = null): void { $this->addMediaConversion('thumb') ->width(50); diff --git a/tests/TestSupport/TestModels/TestModelWithConversionUsingModelInstance.php b/tests/TestSupport/TestModels/TestModelWithConversionUsingModelInstance.php index 99ac28dbd..1b52b5210 100644 --- a/tests/TestSupport/TestModels/TestModelWithConversionUsingModelInstance.php +++ b/tests/TestSupport/TestModels/TestModelWithConversionUsingModelInstance.php @@ -8,7 +8,7 @@ class TestModelWithConversionUsingModelInstance extends TestModelWithConversion { public $registerMediaConversionsUsingModelInstance = true; - public function registerMediaConversions(Media $media = null): void + public function registerMediaConversions(?Media $media = null): void { $this ->addMediaConversion('lazy-conversion') diff --git a/tests/TestSupport/TestModels/TestModelWithConversionsOnOtherDisk.php b/tests/TestSupport/TestModels/TestModelWithConversionsOnOtherDisk.php index 91d6da063..755945ac0 100644 --- a/tests/TestSupport/TestModels/TestModelWithConversionsOnOtherDisk.php +++ b/tests/TestSupport/TestModels/TestModelWithConversionsOnOtherDisk.php @@ -6,7 +6,7 @@ class TestModelWithConversionsOnOtherDisk extends TestModel { - public function registerMediaConversions(Media $media = null): void + public function registerMediaConversions(?Media $media = null): void { $this->addMediaConversion('thumb') ->withResponsiveImages() diff --git a/tests/TestSupport/TestModels/TestModelWithCustomLoadingAttribute.php b/tests/TestSupport/TestModels/TestModelWithCustomLoadingAttribute.php index 984e9b701..cf370844c 100644 --- a/tests/TestSupport/TestModels/TestModelWithCustomLoadingAttribute.php +++ b/tests/TestSupport/TestModels/TestModelWithCustomLoadingAttribute.php @@ -6,7 +6,7 @@ class TestModelWithCustomLoadingAttribute extends TestModelWithConversion { - public function registerMediaConversions(Media $media = null): void + public function registerMediaConversions(?Media $media = null): void { $this ->addMediaConversion('lazy-conversion') diff --git a/tests/TestSupport/TestModels/TestModelWithMultipleConversions.php b/tests/TestSupport/TestModels/TestModelWithMultipleConversions.php index 9934bd45e..e52e46b0c 100644 --- a/tests/TestSupport/TestModels/TestModelWithMultipleConversions.php +++ b/tests/TestSupport/TestModels/TestModelWithMultipleConversions.php @@ -6,7 +6,7 @@ class TestModelWithMultipleConversions extends TestModel { - public function registerMediaConversions(Media $media = null): void + public function registerMediaConversions(?Media $media = null): void { $this->addMediaConversion('small') ->width(50) diff --git a/tests/TestSupport/TestModels/TestModelWithPreviewConversion.php b/tests/TestSupport/TestModels/TestModelWithPreviewConversion.php index ed7bba263..47efd9653 100644 --- a/tests/TestSupport/TestModels/TestModelWithPreviewConversion.php +++ b/tests/TestSupport/TestModels/TestModelWithPreviewConversion.php @@ -7,7 +7,7 @@ class TestModelWithPreviewConversion extends TestModel { - public function registerMediaConversions(Media $media = null): void + public function registerMediaConversions(?Media $media = null): void { $this->addMediaConversion('preview') ->fit(Fit::Contain, 300, 300) diff --git a/tests/TestSupport/TestModels/TestModelWithResponsiveImages.php b/tests/TestSupport/TestModels/TestModelWithResponsiveImages.php index a6373730d..9e6fc8c85 100644 --- a/tests/TestSupport/TestModels/TestModelWithResponsiveImages.php +++ b/tests/TestSupport/TestModels/TestModelWithResponsiveImages.php @@ -6,7 +6,7 @@ class TestModelWithResponsiveImages extends TestModel { - public function registerMediaConversions(Media $media = null): void + public function registerMediaConversions(?Media $media = null): void { $this->addMediaConversion('thumb') ->withResponsiveImages() @@ -24,12 +24,12 @@ public function registerMediaConversions(Media $media = null): void ->withResponsiveImages(); $this->addMediaConversion('lowerQuality') - ->withResponsiveImages() - ->quality(60) - ->nonQueued(); + ->withResponsiveImages() + ->quality(60) + ->nonQueued(); $this->addMediaConversion('standardQuality') - ->withResponsiveImages() - ->nonQueued(); + ->withResponsiveImages() + ->nonQueued(); } } diff --git a/tests/TestSupport/TestModels/TestModelWithoutMediaConversions.php b/tests/TestSupport/TestModels/TestModelWithoutMediaConversions.php index 8ca2c3069..20e82cd8d 100644 --- a/tests/TestSupport/TestModels/TestModelWithoutMediaConversions.php +++ b/tests/TestSupport/TestModels/TestModelWithoutMediaConversions.php @@ -11,6 +11,8 @@ class TestModelWithoutMediaConversions extends Model implements HasMedia use InteractsWithMedia; protected $table = 'test_models'; + protected $guarded = []; + public $timestamps = false; }