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

Image::getSizes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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 1
    public function getSizes()
62
    {
63 1
        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 1
    public function addSize($width, $height)
77
    {
78 1
        $this->sizes[] = [ (int)$width, (int)$height ];
79 1
        return $this;
80
    }
81
82
    /**
83
     * Returns the source path of this file.
84
     *
85
     * @return  string|null
86
     */
87 1
    public function getSrc()
88
    {
89 1
        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 1
    public function setSrc($src)
102
    {
103 1
        $this->src = $src;
104 1
        return $this;
105
    }
106
107
    /**
108
     * Returns the MIME type of this file.
109
     *
110
     * @return  string|null
111
     */
112 1
    public function getType()
113
    {
114 1
        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 1
    public function setType($type)
127
    {
128 1
        $this->type = $type;
129 1
        return $this;
130
    }
131
}
132