Completed
Pull Request — master (#63)
by
unknown
01:17
created

Certificate::authenticateClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Pushok package.
5
 *
6
 * (c) Arthur Edamov <[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 Pushok\AuthProvider;
13
14
use Pushok\AuthProviderInterface;
15
use Pushok\Request;
16
17
/**
18
 * Class Certificate
19
 * @package Pushok\AuthProvider
20
 *
21
 * @see     http://bit.ly/communicating-with-apns
22
 */
23
class Certificate implements AuthProviderInterface
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
24
{
25
    /**
26
     * Path to certificate.
27
     *
28
     * @var string
29
     */
30
    private $certificatePath;
31
32
    /**
33
     * Certificate secret.
34
     *
35
     * @var string
36
     */
37
    private $certificateSecret;
38
39
    /**
40
     * This provider accepts the following options:
41
     *
42
     * - certificate_path
43
     * - certificate_secret
44
     *
45
     * @param array $options
46
     */
47
    private function __construct(array $options)
48
    {
49
        $this->certificatePath   = $options['certificate_path'] ;
50
        $this->certificateSecret = $options['certificate_secret'];
51
    }
52
53
    /**
54
     * Create Certificate Auth provider.
55
     *
56
     * @param array $options
57
     * @return Certificate
58
     */
59
    public static function create(array $options): Certificate
60
    {
61
        return new self($options);
62
    }
63
64
    /**
65
     * Authenticate client.
66
     *
67
     * @param Request $request
68
     */
69
    public function authenticateClient(Request $request)
70
    {
71
        $request->addOptions(
72
            [
73
                CURLOPT_SSLCERT        => $this->certificatePath,
74
                CURLOPT_SSLCERTPASSWD  => $this->certificateSecret,
75
                CURLOPT_SSL_VERIFYPEER => true
76
            ]
77
        );
78
    }
79
}