Completed
Push — master ( f4ebcb...ba1f71 )
by Henry
02:12
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
/**
3
 * This file is part of the Divergence package.
4
 *
5
 * @author Henry Paradiz <[email protected]>
6
 * @copyright 2018 Henry Paradiz <[email protected]>
7
 * @license MIT For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
8
 *
9
 * @since 1.1
10
 */
11
namespace Divergence\Models\Media;
12
13
use Exception;
14
15
/**
16
 * Image Media Model
17
 *
18
 * @author Henry Paradiz <[email protected]>
19
 * @author Chris Alfano <[email protected]>
20
 *
21
 * {@inheritDoc}
22
 */
23
class Image extends Media
24
{
25
    // configurables
26
    public static $jpegCompression = 90;
27
28
    public function getValue($name)
29
    {
30
        switch ($name) {
31
            case 'ThumbnailMIMEType':
32
                switch ($this->MIMEType) {
33
                    case 'application/psd':
34
                        return 'image/png';
35
                    case 'image/tiff':
36
                        return 'image/jpeg';
37
                    default:
38
                        return $this->MIMEType;
39
                }
40
41
                // no break
42
            case 'Extension':
43
44
                switch ($this->MIMEType) {
45
                    case 'application/psd':
46
                        return 'psd';
47
48
                    case 'image/tiff':
49
                        return 'tif';
50
51
                    case 'image/gif':
52
                        return 'gif';
53
54
                    case 'image/jpeg':
55
                        return 'jpg';
56
57
                    case 'image/png':
58
                        return 'png';
59
60
                    default:
61
                        throw new Exception('Unable to find photo extension for mime-type: '.$this->MIMEType);
62
                }
63
64
                // no break
65
            default:
66
                return parent::getValue($name);
67
        }
68
    }
69
70
71
    // public methods
72
73
74
    // static methods
75
    public static function analyzeFile($filename, $mediaInfo = [])
76
    {
77
        if (!$mediaInfo['imageInfo'] = @getimagesize($filename)) {
78
            throw new Exception('Failed to read image file information');
79
        }
80
81
        // store image data
82
        $mediaInfo['width'] = $mediaInfo['imageInfo'][0];
83
        $mediaInfo['height'] = $mediaInfo['imageInfo'][1];
84
        $mediaInfo['duration'] = 0;
85
86
        return $mediaInfo;
87
    }
88
}
89