Passed
Push — master ( daf5ec...c13cfb )
by David
01:33
created

ImageMetadata::setAttribute()   C

Complexity

Conditions 12
Paths 13

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 22
nc 13
nop 2
dl 0
loc 31
rs 6.9666
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
namespace Vaites\ApacheTika\Metadata;
4
5
/**
6
 * Metadata class for images
7
 *
8
 * @author  David Martínez <[email protected]>
9
 */
10
class ImageMetadata extends Metadata
11
{
12
    /**
13
     * Image width in pixels
14
     *
15
     * @var int
16
     */
17
    public $width = 0;
18
19
    /**
20
     * Image height in pixels
21
     *
22
     * @var int
23
     */
24
    public $height = 0;
25
26
    /**
27
     * Lossy/Lossless.
28
     *
29
     * @var bool
30
     */
31
    public $lossless = true;
32
33
    /**
34
     * Sets an attribute
35
     *
36
     * @param string $key
37
     * @param mixed  $value
38
     *
39
     * @return bool
40
     */
41
    protected function setAttribute($key, $value)
42
    {
43
        switch(mb_strtolower($key))
44
        {
45
            case 'compression':
46
            case 'compression lossless':
47
                $this->lossless = ($value == 'true' || $value == 'Uncompressed');
48
                break;
49
50
            case 'height':
51
            case 'image height':
52
            case 'tiff:imageheigth':
53
            case 'tiff:imagelength':
54
                $this->height = (int) $value;
55
                break;
56
57
            case 'width':
58
            case 'image width':
59
            case 'tiff:imagewidth':
60
                $this->width = (int) $value;
61
                break;
62
63
            case 'x-tika:content':
64
                $this->content = $value;
65
                break;
66
67
            default:
68
                return false;
69
        }
70
71
        return true;
72
    }
73
}
74