Completed
Push — master ( 1f6470...ed326c )
by Frederik
02:16
created

CryptoConstant::getDefaultMethod()   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
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol;
5
6
/**
7
 * Class CryptoConstant
8
 * @package Genkgo\Mail\Protocol
9
 */
10
final class CryptoConstant
11
{
12
    /**
13
     * This might be changed after https://github.com/php/php-src/pull/2518
14
     *
15
     * @param string $phpVersion
16
     * @return int
17
     */
18 15
    public static function getDefaultMethod(string $phpVersion)
0 ignored issues
show
Unused Code introduced by
The parameter $phpVersion is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
19
    {
20 15
        return STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
21
    }
22
23
    /**
24
     * Considering that
25
     *
26
     * 1. starting from PHP 7.2.0 tls:// will negotiate best TLS version;
27
     * 2. pre PHP 7.2.0 tls:// is TLS 1.0 only.
28
     *
29
     * The following decisions have been made.
30
     *
31
     * 1. This library uses TLS 1.2 by default for pre PHP 7.2.0.
32
     * 2. Starting from PHP 7.2.0 this library uses the TLS negotiation by PHP, which
33
     *    means TLS 1.2 if available, otherwise falls back to a lower TLS version.
34
     *
35
     * Related: https://github.com/php/php-src/pull/2518 and https://wiki.php.net/rfc/improved-tls-constants
36
     *
37
     * @param string $phpVersion
38
     * @return string
39
     */
40 3
    public static function getDefaultProtocol(string $phpVersion)
41
    {
42 3
        if (version_compare($phpVersion, '7.2.0') < 0) {
43 2
            return 'tlsv1.2://';
44
        }
45
46 1
        return 'tls://';
47
    }
48
}