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.

ImageHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUniqueNameFromUrl() 0 3 1
A imageUrlValidation() 0 10 2
A imageSizeValidation() 0 9 2
1
<?php
2
3
namespace App\Platforms\Traits;
4
5
6
use finfo;
7
use Illuminate\Support\Facades\Storage;
8
9
/**
10
 * Trait ImageHelper
11
 *
12
 * Share the methods related to image between the two platforms
13
 *
14
 * @package App\Platforms\Traits
15
 */
16
trait ImageHelper
17
{
18
    /**
19
     * Since Twitter & Petitesannonces share the same supported mime types, we can leave it here
20
     *
21
     * @var array
22
     */
23
    protected $supportedMimeTypes = [
24
        'image/jpeg',
25
        'image/png',
26
        'image/gif',
27
    ];
28
29
    /**
30
     * @param $imageName
31
     * @throws \Exception
32
     */
33
    protected function imageSizeValidation($imageName)
34
    {
35
        if (Storage::size($imageName) > self::MAX_IMAGE_UPLOAD_SIZE) {
0 ignored issues
show
Bug introduced by
The constant App\Platforms\Traits\Ima...::MAX_IMAGE_UPLOAD_SIZE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
36
            Storage::delete($imageName);
37
            throw new \Exception(
38
                sprintf(
39
                    "La taille de l'image ne doit pas excéder %d %s",
40
                    self::MAX_IMAGE_UPLOAD_SIZE / pow(1024, 2),
41
                    'Mo'
42
                )
43
            );
44
        }
45
    }
46
47
    /**
48
     * @param string $imageUrl
49
     * @throws \Exception
50
     */
51
    protected function imageUrlValidation($imageUrl)
52
    {
53
        $fileInfo = new finfo(FILEINFO_MIME_TYPE);
54
        $mimeType = $fileInfo->buffer(file_get_contents($imageUrl));
55
56
        if (!in_array($mimeType, $this->supportedMimeTypes)) {
57
            throw new \Exception(
58
                sprintf(
59
                    'Type de fichier non supporté. Types supportés : [%s]',
60
                    str_replace('image/', '', implode(', ', $this->supportedMimeTypes))
61
                )
62
            );
63
        }
64
    }
65
66
    /**
67
     * @param $imageUrl
68
     * @return string
69
     */
70
    protected function getUniqueNameFromUrl($imageUrl)
71
    {
72
        return uniqid() . '_' . substr($imageUrl, strrpos($imageUrl, '/') + 1);
73
    }
74
}
75