UploadEntityResponse::withMeta()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Mostafaznv\Larupload\Concerns\Storage\UploadEntity;
4
5
6
use Illuminate\Http\RedirectResponse;
7
use Illuminate\Support\Facades\Storage;
8
use Mostafaznv\Larupload\UploadEntities;
9
use Symfony\Component\HttpFoundation\StreamedResponse;
10
11
trait UploadEntityResponse
12
{
13
    /**
14
     * Specify whether Larupload should return meta values on getAttribute or not.
15
     */
16
    protected bool $withMeta;
17
18
    /**
19
     * Specify whether Larupload should return responses in camel-case or not.
20
     */
21
    protected bool $camelCaseResponse;
22
23
24
    public function withMeta(bool $status): UploadEntities
25
    {
26
        $this->withMeta = $status;
27
28
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mostafaznv\Larupload\Con...ty\UploadEntityResponse which includes types incompatible with the type-hinted return Mostafaznv\Larupload\UploadEntities.
Loading history...
29
    }
30
31
    protected function storageUrl(string $path): ?string
32
    {
33
        if (isset($this->file) and $this->file == LARUPLOAD_NULL) {
34
            return null;
35
        }
36
37
        if ($this->driverIsLocal()) {
0 ignored issues
show
Bug introduced by
It seems like driverIsLocal() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        if ($this->/** @scrutinizer ignore-call */ driverIsLocal()) {
Loading history...
38
            $url = Storage::disk($this->disk)->url($path);
39
40
            return url($url);
41
        }
42
43
        $baseUrl = config("filesystems.disks.$this->disk.url");
44
45
        if ($baseUrl) {
46
            return "$baseUrl/$path";
47
        }
48
49
        return $path;
50
    }
51
52
    protected function storageDownload(string $path): StreamedResponse|RedirectResponse|null
53
    {
54
        if (isset($this->file) and $this->file == LARUPLOAD_NULL) {
55
            return null;
56
        }
57
58
        if ($this->driverIsLocal()) {
59
            return Storage::disk($this->disk)->download($path);
60
        }
61
62
        $baseUrl = config("filesystems.disks.$this->disk.url");
63
64
        if ($baseUrl) {
65
            return redirect("$baseUrl/$path");
66
        }
67
68
        return null;
69
    }
70
}
71