Passed
Push — master ( d8574a...8cadc1 )
by David
02:55
created

ImageMetadata::setSpecificAttribute()   C

Complexity

Conditions 12
Paths 13

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 28
rs 6.9666
cc 12
nc 13
nop 2

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
     * @return \Vaites\ApacheTika\Metadata\MetadataInterface
37
     */
38
    protected function setSpecificAttribute(string $key, $value): MetadataInterface
39
    {
40
        switch(mb_strtolower($key))
41
        {
42
            case 'compression':
43
            case 'compression lossless':
44
                $this->lossless = ($value == 'true' || $value == 'Uncompressed');
45
                break;
46
47
            case 'height':
48
            case 'image height':
49
            case 'tiff:imageheigth':
50
            case 'tiff:imagelength':
51
                $this->height = (int) $value;
52
                break;
53
54
            case 'width':
55
            case 'image width':
56
            case 'tiff:imagewidth':
57
                $this->width = (int) $value;
58
                break;
59
60
            case 'x-tika:content':
61
                $this->content = $value;
62
                break;
63
        }
64
65
        return $this;
66
    }
67
}
68