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

CryptoConstant   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 39
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultMethod() 0 4 1
A getDefaultProtocol() 0 8 2
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
}