Passed
Push — google-wallet-support ( 15e26d...cd8842 )
by Razvan
04:15
created

Image::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Passbook package.
5
 *
6
 * (c) Eymen Gunay <[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 Passbook\Apple;
13
14
/**
15
 * Image
16
 *
17
 * Must be one of the following values:
18
 * background - The image displayed as the background of the front of the pass.
19
 * footer - The image displayed on the front of the pass near the barcode.
20
 * icon - The pass’s icon. This is displayed in notifications and in emails that have a pass attached, and on the lock screen.
21
 * logo - The image displayed on the front of the pass in the top left.
22
 * strip - The image displayed behind the primary fields on the front of the pass.
23
 * thumbnail - An additional image displayed on the front of the pass. For example, on a membership card, the thumbnail could be used to a picture of the cardholder.
24
 *
25
 * @author Eymen Gunay <[email protected]>
26
 */
27
class Image extends \SplFileObject implements ImageInterface
28
{
29
    /**
30
     * Image context. Must be one of the following values:
31
     * thumbnail, icon, background, logo, footer, strip
32
     * @var string
33
     */
34
    protected $context;
35
36
    /**
37
     * All of the pass’s images are loaded using standard UIImage image-loading methods.
38
     * This means, for example, the file name of high resolution versions of the image ends with @2x.png/@3x.png.
39
     * @var integer
40
     */
41
    protected $density;
42
43
    /**
44
     * Force "png" extension in case of dynamic conversion of the file, i.e. by CDN.
45
     *
46
     * @var bool
47
     */
48
    protected $forceExtension;
49
50 7
    public function __construct($filename, $context, $forceExtension = false)
51
    {
52 7
        parent::__construct($filename);
53
54 7
        $this->context = $context;
55 7
        $this->forceExtension = $forceExtension;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function setContext($context)
62
    {
63
        $this->context = $context;
64
65
        return $this;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 7
    public function getContext()
72
    {
73 7
        return $this->context;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 2
    public function setDensity($density)
80
    {
81 2
        $this->density = $density;
82
83 2
        return $this;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89 5
    public function getDensity()
90
    {
91 5
        return $this->density;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97 5
    public function getExtension(): string
98
    {
99 5
        if ($this->forceExtension) {
100
            return 'png';
101
        }
102
103
        // Image pathname can be URL not only local file location
104 5
        return pathinfo(parse_url($this->getPathname(), PHP_URL_PATH), PATHINFO_EXTENSION);
0 ignored issues
show
Bug Best Practice introduced by
The expression return pathinfo(parse_ur...ple\PATHINFO_EXTENSION) could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
105
    }
106
}
107