GridFSFsComponent   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 12 3
A initAdapter() 0 6 1
1
<?php
2
/**
3
 * This file is part of the 2amigos/yii2-flysystem-component project.
4
 *
5
 * (c) 2amigOS! <http://2amigos.us/>
6
 *
7
 * For the full copyright and license information, please view
8
 * the LICENSE file that was distributed with this source code.
9
 */
10
namespace dosamigos\flysystem;
11
12
use League\Flysystem\GridFS\GridFSAdapter;
13
use MongoClient;
14
use yii\base\InvalidConfigException;
15
16
class GridFSFsComponent extends AbstractFsComponent
17
{
18
    /**
19
     * @var string
20
     */
21
    public $server;
22
    /**
23
     * @var string
24
     */
25
    public $database;
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function init()
31
    {
32
        if ($this->server === null) {
33
            throw new InvalidConfigException('The "server" property must be set.');
34
        }
35
36
        if ($this->database === null) {
37
            throw new InvalidConfigException('The "database" property must be set.');
38
        }
39
40
        parent::init();
41
    }
42
43
    /**
44
     * @return GridFSAdapter
45
     */
46
    protected function initAdapter()
47
    {
48
        $mongo = new MongoClient($this->server);
49
50
        return new GridFSAdapter($mongo->selectDB($this->database)->getGridFS());
51
    }
52
}
53