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.
Completed
Push — master ( dfd258...a1c6c3 )
by Charlotte
02:11
created

DriverFactory::setFilesystem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
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
     *     'characters.set' => string, (the character set, defaults to utf8mb4)
47
     *     'characters.collate' => string, (the collate to use, defaults to the charset default)
48
     *     'tls.context' => array, (socket TLS context options)
49
     *     'tls.force' => bool, (whether non-localhost connections are forced to use TLS, defaults to true)
50
     *     'tls.forceLocal' => bool, (whether localhost connections are forced to use TLS, defaults to false)
51
     * )
52
     * ```
53
     *
54
     * @param \React\EventLoop\LoopInterface  $loop
55
     * @param array                           $options
56
     */
57 78
    function __construct(\React\EventLoop\LoopInterface $loop, array $options) {
58 78
        if(!\function_exists('stream_socket_enable_crypto')) {
59
            throw new \LogicException('Encryption is not supported on your platform');
60
        }
61
        
62
        try {
63 78
            \Plasma\Types\TypeExtensionsManager::registerManager('driver-mysql', null);
64 77
        } catch (\Plasma\Exception $e) {
65
            /* One already exists, continue regardless */
66
        }
67
        
68 78
        $this->loop = $loop;
69 78
        $this->options = $options;
70 78
    }
71
    
72
    /**
73
     * Creates a new driver instance.
74
     * @return \Plasma\DriverInterface
75
     */
76 75
    function createDriver(): \Plasma\DriverInterface {
77 75
        return (new \Plasma\Drivers\MySQL\Driver($this->loop, $this->options));
78
    }
79
    
80
    /**
81
     * Adds an auth plugin. `$condition` is either an int (for server capabilities), or a string (for auth plugin name).
82
     * @param string|int  $condition
83
     * @param string      $classname  A class implementing `AuthPluginInterface`.
84
     * @return void
85
     * @throws \InvalidArgumentException
86
     */
87 3
    static function addAuthPlugin($condition, string $classname): void {
88 3
        if(isset(static::$authPlugins[$condition])) {
89 1
            throw new \InvalidArgumentException('Auth plugin for specified condition already exists');
90
        }
91
        
92 3
        if(!\in_array(\Plasma\Drivers\MySQL\AuthPlugins\AuthPluginInterface::class, \class_implements($classname, true))) {
93 1
            throw new \InvalidArgumentException('Specified auth plugin does not implement interface');
94
        }
95
        
96 2
        static::$authPlugins[$condition] = $classname;
97 2
    }
98
    
99
    /**
100
     * Get the registered auth plugins.
101
     * @return \Plasma\Drivers\MySQL\AuthPlugins\AuthPluginInterface[]
102
     */
103 57
    static function getAuthPlugins(): array {
104 57
        return static::$authPlugins;
105
    }
106
    
107
    /**
108
     * Set the React Filesystem to use.
109
     * @param \React\Filesystem\FilesystemInterface|null  $filesystem
110
     * @return void
111
     */
112 1
    static function setFilesystem(?\React\Filesystem\FilesystemInterface $filesystem): void {
113 1
        static::$filesystem = $filesystem;
114 1
    }
115
    
116
    /**
117
     * Get the React Filesystem, or null. The filesystem must be set by the user, in order to not get `null`.
118
     * @return \React\Filesystem\FilesystemInterface|null
119
     */
120 2
    static function getFilesystem(): ?\React\Filesystem\FilesystemInterface {
121 2
        return static::$filesystem;
122
    }
123
}
124