Test Failed
Pull Request — master (#180)
by
unknown
04:22
created

ExpressionAttributeNames::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace BaoPham\DynamoDb\Parsers;
4
5
class ExpressionAttributeNames
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $mapping;
11
12
    /**
13
     * @var array
14
     */
15
    protected $nested;
16
17
    /**
18
     * @var string
19
     */
20
    protected $prefix;
21
22 131
    public function __construct($prefix = '#')
23
    {
24 131
        $this->reset();
25 131
        $this->prefix = $prefix;
26 131
    }
27
28 80
    public function set($name)
29
    {
30 80
        if ($this->isNested($name)) {
31 13
            $this->nested[] = $name;
32 13
            return;
33
        }
34 76
        $this->mapping["{$this->prefix}{$name}"] = $name;
35 76
    }
36
37
    public function get($placeholder)
38
    {
39
        return $this->mapping[$placeholder];
40
    }
41
42 70
    public function placeholder($name)
43
    {
44 70
        $placeholder = "{$this->prefix}{$name}";
45 70
        if (isset($this->mapping[$placeholder])) {
46 68
            return $placeholder;
47
        }
48 2
        return $name;
49
    }
50
51 103
    public function all()
52
    {
53 103
        return $this->mapping;
54
    }
55
56 15
    public function placeholders()
57
    {
58 15
        return array_merge(array_keys($this->mapping), $this->nested);
59
    }
60
61 131
    public function reset()
62
    {
63 131
        $this->mapping = [];
64 131
        $this->nested = [];
65
66 131
        return $this;
67
    }
68
69 80
    private function isNested($name)
70
    {
71 80
        return strpos($name, '.') !== false || (strpos($name, '[') !== false && strpos($name, ']') !== false);
72
    }
73
}
74