Passed
Push — develop ( 0540ad...1b4c9d )
by
unknown
39s
created

Database::setDatabaseName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace Fathomminds\Rest\Database\Clusterpoint;
3
4
use Clusterpoint\Client;
5
use Fathomminds\Rest\Contracts\IDatabase;
6
use Fathomminds\Rest\Database\Clusterpoint\Resource;
7
use Fathomminds\Rest\Helpers\ReflectionHelper;
8
9
class Database implements IDatabase
10
{
11
    protected $client;
12
    protected $databaseName;
13
14 29
    public function __construct(Client $client = null, $databaseName = null)
15
    {
16 29
        $this->client = $client === null ? new Client : $client;
17 29
        $this->databaseName = $databaseName === null ? getenv('CLUSTERPOINT_DATABASE') : $databaseName;
18 29
    }
19
20 4
    public function get($resourceName, $primaryKey, $resourceId = null)
21
    {
22 4
        return (new Resource(
23 4
            $resourceName,
24 4
            $primaryKey,
25 4
            $this->client,
26 4
            $this->databaseName
27 4
        ))->get($resourceId);
28
    }
29
30 1
    public function post($resourceName, $primaryKey, $newResource)
31
    {
32 1
        return (new Resource(
33 1
            $resourceName,
34 1
            $primaryKey,
35 1
            $this->client,
36 1
            $this->databaseName
37 1
        ))->post($newResource);
38
    }
39
40 1
    public function put($resourceName, $primaryKey, $resourceId, $newResource)
41
    {
42 1
        return (new Resource(
43 1
            $resourceName,
44 1
            $primaryKey,
45 1
            $this->client,
46 1
            $this->databaseName
47 1
        ))->put($resourceId, $newResource);
48
    }
49
50 2
    public function delete($resourceName, $primaryKey, $resourceId)
51
    {
52 2
        return (new Resource(
53 2
            $resourceName,
54 2
            $primaryKey,
55 2
            $this->client,
56 2
            $this->databaseName
57 2
        ))->delete($resourceId);
58
    }
59
60 1
    public function setDatabaseName($databaseName)
61
    {
62 1
        $this->databaseName = $databaseName;
63 1
    }
64
65 9
    public function getDatabaseName()
66
    {
67 9
        return $this->databaseName;
68
    }
69
70 6
    public function getClient()
71
    {
72 6
        return $this->client;
73
    }
74
}
75