Completed
Pull Request — develop (#10)
by Lucas
11:08 queued 05:18
created

MongoCredentialsProvider::getConnection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.3149

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
ccs 4
cts 7
cp 0.5714
rs 9.4286
cc 2
eloc 7
nc 2
nop 0
crap 2.3149
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 1
    public static function getConnection()
24
    {
25
        // defaults
26 1
        $ret = ['uri' => null, 'db' => 'db'];
27
28 1
        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 1
        return $ret;
35
    }
36
}
37