Certificate::writeToTmp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace JWage\APNS;
4
5
class Certificate
6
{
7
    /**
8
     * @var string
9
     */
10
    private $certificateString;
11
12
    /**
13
     * @var string
14
     */
15
    private $password;
16
17
    /**
18
     * Construct.
19
     *
20
     * @param string $certificateString
21
     * @param string $password
22
     */
23
    public function __construct($certificateString, $password = null)
24
    {
25
        $this->certificateString =  (string) $certificateString;
26
        $this->password = $password;
27
    }
28
29
    /**
30
     * Gets the certificate string.
31
     *
32
     * @return string $certificateString
33
     */
34
    public function getCertificateString()
35
    {
36
        return $this->certificateString;
37
    }
38
39
    /**
40
     * Gets the certificate password.
41
     *
42
     * @return string $password
43
     */
44
    public function getPassword()
45
    {
46
        return $this->password;
47
    }
48
49
    /**
50
     * Writes the certificate to the given file path.
51
     *
52
     * @param string $path
53
     */
54
    public function writeTo($path)
55
    {
56
        file_put_contents($path, $this->certificateString);
57
    }
58
59
    /**
60
     * Writes the certificate to a temporary file and returns the path.
61
     *
62
     * @return string $path
63
     */
64
    public function writeToTmp()
65
    {
66
        $path = tempnam(sys_get_temp_dir(), 'cert_');
67
68
        $this->writeTo($path);
69
70
        return $path;
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function __toString()
77
    {
78
        return $this->certificateString;
79
    }
80
}
81