Completed
Pull Request — master (#7)
by Fabian
02:20
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
use Fusonic\WebApp\Members\PlatformInterface;
15
use Fusonic\WebApp\Members\PlatformTrait;
16
17
/**
18
 * Represents an <b>image object</b>.
19
 *
20
 * @package Fusonic\WebApp
21
 *
22
 * @see https://www.w3.org/TR/appmanifest/#image-object-and-its-members
23
 */
24
final class Image implements PlatformInterface
25
{
26
    use PlatformTrait;
27
28
    const PURPOSE_BADGE = "badge";
29
    const PURPOSE_ANY = "any";
30
31
    private $purpose = [ ];
32
    private $sizes = [ ];
33
    private $src;
34
    private $type;
35
36
    /**
37
     * Returns the image's intended purpose.
38
     *
39
     * @return  string[]
40
     */
41
    public function getPurpose()
42
    {
43
        return array_values($this->purpose);
44
    }
45
46
    /**
47
     * Adds a purpose for this image.
48
     *
49
     * @param   string              $purpose            One of of Image::PURPOSE_* constants.
50
     *
51
     * @return  Image
52
     *
53
     * @see https://www.w3.org/TR/appmanifest/#purpose-member
54
     */
55
    public function addPurpose($purpose)
56
    {
57
        $this->purpose[$purpose] = $purpose;
58
        return $this;
59
    }
60
61
    /**
62
     * Returns an array of sizes contained in this file.
63
     *
64
     * @return  array[]
65
     */
66 1
    public function getSizes()
67
    {
68 1
        return $this->sizes;
69
    }
70
71
    /**
72
     * Adds an additional size contained in this file.
73
     *
74
     * @param   int                 $width
75
     * @param   int                 $height
76
     *
77
     * @return  Image
78
     *
79
     * @see https://www.w3.org/TR/appmanifest/#sizes-member
80
     */
81 1
    public function addSize($width, $height)
82
    {
83 1
        $this->sizes[] = [ (int)$width, (int)$height ];
84 1
        return $this;
85
    }
86
87
    /**
88
     * Returns the source path of this file.
89
     *
90
     * @return  string|null
91
     */
92 1
    public function getSrc()
93
    {
94 1
        return $this->src;
95
    }
96
97
    /**
98
     * Sets the source path of this file.
99
     *
100
     * @param   string              $src
101
     *
102
     * @return  Image
103
     *
104
     * @see https://www.w3.org/TR/appmanifest/#src-member
105
     */
106 1
    public function setSrc($src)
107
    {
108 1
        $this->src = $src;
109 1
        return $this;
110
    }
111
112
    /**
113
     * Returns the MIME type of this file.
114
     *
115
     * @return  string|null
116
     */
117 1
    public function getType()
118
    {
119 1
        return $this->type;
120
    }
121
122
    /**
123
     * Sets the MIME type of this file.
124
     *
125
     * @param   string              $type
126
     *
127
     * @return  Image
128
     *
129
     * @see https://www.w3.org/TR/appmanifest/#type-member
130
     */
131 1
    public function setType($type)
132
    {
133 1
        $this->type = $type;
134 1
        return $this;
135
    }
136
}
137