Completed
Push — develop ( 9af4bd...daa113 )
by
unknown
7s
created

MongoCredentialsProvider::getConnection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
ccs 0
cts 10
cp 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * small helper to read our VCAP_SERVICES in cf
4
 */
5
6
namespace Graviton\ImportExport\Util;
7
8
use Flow\JSONPath\JSONPath;
9
10
/**
11
 * @author   List of contributors <https://github.com/libgraviton/import-export/graphs/contributors>
12
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
13
 * @link     http://swisscom.ch
14
 */
15
class MongoCredentialsProvider
16
{
17
18
    /**
19
     * gets connection params from ENV if available
20
     *
21
     * @return array connection params
22
     */
23
    public static function getConnection()
24
    {
25
        // defaults
26
        $ret = ['uri' => null, 'db' => 'db'];
27
28
        if (isset($_ENV['VCAP_SERVICES'])) {
29
            $path = new JSONPath(json_decode($_ENV['VCAP_SERVICES'], true));
30
            $ret['uri'] = $path->find('$..mongodb[0].*.uri')->first();
31
            $ret['db'] = $path->find('$..mongodb[0].*.database')->first();
32
        }
33
34
        return $ret;
35
    }
36
}
37