From a17be959d8b148f439305498ada0babd1b0ca2c7 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 1 Nov 2021 13:26:02 +0000 Subject: [PATCH] Applied latest styleci changes --- app/Entities/Tools/PageContent.php | 4 +++- app/Http/Controllers/AttachmentController.php | 1 + app/Http/Controllers/Controller.php | 4 +--- app/Providers/CustomValidationServiceProvider.php | 1 + app/Uploads/ImageRepo.php | 3 ++- app/Uploads/ImageService.php | 4 +++- app/Util/WebSafeMimeSniffer.php | 4 +--- tests/Auth/MfaVerificationTest.php | 4 ++-- tests/Entity/PageContentTest.php | 1 - tests/Uploads/AttachmentTest.php | 3 +-- 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/Entities/Tools/PageContent.php b/app/Entities/Tools/PageContent.php index c5b17ddef..b1323bc68 100644 --- a/app/Entities/Tools/PageContent.php +++ b/app/Entities/Tools/PageContent.php @@ -149,15 +149,17 @@ class PageContent /** * Parse a base64 image URI into the data and extension. + * * @return array{extension: array, data: string} */ protected function parseBase64ImageUri(string $uri): array { [$dataDefinition, $base64ImageData] = explode(',', $uri, 2); $extension = strtolower(preg_split('/[\/;]/', $dataDefinition)[1] ?? ''); + return [ 'extension' => $extension, - 'data' => base64_decode($base64ImageData) ?: '', + 'data' => base64_decode($base64ImageData) ?: '', ]; } diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php index 477640b0a..c08247dad 100644 --- a/app/Http/Controllers/AttachmentController.php +++ b/app/Http/Controllers/AttachmentController.php @@ -173,6 +173,7 @@ class AttachmentController extends Controller /** * Get the attachments for a specific page. + * * @throws NotFoundException */ public function listForPage(int $pageId) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 3bccdcda4..d63280a23 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -6,7 +6,6 @@ use BookStack\Facades\Activity; use BookStack\Interfaces\Loggable; use BookStack\Model; use BookStack\Util\WebSafeMimeSniffer; -use finfo; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Http\Exceptions\HttpResponseException; @@ -130,8 +129,7 @@ abstract class Controller extends BaseController */ protected function inlineDownloadResponse(string $content, string $fileName): Response { - - $mime = (new WebSafeMimeSniffer)->sniff($content); + $mime = (new WebSafeMimeSniffer())->sniff($content); return response()->make($content, 200, [ 'Content-Type' => $mime, diff --git a/app/Providers/CustomValidationServiceProvider.php b/app/Providers/CustomValidationServiceProvider.php index c2c0197c7..ac95099cc 100644 --- a/app/Providers/CustomValidationServiceProvider.php +++ b/app/Providers/CustomValidationServiceProvider.php @@ -15,6 +15,7 @@ class CustomValidationServiceProvider extends ServiceProvider { Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) { $extension = strtolower($value->getClientOriginalExtension()); + return ImageService::isExtensionSupported($extension); }); diff --git a/app/Uploads/ImageRepo.php b/app/Uploads/ImageRepo.php index 67297f308..5c6228b37 100644 --- a/app/Uploads/ImageRepo.php +++ b/app/Uploads/ImageRepo.php @@ -17,7 +17,8 @@ class ImageRepo /** * ImageRepo constructor. */ - public function __construct(ImageService $imageService, PermissionService $permissionService) { + public function __construct(ImageService $imageService, PermissionService $permissionService) + { $this->imageService = $imageService; $this->restrictionService = $permissionService; } diff --git a/app/Uploads/ImageService.php b/app/Uploads/ImageService.php index 0c3dfc47d..644269731 100644 --- a/app/Uploads/ImageService.php +++ b/app/Uploads/ImageService.php @@ -232,6 +232,7 @@ class ImageService * Get the thumbnail for an image. * If $keepRatio is true only the width will be used. * Checks the cache then storage to avoid creating / accessing the filesystem on every check. + * * @throws Exception * @throws InvalidArgumentException */ @@ -271,7 +272,7 @@ class ImageService { try { $thumb = $this->imageTool->make($imageData); - } catch (ErrorException | NotSupportedException $e) { + } catch (ErrorException|NotSupportedException $e) { throw new ImageUploadException(trans('errors.cannot_create_thumbs')); } @@ -452,6 +453,7 @@ class ImageService public function streamImageFromStorageResponse(string $imageType, string $path): StreamedResponse { $disk = $this->getStorageDisk($imageType); + return $disk->response($path); } diff --git a/app/Util/WebSafeMimeSniffer.php b/app/Util/WebSafeMimeSniffer.php index a896bd9e5..4012004fc 100644 --- a/app/Util/WebSafeMimeSniffer.php +++ b/app/Util/WebSafeMimeSniffer.php @@ -10,7 +10,6 @@ use finfo; */ class WebSafeMimeSniffer { - /** * @var string[] */ @@ -61,5 +60,4 @@ class WebSafeMimeSniffer return 'application/octet-stream'; } - -} \ No newline at end of file +} diff --git a/tests/Auth/MfaVerificationTest.php b/tests/Auth/MfaVerificationTest.php index ee6f3ecc8..49ca6663d 100644 --- a/tests/Auth/MfaVerificationTest.php +++ b/tests/Auth/MfaVerificationTest.php @@ -242,7 +242,7 @@ class MfaVerificationTest extends TestCase } /** - * @return Array + * @return array */ protected function startTotpLogin(): array { @@ -260,7 +260,7 @@ class MfaVerificationTest extends TestCase } /** - * @return Array + * @return array */ protected function startBackupCodeLogin($codes = ['kzzu6-1pgll', 'bzxnf-plygd', 'bwdsp-ysl51', '1vo93-ioy7n', 'lf7nw-wdyka', 'xmtrd-oplac']): array { diff --git a/tests/Entity/PageContentTest.php b/tests/Entity/PageContentTest.php index 049b47f0e..d3a00ebde 100644 --- a/tests/Entity/PageContentTest.php +++ b/tests/Entity/PageContentTest.php @@ -614,7 +614,6 @@ class PageContentTest extends TestCase $page->refresh(); $this->assertStringContainsString('html); } - } public function test_base64_images_get_extracted_from_markdown_page_content() diff --git a/tests/Uploads/AttachmentTest.php b/tests/Uploads/AttachmentTest.php index 1682577bf..abd7ca616 100644 --- a/tests/Uploads/AttachmentTest.php +++ b/tests/Uploads/AttachmentTest.php @@ -9,7 +9,6 @@ use BookStack\Uploads\Attachment; use BookStack\Uploads\AttachmentService; use Illuminate\Http\UploadedFile; use Tests\TestCase; -use Tests\TestResponse; class AttachmentTest extends TestCase { @@ -56,6 +55,7 @@ class AttachmentTest extends TestCase $upload = new UploadedFile($filePath, $filename, $mimeType, null, true); $this->call('POST', '/attachments/upload', ['uploaded_to' => $page->id], [], ['file' => $upload], []); + return $page->attachments()->latest()->firstOrFail(); } @@ -340,5 +340,4 @@ class AttachmentTest extends TestCase $this->deleteUploads(); } - }