From fe5c7e927b073c195cb266d19c029116a5be630b Mon Sep 17 00:00:00 2001 From: Sean Fraser Date: Tue, 16 May 2023 21:00:37 -0400 Subject: [PATCH 1/2] update psr/message requirement to 2.0 --- composer.json | 2 +- src/Stream.php | 30 ++++++++++++++---------------- tests/TestCase.php | 1 + 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 860450ee..d9178b05 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "illuminate/filesystem": "^8.83.3|^9.0|^10.0", "illuminate/database": "^8.83.3|^9.0|^10.0", "league/flysystem": "^1.1.9|^2.4.2|^3.0.4", - "psr/http-message": "^1.0.1", + "psr/http-message": "^2.0", "intervention/image": "^2.7.1", "guzzlehttp/guzzle": "^6.5.5|^7.4.1", "symfony/http-foundation": "^5.0.11|^6.0.3" diff --git a/src/Stream.php b/src/Stream.php index c4f6291f..910d03dd 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -90,7 +90,7 @@ public function __destruct() /** * {@inheritdoc} */ - public function __toString() + public function __toString(): string { try { $this->seek(0); @@ -103,7 +103,7 @@ public function __toString() /** * {@inheritdoc} */ - public function getContents() + public function getContents(): string { $contents = stream_get_contents($this->resource); @@ -117,7 +117,7 @@ public function getContents() /** * {@inheritdoc} */ - public function close() + public function close(): void { if (!$this->resource) { return; @@ -148,7 +148,7 @@ public function detach() /** * {@inheritdoc} */ - public function getSize() + public function getSize(): ?int { if ($this->size !== null) { return $this->size; @@ -176,7 +176,7 @@ public function getSize() /** * {@inheritdoc} */ - public function isReadable() + public function isReadable(): bool { return $this->readable; } @@ -184,7 +184,7 @@ public function isReadable() /** * {@inheritdoc} */ - public function isWritable() + public function isWritable(): bool { return $this->writable; } @@ -192,7 +192,7 @@ public function isWritable() /** * {@inheritdoc} */ - public function isSeekable() + public function isSeekable(): bool { return $this->seekable; } @@ -200,7 +200,7 @@ public function isSeekable() /** * {@inheritdoc} */ - public function eof() + public function eof(): bool { return !$this->resource || feof($this->resource); } @@ -208,7 +208,7 @@ public function eof() /** * {@inheritdoc} */ - public function tell() + public function tell(): int { if (!$this->resource) { throw new \RuntimeException('No resource available; cannot tell position'); @@ -226,7 +226,7 @@ public function tell() /** * {@inheritdoc} */ - public function rewind() + public function rewind(): void { $this->seek(0); } @@ -234,7 +234,7 @@ public function rewind() /** * {@inheritdoc} */ - public function seek($offset, $whence = SEEK_SET) + public function seek(int $offset, int $whence = SEEK_SET): void { if (!$this->resource) { throw new \RuntimeException('No resource available; cannot seek position'); @@ -250,14 +250,12 @@ public function seek($offset, $whence = SEEK_SET) throw new \RuntimeException('Unable to seek to stream position ' . $offset . ' with whence ' . var_export($whence, true)); } - - return true; } /** * {@inheritdoc} */ - public function read($length) + public function read(int $length): string { if (!$this->resource) { throw new \RuntimeException('No resource available; cannot read'); @@ -279,7 +277,7 @@ public function read($length) /** * {@inheritdoc} */ - public function write($string) + public function write(string $string): int { if (!$this->resource) { throw new \RuntimeException('No resource available; cannot write'); @@ -303,7 +301,7 @@ public function write($string) /** * {@inheritdoc} */ - public function getMetadata($key = null) + public function getMetadata(?string $key = null) { $metadata = stream_get_meta_data($this->resource); diff --git a/tests/TestCase.php b/tests/TestCase.php index 01a437a4..c6977576 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,6 +5,7 @@ use Dotenv\Dotenv; use Faker\Factory; use Illuminate\Contracts\Console\Kernel; +use Illuminate\Database\Eloquent\Model; use Illuminate\Filesystem\Filesystem; use Orchestra\Testbench\TestCase as BaseTestCase; use Plank\Mediable\Media; From cca978f514771bed0621ac6ef61d725f6d430d5d Mon Sep 17 00:00:00 2001 From: Sean Fraser Date: Tue, 16 May 2023 21:13:59 -0400 Subject: [PATCH 2/2] style fixes --- src/Media.php | 2 +- src/MediaUploader.php | 22 +++++++++++----------- src/Mediable.php | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Media.php b/src/Media.php index d72f6a4c..09ea547d 100644 --- a/src/Media.php +++ b/src/Media.php @@ -553,7 +553,7 @@ protected function handleMediaDeletion(): void ->where('media_id', $this->getKey()) ->delete(); } - // unlink associated file on delete + // unlink associated file on delete } elseif ($this->storage()->has($this->getDiskPath())) { $this->storage()->delete($this->getDiskPath()); } diff --git a/src/MediaUploader.php b/src/MediaUploader.php index aba7b350..48844ea8 100644 --- a/src/MediaUploader.php +++ b/src/MediaUploader.php @@ -878,17 +878,17 @@ private function handleDuplicate(Media $model): Media $this->deleteExistingMedia($model, true); break; case static::ON_DUPLICATE_UPDATE: - $original = $model->newQuery() - ->where('disk', $model->disk) - ->where('directory', $model->directory) - ->where('filename', $model->filename) - ->where('extension', $model->extension) - ->first(); - - if ($original) { - $model->{$model->getKeyName()} = $original->getKey(); - $model->exists = true; - } + $original = $model->newQuery() + ->where('disk', $model->disk) + ->where('directory', $model->directory) + ->where('filename', $model->filename) + ->where('extension', $model->extension) + ->first(); + + if ($original) { + $model->{$model->getKeyName()} = $original->getKey(); + $model->exists = true; + } break; case static::ON_DUPLICATE_INCREMENT: default: diff --git a/src/Mediable.php b/src/Mediable.php index 1eac04e2..7edab1c4 100644 --- a/src/Mediable.php +++ b/src/Mediable.php @@ -569,7 +569,7 @@ protected function handleMediableDeletion(): void if (config('mediable.detach_on_soft_delete')) { $this->media()->detach(); } - // always cascade for hard deletes + // always cascade for hard deletes } else { $this->media()->detach(); }