Completed
Pull Request — master (#7)
by Fabian
02:04
created

Image   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 2
cbo 0
dl 0
loc 111
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getPurpose() 0 4 1
A addPurpose() 0 5 1
A getSizes() 0 4 1
A addSize() 0 5 1
A getSrc() 0 4 1
A setSrc() 0 5 1
A getType() 0 4 1
A setType() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the fusonic/webapp package.
5
 *
6
 * (c) Fusonic GmbH <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Fusonic\WebApp\Objects;
13
14
/**
15
 * Represents an <b>image object</b>.
16
 *
17
 * @package Fusonic\WebApp
18
 *
19
 * @see https://www.w3.org/TR/appmanifest/#image-object-and-its-members
20
 */
21
final class Image
22
{
23
    const PURPOSE_BADGE = "badge";
24
    const PURPOSE_ANY = "any";
25
26
    private $purpose = [ ];
27
    private $sizes = [ ];
28
    private $src;
29
    private $type;
30
31
    /**
32
     * Returns the image's intended purpose.
33
     *
34
     * @return  string[]
35
     */
36
    public function getPurpose()
37
    {
38
        return array_values($this->purpose);
39
    }
40
41
    /**
42
     * Adds a purpose for this image.
43
     *
44
     * @param   string              $purpose            One of of Image::PURPOSE_* constants.
45
     *
46
     * @return  Image
47
     *
48
     * @see https://www.w3.org/TR/appmanifest/#purpose-member
49
     */
50
    public function addPurpose($purpose)
51
    {
52
        $this->purpose[$purpose] = $purpose;
53
        return $this;
54
    }
55
56
    /**
57
     * Returns an array of sizes contained in this file.
58
     *
59
     * @return  array[]
60
     */
61
    public function getSizes()
62
    {
63
        return $this->sizes;
64
    }
65
66
    /**
67
     * Adds an additional size contained in this file.
68
     *
69
     * @param   int                 $width
70
     * @param   int                 $height
71
     *
72
     * @return  Image
73
     *
74
     * @see https://www.w3.org/TR/appmanifest/#sizes-member
75
     */
76
    public function addSize($width, $height)
77
    {
78
        $this->sizes[] = [ (int)$width, (int)$height ];
79
        return $this;
80
    }
81
82
    /**
83
     * Returns the source path of this file.
84
     *
85
     * @return  string|null
86
     */
87
    public function getSrc()
88
    {
89
        return $this->src;
90
    }
91
92
    /**
93
     * Sets the source path of this file.
94
     *
95
     * @param   string|null         $src
96
     *
97
     * @return  Image
98
     *
99
     * @see https://www.w3.org/TR/appmanifest/#src-member
100
     */
101
    public function setSrc($src)
102
    {
103
        $this->src = $src;
104
        return $this;
105
    }
106
107
    /**
108
     * Returns the MIME type of this file.
109
     *
110
     * @return  string|null
111
     */
112
    public function getType()
113
    {
114
        return $this->type;
115
    }
116
117
    /**
118
     * Sets the MIME type of this file.
119
     *
120
     * @param   string              $type
121
     *
122
     * @return  Image
123
     *
124
     * @see https://www.w3.org/TR/appmanifest/#type-member
125
     */
126
    public function setType($type)
127
    {
128
        $this->type = $type;
129
        return $this;
130
    }
131
}
132