/**
* Delete a comment from the system.
*/
- public function delete(Comment $comment)
+ public function delete(Comment $comment): void
{
$comment->delete();
}
/**
- * Convert the given comment markdown text to HTML.
+ * Convert the given comment Markdown to HTML.
*/
public function commentToHtml(string $commentText): string
{
'file' => 'required|file',
]);
+ /** @var Attachment $attachment */
$attachment = Attachment::query()->findOrFail($attachmentId);
$this->checkOwnablePermission('view', $attachment->page);
$this->checkOwnablePermission('page-update', $attachment->page);
/**
* Get the update form for an attachment.
- *
- * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function getUpdateForm(string $attachmentId)
{
+ /** @var Attachment $attachment */
$attachment = Attachment::query()->findOrFail($attachmentId);
$this->checkOwnablePermission('page-update', $attachment->page);
/**
* Get the attachments for a specific page.
+ * @throws NotFoundException
*/
public function listForPage(int $pageId)
{
public function getAsBase64($id)
{
$image = $this->imageRepo->getById($id);
- $page = $image->getPage();
- if ($image === null || $image->type !== 'drawio' || !userCan('page-view', $page)) {
+ if (is_null($image) || $image->type !== 'drawio' || !userCan('page-view', $image->getPage())) {
return $this->jsonError('Image data could not be found');
}
$imageData = $this->imageRepo->getImageData($image);
- if ($imageData === null) {
+ if (is_null($imageData)) {
return $this->jsonError('Image data could not be found');
}
/**
* ImageRepo constructor.
*/
- public function __construct(
- ImageService $imageService,
- PermissionService $permissionService
- ) {
+ public function __construct(ImageService $imageService, PermissionService $permissionService) {
$this->imageService = $imageService;
$this->restrictionService = $permissionService;
}
$hasMore = count($images) > $pageSize;
$returnImages = $images->take($pageSize);
- $returnImages->each(function ($image) {
+ $returnImages->each(function (Image $image) {
$this->loadThumbs($image);
});
int $uploadedTo = null,
string $search = null
): array {
+ /** @var Page $contextPage */
$contextPage = Page::visible()->findOrFail($uploadedTo);
$parentFilter = null;
*
* @throws ImageUploadException
*/
- public function saveNewFromData(string $imageName, string $imageData, string $type, int $uploadedTo = 0)
+ public function saveNewFromData(string $imageName, string $imageData, string $type, int $uploadedTo = 0): Image
{
$image = $this->imageService->saveNew($imageName, $imageData, $type, $uploadedTo);
$this->loadThumbs($image);
}
/**
- * Save a drawing the the database.
+ * Save a drawing in the database.
*
* @throws ImageUploadException
*/
public function saveDrawing(string $base64Uri, int $uploadedTo): Image
{
- $name = 'Drawing-' . strval(user()->id) . '-' . strval(time()) . '.png';
+ $name = 'Drawing-' . user()->id . '-' . time() . '.png';
return $this->imageService->saveNewFromBase64Uri($base64Uri, $name, 'drawio', $uploadedTo);
}
/**
* Update the details of an image via an array of properties.
*
- * @throws ImageUploadException
* @throws Exception
*/
public function updateImageDetails(Image $image, $updateDetails): Image
*
* @throws Exception
*/
- public function destroyImage(Image $image = null): bool
+ public function destroyImage(Image $image = null): void
{
if ($image) {
$this->imageService->destroy($image);
}
-
- return true;
}
/**
*
* @throws Exception
*/
- public function destroyByType(string $imageType)
+ public function destroyByType(string $imageType): void
{
$images = Image::query()->where('type', '=', $imageType)->get();
foreach ($images as $image) {
/**
* Load thumbnails onto an image object.
- *
- * @throws Exception
*/
- public function loadThumbs(Image $image)
+ public function loadThumbs(Image $image): void
{
$image->setAttribute('thumbs', [
'gallery' => $this->getThumbnail($image, 150, 150, false),
* 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
*/
- protected function getThumbnail(Image $image, ?int $width = 220, ?int $height = 220, bool $keepRatio = false): ?string
+ protected function getThumbnail(Image $image, ?int $width, ?int $height, bool $keepRatio): ?string
{
try {
return $this->imageService->getThumbnail($image, $width, $height, $keepRatio);
use Intervention\Image\Exception\NotSupportedException;
use Intervention\Image\ImageManager;
use League\Flysystem\Util;
+use Log;
+use Psr\SimpleCache\InvalidArgumentException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\StreamedResponse;
try {
$this->saveImageDataInPublicSpace($storage, $this->adjustPathForStorageDisk($fullPath, $type), $imageData);
} catch (Exception $e) {
- \Log::error('Error when attempting image upload:' . $e->getMessage());
+ Log::error('Error when attempting image upload:' . $e->getMessage());
throw new ImageUploadException(trans('errors.path_not_writable', ['filePath' => $fullPath]));
}
* 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.
- *
- * @param Image $image
- * @param int $width
- * @param int $height
- * @param bool $keepRatio
- *
* @throws Exception
- * @throws ImageUploadException
- *
- * @return string
+ * @throws InvalidArgumentException
*/
- public function getThumbnail(Image $image, $width = 220, $height = 220, $keepRatio = false)
+ public function getThumbnail(Image $image, ?int $width, ?int $height, bool $keepRatio = false): string
{
if ($keepRatio && $this->isGif($image)) {
return $this->getPublicUrl($image->path);
}
/**
- * Resize image data.
- *
- * @param string $imageData
- * @param int $width
- * @param int $height
- * @param bool $keepRatio
+ * Resize the image of given data to the specified size, and return the new image data.
*
* @throws ImageUploadException
- *
- * @return string
*/
- protected function resizeImage(string $imageData, $width = 220, $height = null, bool $keepRatio = true)
+ protected function resizeImage(string $imageData, ?int $width, ?int $height, bool $keepRatio): string
{
try {
$thumb = $this->imageTool->make($imageData);
- } catch (Exception $e) {
- if ($e instanceof ErrorException || $e instanceof NotSupportedException) {
- throw new ImageUploadException(trans('errors.cannot_create_thumbs'));
- }
-
- throw $e;
+ } catch (ErrorException | NotSupportedException $e) {
+ throw new ImageUploadException(trans('errors.cannot_create_thumbs'));
}
if ($keepRatio) {
*/
private function getPublicUrl(string $filePath): string
{
- if ($this->storageUrl === null) {
+ if (is_null($this->storageUrl)) {
$storageUrl = config('filesystems.url');
// Get the standard public s3 url if s3 is set as storage type
$storageUrl = 'https://s3-' . $storageDetails['region'] . '.amazonaws.com/' . $storageDetails['bucket'];
}
}
+
$this->storageUrl = $storageUrl;
}