Completed
Push — master ( d73f1a...00b534 )
by Frederik
02:19
created

SecureConnectionOptions::createContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol;
5
6
/**
7
 * @codeCoverageIgnore
8
 */
9
final class SecureConnectionOptions
10
{
11
    /**
12
     * @var float
13
     */
14
    private $timeout = 10;
15
16
    /**
17
     * @var int
18
     */
19
    private $method;
20
21
    /**
22
     * @var array
23
     */
24
    private $contextOptions = [];
25
26
    /**
27
     * @param int $method
28
     * @param int $timeout
29
     * @param array $contextOptions
30
     */
31
    public function __construct(int $method, int $timeout = 10, array $contextOptions = [])
32
    {
33
        $this->method = $method;
34
        $this->timeout = $timeout;
0 ignored issues
show
Documentation Bug introduced by
The property $timeout was declared of type double, but $timeout is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
35
        $this->contextOptions = $contextOptions;
36
    }
37
38
    /**
39
     * @param float $connectionTimeout
40
     * @return SecureConnectionOptions
41
     */
42
    public function withTimeout(float $connectionTimeout): self
43
    {
44
        $clone = clone $this;
45
        $clone->timeout = $connectionTimeout;
46
        return $clone;
47
    }
48
49
    /**
50
     * @param int $method
51
     * @return SecureConnectionOptions
52
     */
53
    public function withMethod(int $method): self
54
    {
55
        $clone = clone $this;
56
        $clone->method = $method;
57
        return $clone;
58
    }
59
60
    /**
61
     * @param array $contextOptions
62
     * @return SecureConnectionOptions
63
     */
64
    public function withContextOptions(array $contextOptions): self
65
    {
66
        $clone = clone $this;
67
        $clone->contextOptions = $contextOptions;
68
        return $clone;
69
    }
70
71
    /**
72
     * @return float
73
     */
74
    public function getTimeout(): float
75
    {
76
        return $this->timeout;
77
    }
78
79
    /**
80
     * @return int
81
     */
82
    public function getMethod(): int
83
    {
84
        return $this->method;
85
    }
86
87
    /**
88
     * @return array
89
     */
90
    public function getContextOptions(): array
91
    {
92
        return $this->contextOptions;
93
    }
94
95
    /**
96
     * @return resource
97
     */
98
    public function createContext()
99
    {
100
        return \stream_context_create([
101
            'ssl' => \array_merge(
102
                $this->contextOptions,
103
                ['crypto_method' => $this->method]
104
            )
105
        ]);
106
    }
107
}
108