Completed
Push — master ( f8ff86...ec22b1 )
by Henry
03:57
created

Image::getValue()   B

Complexity

Conditions 10
Paths 10

Size

Total Lines 39
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 25
nc 10
nop 1
dl 0
loc 39
rs 7.6666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Divergence\Models\Media;
3
4
use Exception;
5
6
class Image extends Media
7
{
8
    // configurables
9
    public static $jpegCompression = 90;
10
11
    // magic methods
12
    public static function __classLoaded()
13
    {
14
        $className = get_called_class();
15
16
        Media::$mimeHandlers['image/gif'] = $className;
17
        Media::$mimeHandlers['image/jpeg'] = $className;
18
        Media::$mimeHandlers['image/png'] = $className;
19
        Media::$mimeHandlers['image/tiff'] = $className;
20
        Media::$mimeHandlers['application/psd'] = $className;
21
22
        parent::__classLoaded();
0 ignored issues
show
introduced by
The method __classLoaded() does not exist on Divergence\Models\Media\Media. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

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

22
        parent::/** @scrutinizer ignore-call */ 
23
                __classLoaded();
Loading history...
23
    }
24
25
26
    public function getValue($name)
27
    {
28
        switch ($name) {
29
            case 'ThumbnailMIMEType':
30
                switch ($this->MIMEType) {
31
                    case 'application/psd':
32
                        return 'image/png';
33
                    case 'image/tiff':
34
                        return 'image/jpeg';
35
                    default:
36
                        return $this->MIMEType;
37
                }
38
39
                // no break
40
            case 'Extension':
41
42
                switch ($this->MIMEType) {
43
                    case 'application/psd':
44
                        return 'psd';
45
46
                    case 'image/tiff':
47
                        return 'tif';
48
49
                    case 'image/gif':
50
                        return 'gif';
51
52
                    case 'image/jpeg':
53
                        return 'jpg';
54
55
                    case 'image/png':
56
                        return 'png';
57
58
                    default:
59
                        throw new Exception('Unable to find photo extension for mime-type: '.$this->MIMEType);
60
                }
61
62
                // no break
63
            default:
64
                return parent::getValue($name);
65
        }
66
    }
67
68
69
    // public methods
70
71
72
    // static methods
73
    public static function analyzeFile($filename, $mediaInfo = [])
74
    {
75
        if (!$mediaInfo['imageInfo'] = @getimagesize($filename)) {
76
            throw new Exception('Failed to read image file information');
77
        }
78
79
        // store image data
80
        $mediaInfo['width'] = $mediaInfo['imageInfo'][0];
81
        $mediaInfo['height'] = $mediaInfo['imageInfo'][1];
82
        $mediaInfo['duration'] = 0;
83
84
        return $mediaInfo;
85
    }
86
}
87