GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Push — master ( 2017fb...f66b1d )
by Charlotte
10:52
created

DriverFactory::addAuthPlugin()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Plasma Driver MySQL component
4
 * Copyright 2018 PlasmaPHP, All Rights Reserved
5
 *
6
 * Website: https://github.com/PlasmaPHP
7
 * License: https://github.com/PlasmaPHP/driver-mysql/blob/master/LICENSE
8
*/
9
10
namespace Plasma\Drivers\MySQL;
11
12
/**
13
 * The Driver Factory is responsible for creating the driver correctly.
14
 */
15
class DriverFactory implements \Plasma\DriverFactoryInterface {
16
    /**
17
     * @var \React\EventLoop\LoopInterface
18
     */
19
    protected $loop;
20
    
21
    /**
22
     * @var array
23
     */
24
    protected $options;
25
    
26
    /**
27
     * @var \Plasma\Drivers\MySQL\AuthPlugins\AuthPluginInterface[]
28
     */
29
    protected static $authPlugins = array(
30
        \Plasma\Drivers\MySQL\CapabilityFlags::CLIENT_SECURE_CONNECTION => \Plasma\Drivers\MySQL\AuthPlugins\AuthSecureConnection::class,
31
        'mysql_native_password' => \Plasma\Drivers\MySQL\AuthPlugins\AuthSecureConnection::class
32
    );
33
    
34
    /**
35
     * @var \React\Filesystem\FilesystemInterface|null
36
     */
37
    protected static $filesystem;
38
    
39
    /**
40
     * Constructor.
41
     *
42
     * The driver supports the following options:
43
     * ```
44
     * array(
45
     *     'connector' => ConnectorInstance, (a custom connector instance, which MUST return a `Connection` instance from the `react/socket` package)
46
     *     'tls.context' => array, (socket TLS context options)
47
     *     'tls.force' => bool, (whether non-private IP connections are forced to use TLS, defaults to false)
48
     * )
49
     * ```
50
     *
51
     * @param \React\EventLoop\LoopInterface  $loop
52
     * @param array                           $options
53
     */
54 16
    function __construct(\React\EventLoop\LoopInterface $loop, array $options) {
55 16
        if(!\function_exists('stream_socket_enable_crypto')) {
56
            throw new \LogicException('Encryption is not supported on your platform');
57
        }
58
        
59 16
        $this->loop = $loop;
60 16
        $this->options = $options;
61 16
    }
62
    
63
    /**
64
     * Creates a new driver instance.
65
     * @return \Plasma\DriverInterface
66
     */
67 16
    function createDriver(): \Plasma\DriverInterface {
68 16
        return (new \Plasma\Drivers\MySQL\Driver($this->loop, $this->options));
69
    }
70
    
71
    /**
72
     * Adds an auth plugin. `$condition` is either an int (for server capabilities), or a string (for auth plugin name).
73
     * @param string|int  $condition
74
     * @param string      $classname  A class implementing `AuthPluginInterface`.
75
     * @return void
76
     * @throws \InvalidArgumentException
77
     */
78 3
    static function addAuthPlugin($condition, string $classname): void {
79 3
        if(isset(static::$authPlugins[$condition])) {
80 1
            throw new \InvalidArgumentException('Auth plugin for specified condition already exists');
81
        }
82
        
83 3
        if(!\in_array(\Plasma\Drivers\MySQL\AuthPlugins\AuthPluginInterface::class, \class_implements($classname, true))) {
84 1
            throw new \InvalidArgumentException('Specified auth plugin does not implement interface');
85
        }
86
        
87 2
        static::$authPlugins[$condition] = $classname;
88 2
    }
89
    
90
    /**
91
     * Get the registered auth plugins.
92
     * @return \Plasma\Drivers\MySQL\AuthPlugins\AuthPluginInterface[]
93
     */
94 2
    static function getAuthPlugins(): array {
95 2
        return static::$authPlugins;
96
    }
97
    
98
    /**
99
     * Set the React Filesystem to use.
100
     * @param \React\Filesystem\FilesystemInterface  $filesystem
101
     * @return void
102
     */
103 1
    static function setFilesystem(\React\Filesystem\FilesystemInterface $filesystem): void {
104 1
        static::$filesystem = $filesystem;
105 1
    }
106
    
107
    /**
108
     * Get the React Filesystem, or null. The filesystem must be set by the user, in order to not get `null`.
109
     * @return \React\Filesystem\FilesystemInterface|null
110
     */
111 1
    static function getFilesystem(): ?\React\Filesystem\FilesystemInterface {
112 1
        return static::$filesystem;
113
    }
114
}
115