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

ImageMetadata   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 12

1 Method

Rating   Name   Duplication   Size   Complexity  
C setAttribute() 0 31 12
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