Passed
Pull Request — master (#42)
by
unknown
02:32 queued 42s
created

Database::patch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 9.6666
cc 1
eloc 7
nc 1
nop 4
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 31
    public function __construct(Client $client = null, $databaseName = null)
15
    {
16 31
        $this->client = $client === null ? new Client : $client;
17 31
        $this->databaseName = $databaseName === null ? getenv('CLUSTERPOINT_DATABASE') : $databaseName;
18 31
    }
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 patch($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
        ))->patch($resourceId, $newResource);
48
    }
49
50 1
    public function put($resourceName, $primaryKey, $resourceId, $newResource)
51
    {
52 1
        return (new Resource(
53 1
            $resourceName,
54 1
            $primaryKey,
55 1
            $this->client,
56 1
            $this->databaseName
57 1
        ))->put($resourceId, $newResource);
58
    }
59
60 2
    public function delete($resourceName, $primaryKey, $resourceId)
61
    {
62 2
        return (new Resource(
63 2
            $resourceName,
64 2
            $primaryKey,
65 2
            $this->client,
66 2
            $this->databaseName
67 2
        ))->delete($resourceId);
68
    }
69
70 1
    public function setDatabaseName($databaseName)
71
    {
72 1
        $this->databaseName = $databaseName;
73 1
    }
74
75 10
    public function getDatabaseName()
76
    {
77 10
        return $this->databaseName;
78
    }
79
80 7
    public function getClient()
81
    {
82 7
        return $this->client;
83
    }
84
}
85