ArtificerImage::store()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 19
rs 9.2
cc 4
eloc 10
nc 8
nop 3
1
<?php namespace Mascame\Artificer;
2
3
use File;
4
5
class ArtificerImage
6
{
7
8
    public $image;
9
10
//	public function __construct(\Intervention\Image\Image $image) {
11
//		$this->image = $image;
12
//	}
13
14
    public static function store(\Intervention\Image\Image $image, $path = null, $quality = null)
15
    {
16
        if (!$path) {
17
            $pathinfo = pathinfo($path);
18
            $path = $pathinfo['dirname'];
19
        }
20
21
        if (!file_exists($path)) {
22
            File::makeDirectory($path, 0777, true, true);
23
        }
24
25
        $filename = $path . $image->filename . '.' . $image->extension;
26
27
        if (!file_exists($filename)) {
28
            return $image->save($filename, $quality);
29
        }
30
31
        return false;
32
    }
33
34
    public static function get($image, $layout)
35
    {
36
        return 'uploads/' . $layout . '/' . $image;
37
    }
38
39
    public static function path($image, $layout)
40
    {
41
        return public_path() . 'uploads/' . $layout . '/' . $image;
42
    }
43
44
}