Issues (177)

Concerns/Standalone/BaseStandaloneLarupload.php (14 issues)

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
The property internalFunctionIsCallable does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
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
Bug Best Practice introduced by
The property file does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
        $this->type = GuessLaruploadFileTypeAction::make($file)->calc();
0 ignored issues
show
Bug Best Practice introduced by
The property type does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
        $this->cover = $cover;
0 ignored issues
show
Bug Best Practice introduced by
The property cover does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
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 ignore-call  annotation

24
        $this->/** @scrutinizer ignore-call */ 
25
               clean($this->id);
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 ignore-call  annotation

25
        $this->/** @scrutinizer ignore-call */ 
26
               setBasicDetails();
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 ignore-call  annotation

26
        $this->/** @scrutinizer ignore-call */ 
27
               setMediaDetails();
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 ignore-call  annotation

27
        $this->/** @scrutinizer ignore-call */ 
28
               uploadOriginalFile($this->id);

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 ignore-call  annotation

28
        $this->/** @scrutinizer ignore-call */ 
29
               setCover($this->id);
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 ignore-call  annotation

29
        $this->/** @scrutinizer ignore-call */ 
30
               handleStyles($this->id, self::class, true);
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 ignore-call  annotation

30
        /** @scrutinizer ignore-call */ 
31
        $urls = $this->urls();
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 ignore-call  annotation

39
        /** @scrutinizer ignore-call */ 
40
        $basePath = $this->getBasePath($this->id);
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 ignore-type  annotation

71
            $meta = json_decode(/** @scrutinizer ignore-type */ $meta);
Loading history...
72
73
            foreach ($meta->meta as $key => $value) {
74
                $this->output[$key] = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property output does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
75
            }
76
77
            return true;
78
        }
79
80
        return false;
81
    }
82
}
83