Completed
Pull Request — master (#150)
by De Cramer
03:29
created

FileSystem   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 63
ccs 0
cts 14
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getUserData() 0 8 2
A getLocalAdapter() 0 9 2
1
<?php
2
3
namespace eXpansion\Framework\Core\Helpers;
4
5
use League\Flysystem\Adapter\Local;
6
use League\Flysystem\FilesystemInterface;
7
use Maniaplanet\DedicatedServer\Connection;
8
9
/**
10
 * Class FileSystem
11
 *
12
 * @package eXpansion\Framework\Core\Helpers;
13
 * @author  oliver de Cramer <[email protected]>
14
 */
15
class FileSystem
16
{
17
    const CONNECTION_TYPE_LOCAL = 'local';
18
    const CONNECTION_TYPE_REMOTE = 'remote';
19
20
    /** @var Connection */
21
    protected $connection;
22
23
    /** @var string */
24
    protected $connectionType;
25
26
    /** @var array */
27
    protected $adapterParams;
28
29
    /** @var Local */
30
    protected $localAdapter;
31
32
    /** @var FilesystemInterface  */
33
    protected $remoteAdapter;
34
35
    /**
36
     * FileSystem constructor.
37
     *
38
     * @param Connection          $connection
39
     * @param string              $connectionType
40
     * @param FilesystemInterface $remoteAdapter
41
     */
42
    public function __construct(Connection $connection, string $connectionType, FilesystemInterface $remoteAdapter)
43
    {
44
        $this->connection = $connection;
45
        $this->connectionType = $connectionType;
46
        $this->remoteAdapter = $remoteAdapter;
47
    }
48
49
    /**
50
     * Get Filesystem adapter for the user data directory of the dedicated server.
51
     *
52
     * @return FilesystemInterface
53
     */
54
    public function getUserData() : FilesystemInterface
55
    {
56
        if ($this->connectionType == self::CONNECTION_TYPE_LOCAL) {
57
            return $this->getLocalAdapter();
58
        } else {
59
            return $this->remoteAdapter;
60
        }
61
    }
62
63
    /**
64
     * Get local adapter if dedicated is installed on same host.
65
     *
66
     * @return FilesystemInterface
67
     */
68
    protected function getLocalAdapter() : FilesystemInterface
69
    {
70
        if (is_null($this->localAdapter)) {
71
            $dir = $this->connection->getMapsDirectory();
72
            $this->localAdapter = new \League\Flysystem\Filesystem(new Local($dir . '/../'));
0 ignored issues
show
Documentation Bug introduced by
It seems like new \League\Flysystem\Fi...r\Local($dir . '/../')) of type object<League\Flysystem\Filesystem> is incompatible with the declared type object<League\Flysystem\Adapter\Local> of property $localAdapter.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
73
        }
74
75
        return $this->localAdapter;
76
    }
77
}
78