Image   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 22
c 2
b 1
f 0
dl 0
loc 80
rs 10
wmc 14

4 Methods

Rating   Name   Duplication   Size   Complexity  
A url_to() 0 10 3
B thumbnails() 0 26 9
A getThumbnailsAttribute() 0 3 1
A url() 0 3 1
1
<?php
2
3
namespace OkayBueno\Images\Models;
4
5
use Illuminate\Database\Eloquent\SoftDeletes;
6
use Illuminate\Database\Eloquent\Model;
7
8
/**
9
 * Class Image
10
 * @package OkayBueno\Images\Models
11
 */
12
class Image extends Model
13
{
14
    use SoftDeletes;
15
16
    protected $fillable = [
17
        'path', 'filename', 'type', 'thumbnails', 'metadata', 'processed'
18
    ];
19
20
21
    /*******************************************************************************************************************
22
     ************************************************** HELPERS / DATA *************************************************
23
     *******************************************************************************************************************/
24
    /**
25
     * @param null $size
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $size is correct as it would always require null to be passed?
Loading history...
26
     * @param bool|FALSE $onlyPath
27
     * @return array|null|string
28
     */
29
    public function thumbnails( $size = NULL, $onlyPath = FALSE )
30
    {
31
        $sizesArray = [];
32
33
        if ( is_null( $size ) )
0 ignored issues
show
introduced by
The condition is_null($size) is always true.
Loading history...
34
        {
35
            if ( is_array( $this->thumbnails ) )
36
            {
37
                foreach( $this->thumbnails as $sizeKey => $path )
38
                {
39
                    $sizesArray[ $sizeKey ] = $onlyPath ? $path : $this->url_to( $path );
40
                }
41
            }
42
43
        } else
44
        {
45
            if ( is_array( $this->thumbnails) )
46
            {
47
                foreach( $this->thumbnails as $sizeKey => $path )
48
                {
49
                    if( $size == $sizeKey ) return $onlyPath ? $path : $this->url_to( $path );
50
                }
51
            }
52
        }
53
54
        return $sizesArray;
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function url()
61
    {
62
        return $this->url_to( $this->path );
0 ignored issues
show
Bug introduced by
The property path does not seem to exist on OkayBueno\Images\Models\Image. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
63
    }
64
65
    /*******************************************************************************************************************
66
     **************************************************** INTERNAL *****************************************************
67
     *******************************************************************************************************************/
68
69
    /**
70
     * @param $value
71
     * @return mixed
72
     */
73
    public function getThumbnailsAttribute( $value )
74
    {
75
        return json_decode( $value, TRUE );
76
    }
77
78
    /**
79
     * @param $path
80
     * @return string
81
     */
82
    protected function url_to( $path )
83
    {
84
        $localUrl = config('images.local_disk_url');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

84
        $localUrl = /** @scrutinizer ignore-call */ config('images.local_disk_url');
Loading history...
85
        $remoteUrl = config('images.cloud_disk_url');
86
        if ( $this->processed ) $cdnBaseUrl = $remoteUrl ? $remoteUrl : $localUrl;
0 ignored issues
show
Bug introduced by
The property processed does not seem to exist on OkayBueno\Images\Models\Image. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
87
        else $cdnBaseUrl = $localUrl;
88
89
        $cdnUrlToImage = rtrim( $cdnBaseUrl, '/') . '/' . trim( $path, '/');
90
91
        return $cdnUrlToImage;
92
    }
93
94
95
}
96