GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( f4fa04...7bcf2a )
by Pascal
02:48
created

ConvertsBase64ToFiles::base64FileKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ProtoneMedia\LaravelMixins\Request;
4
5
use Illuminate\Http\UploadedFile;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\Str;
8
9
trait ConvertsBase64ToFiles
10
{
11
    protected function base64FileKeys(): array
12
    {
13
        return [];
14
    }
15
16
    /**
17
     * Pulls the Base64 contents for each image key and creates
18
     * an UploadedFile instance from it and sets it on the
19
     * request.
20
     *
21
     * @return void
22
     */
23
    protected function prepareForValidation()
24
    {
25
        Collection::make($this->base64FileKeys())->each(function ($filename, $key) {
26
            rescue(function () use ($key, $filename) {
27
                $base64Contents = $this->input($key);
0 ignored issues
show
Bug introduced by
It seems like input() 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

27
                /** @scrutinizer ignore-call */ 
28
                $base64Contents = $this->input($key);
Loading history...
28
29
                if (!$base64Contents) {
30
                    return;
31
                }
32
33
                // Generate a temporary path to store the Base64 contents
34
                $tempFilePath = tempnam(sys_get_temp_dir(), $filename);
35
36
                // Store the contents using a stream, or by decoding manually
37
                if (Str::startsWith($base64Contents, 'data:') && count(explode(',', $base64Contents)) > 1) {
38
                    $source = fopen($base64Contents, 'r');
39
                    $destination = fopen($tempFilePath, 'w');
40
41
                    stream_copy_to_stream($source, $destination);
0 ignored issues
show
Bug introduced by
It seems like $source can also be of type false; however, parameter $source of stream_copy_to_stream() does only seem to accept resource, 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

41
                    stream_copy_to_stream(/** @scrutinizer ignore-type */ $source, $destination);
Loading history...
Bug introduced by
It seems like $destination can also be of type false; however, parameter $dest of stream_copy_to_stream() does only seem to accept resource, 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

41
                    stream_copy_to_stream($source, /** @scrutinizer ignore-type */ $destination);
Loading history...
42
43
                    fclose($source);
0 ignored issues
show
Bug introduced by
It seems like $source can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, 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

43
                    fclose(/** @scrutinizer ignore-type */ $source);
Loading history...
44
                    fclose($destination);
45
                } else {
46
                    file_put_contents($tempFilePath, base64_decode($base64Contents, true));
47
                }
48
49
                $uploadedFile = new UploadedFile($tempFilePath, $filename, null, null, true);
50
51
                $this->request->remove($key);
52
                $this->files->set($key, $uploadedFile);
53
            }, null, false);
54
        });
55
    }
56
}
57