Completed
Push β€” master ( 77ffdb...bbbe01 )
by hook
04:07
created

DynamoDBBuilder::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hoooklife\DynamodbPodm\Query;
4
/**
5
 * Class DynamoDBBuilder
6
 *
7
 * @package BaoPham\DynamoDb\DynamoDb
8
 *
9
 * Methods are in the form of `set<key_name>`, where `<key_name>`
10
 * is the key name of the query body to be sent.
11
 *
12
 * For example, to build a query:
13
 * [
14
 *     'AttributeDefinitions' => ...,
15
 *     'GlobalSecondaryIndexUpdates' => ...
16
 *     'TableName' => ...
17
 * ]
18
 *
19
 * Do:
20
 *
21
 * $query = $query->setAttributeDefinitions(...)->setGlobalSecondaryIndexUpdates(...)->setTableName(...);
22
 *
23
 * When ready:
24
 *
25
 * $query->prepare()->updateTable();
26
 *
27
 * Common methods:
28
 *
29
 * @method DynamoDBBuilder setExpressionAttributeNames(array $mapping)
30
 * @method DynamoDBBuilder setExpressionAttributeValues(array $mapping)
31
 * @method DynamoDBBuilder setFilterExpression(string $expression)
32
 * @method DynamoDBBuilder setKeyConditionExpression(string $expression)
33
 * @method DynamoDBBuilder setProjectionExpression(string $expression)
34
 * @method DynamoDBBuilder setUpdateExpression(string $expression)
35
 * @method DynamoDBBuilder setAttributeUpdates(array $updates)
36
 * @method DynamoDBBuilder setConsistentRead(bool $consistent)
37
 * @method DynamoDBBuilder setScanIndexForward(bool $forward)
38
 * @method DynamoDBBuilder setExclusiveStartKey(mixed $key)
39
 * @method DynamoDBBuilder setReturnValues(string $type)
40
 * @method DynamoDBBuilder setRequestItems(array $items)
41
 * @method DynamoDBBuilder setTableName(string $table)
42
 * @method DynamoDBBuilder setIndexName(string $index)
43
 * @method DynamoDBBuilder setSelect(string $select)
44
 * @method DynamoDBBuilder setItem(array $item)
45
 * @method DynamoDBBuilder setKeys(array $keys)
46
 * @method DynamoDBBuilder setLimit(int $limit)
47
 * @method DynamoDBBuilder setKey(array $key)
48
 */
49
class DynamoDBBuilder
50
{
51
    /**
52
     * Query body to be sent to AWS
53
     *
54
     * @var array
55
     */
56
    public $query = [];
57
58
    /**
59
     * @param  string $method
60
     * @param  array $parameters
61
     * @return mixed
62
     */
63
    public function __call($method, $parameters)
64
    {
65
        if (starts_with($method, 'set')) {
0 ignored issues
show
Bug introduced by
The function starts_with was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        if (/** @scrutinizer ignore-call */ starts_with($method, 'set')) {
Loading history...
66
            $key = array_reverse(explode('set', $method, 2))[0];
67
            $this->query[$key] = current($parameters);
68
            return $this;
69
        }
70
        throw new BadMethodCallException(sprintf(
0 ignored issues
show
Bug introduced by
The type Hoooklife\DynamodbPodm\Q...\BadMethodCallException was not found. Did you mean BadMethodCallException? If so, make sure to prefix the type with \.
Loading history...
71
            'Method %s::%s does not exist.',
72
            static::class,
73
            $method
74
        ));
75
    }
76
77
    public function exec()
78
    {
79
80
    }
81
}