mostafaznv /
larupload
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Mostafaznv\Larupload\Concerns\Standalone; |
||||||
| 4 | |||||||
| 5 | |||||||
| 6 | use Illuminate\Http\UploadedFile; |
||||||
| 7 | use Illuminate\Support\Facades\Storage; |
||||||
| 8 | use Mostafaznv\Larupload\Actions\GuessLaruploadFileTypeAction; |
||||||
| 9 | use Mostafaznv\Larupload\Actions\OptimizeImageAction; |
||||||
| 10 | |||||||
| 11 | trait BaseStandaloneLarupload |
||||||
| 12 | { |
||||||
| 13 | public function upload(UploadedFile $file, ?UploadedFile $cover = null): object |
||||||
| 14 | { |
||||||
| 15 | $this->internalFunctionIsCallable = true; |
||||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||||
| 16 | |||||||
| 17 | file_is_valid($file, $this->name, 'file'); |
||||||
| 18 | file_is_valid($cover, $this->name, 'cover'); |
||||||
| 19 | |||||||
| 20 | $this->file = $this->optimizeImage ? OptimizeImageAction::make($file)->process() : $file; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 21 | $this->type = GuessLaruploadFileTypeAction::make($file)->calc(); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 22 | $this->cover = $cover; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 23 | |||||||
| 24 | $this->clean($this->id); |
||||||
|
0 ignored issues
–
show
It seems like
clean() 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
Loading history...
|
|||||||
| 25 | $this->setBasicDetails(); |
||||||
|
0 ignored issues
–
show
It seems like
setBasicDetails() 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
Loading history...
|
|||||||
| 26 | $this->setMediaDetails(); |
||||||
|
0 ignored issues
–
show
It seems like
setMediaDetails() 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
Loading history...
|
|||||||
| 27 | $this->uploadOriginalFile($this->id); |
||||||
|
0 ignored issues
–
show
The method
uploadOriginalFile() does not exist on Mostafaznv\Larupload\Con...BaseStandaloneLarupload. Did you maybe mean upload()?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 28 | $this->setCover($this->id); |
||||||
|
0 ignored issues
–
show
It seems like
setCover() 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
Loading history...
|
|||||||
| 29 | $this->handleStyles($this->id, self::class, true); |
||||||
|
0 ignored issues
–
show
It seems like
handleStyles() 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
Loading history...
|
|||||||
| 30 | $urls = $this->urls(); |
||||||
|
0 ignored issues
–
show
It seems like
urls() 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
Loading history...
|
|||||||
| 31 | |||||||
| 32 | $this->updateMeta($urls); |
||||||
| 33 | |||||||
| 34 | return $urls; |
||||||
| 35 | } |
||||||
| 36 | |||||||
| 37 | public function delete(): bool |
||||||
| 38 | { |
||||||
| 39 | $basePath = $this->getBasePath($this->id); |
||||||
|
0 ignored issues
–
show
It seems like
getBasePath() 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
Loading history...
|
|||||||
| 40 | |||||||
| 41 | if (Storage::disk($this->disk)->exists($basePath)) { |
||||||
| 42 | $this->clean($this->id); |
||||||
| 43 | |||||||
| 44 | return true; |
||||||
| 45 | } |
||||||
| 46 | |||||||
| 47 | return false; |
||||||
| 48 | } |
||||||
| 49 | |||||||
| 50 | private function updateMeta(?object $urls = null): void |
||||||
| 51 | { |
||||||
| 52 | if (is_null($urls)) { |
||||||
| 53 | $urls = $this->urls(); |
||||||
| 54 | } |
||||||
| 55 | |||||||
| 56 | $metaPath = $this->getBasePath($this->id) . '/.meta'; |
||||||
| 57 | Storage::disk($this->disk)->put($metaPath, json_encode($urls), 'private'); |
||||||
| 58 | } |
||||||
| 59 | |||||||
| 60 | /** |
||||||
| 61 | * Check if .meta file exists |
||||||
| 62 | * |
||||||
| 63 | * @return bool |
||||||
| 64 | */ |
||||||
| 65 | private function metaExists(): bool |
||||||
| 66 | { |
||||||
| 67 | $metaPath = $this->getBasePath($this->id) . '/.meta'; |
||||||
| 68 | |||||||
| 69 | if (Storage::disk($this->disk)->exists($metaPath)) { |
||||||
| 70 | $meta = Storage::disk($this->disk)->get($metaPath); |
||||||
| 71 | $meta = json_decode($meta); |
||||||
|
0 ignored issues
–
show
It seems like
$meta can also be of type null; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 72 | |||||||
| 73 | foreach ($meta->meta as $key => $value) { |
||||||
| 74 | $this->output[$key] = $value; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 75 | } |
||||||
| 76 | |||||||
| 77 | return true; |
||||||
| 78 | } |
||||||
| 79 | |||||||
| 80 | return false; |
||||||
| 81 | } |
||||||
| 82 | } |
||||||
| 83 |