Completed
Push — master ( d4a92d...b23853 )
by hook
05:07 queued 02:55
created

DynamoDBGrammar::insert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hoooklife\DynamodbPodm\Grammars;
4
5
use Aws\DynamoDb\Marshaler;
6
use Hoooklife\DynamodbPodm\DB;
7
use Hoooklife\DynamodbPodm\Query\Builder;
8
use Hoooklife\DynamodbPodm\Grammars\DynamoDBBuilder;
9
10
class DynamoDBGrammar
11
{
12
    protected $operators = [];
13
14
    protected $params = [];
15
16
    /**
17
     * @var Builder
18
     */
19
    private $builder;
20
    /**
21
     * @var array
22
     */
23
    private $config;
24
25
    private $dynamoDBBuilder;
26
27
    /**
28
     * DynamoDBGrammar constructor.
29
     * @param Builder $builder
30
     * @param array $config
31
     */
32
    public function __construct(Builder $builder, array $config)
33
    {
34
        $this->builder = $builder;
35
        $this->config = $config;
36
37
        $this->dynamoDBBuilder = new DynamoDBBuilder($config);
38
    }
39
40
    // 表达式解析 where
41
    public function parseKeyConditionExpression()
42
    {
43
        $expression = [];
44
        foreach ($this->builder->wheres as $where) {
45
            $expression[] = "{$where['column']} {$where['operator']} {$where['value']}";
46
        }
47
48
        return implode("and", $expression);
49
50
    }
51
52
    // select
53
    public function parseProjectionExpression()
54
    {
55
        if (reset($this->builder->columns) != '*') {
56
            return implode(",", $this->columns);
0 ignored issues
show
Bug Best Practice introduced by
The property columns does not exist on Hoooklife\DynamodbPodm\Grammars\DynamoDBGrammar. Did you maybe forget to declare it?
Loading history...
57
        }
58
        return null;
59
    }
60
61
    // limit
62
    public function parseLimit()
63
    {
64
        return $this->builder->limit;
65
    }
66
67
    /**
68
     * Get the grammar specific operators.
69
     *
70
     * @return array
71
     */
72
    public function getOperators()
73
    {
74
        return $this->operators;
75
    }
76
77
    public function all()
78
    {
79
80
81
//        var_dump((new Marshaler())->marshalItem([
82
//            ':title'=>'aaa'
83
//        ]));
84
//        var_dump((new Marshaler())->marshalJson('
85
//            {
86
//                ":title": "aaa"
87
//            }
88
//        '));
89
//        die;
90
        $params = [
0 ignored issues
show
Unused Code introduced by
The assignment to $params is dead and can be removed.
Loading history...
91
            'TableName' => $this->builder->table,
92
            'KeyConditionExpression' => 'title = :title',
93
            'FilterExpression' => 'title = :title',
94
            'ExpressionAttributeValues' => (new Marshaler())->marshalItem([
95
                ':title' => 'The Big New Movie'
96
            ])
97
        ];
98
99
        $this->dynamoDBBuilder->setTableName($this->builder->table)
100
            ->setKeyConditionExpression('title = :title')
101
            ->setFilterExpression('title = :title')
102
            ->setExpressionAttributeValues(
103
                (new Marshaler())->marshalItem([
104
                    ':title' => 'The Big New Movie'
105
                ]));
106
107
108
        $result = $this->dynamoDBBuilder->scan();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $this->dynamoDBBuilder->scan() targeting Hoooklife\DynamodbPodm\G...DynamoDBBuilder::scan() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
109
110
        var_dump($result);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($result) looks like debug code. Are you sure you do not want to remove it?
Loading history...
111
    }
112
}