ExpressionAttributeNames   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 21
c 1
b 0
f 0
dl 0
loc 67
ccs 27
cts 27
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A placeholders() 0 3 1
A placeholder() 0 7 2
A isNested() 0 3 3
A all() 0 3 1
A get() 0 3 1
A set() 0 7 2
A __construct() 0 4 1
A reset() 0 6 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 134
    public function __construct($prefix = '#')
23
    {
24 134
        $this->reset();
25 134
        $this->prefix = $prefix;
26 134
    }
27
28 82
    public function set($name)
29
    {
30 82
        if ($this->isNested($name)) {
31 14
            $this->nested[] = $name;
32 14
            return;
33
        }
34 77
        $this->mapping["{$this->prefix}{$name}"] = $name;
35 77
    }
36
37 1
    public function get($placeholder)
38
    {
39 1
        return $this->mapping[$placeholder];
40
    }
41
42 72
    public function placeholder($name)
43
    {
44 72
        $placeholder = "{$this->prefix}{$name}";
45 72
        if (isset($this->mapping[$placeholder])) {
46 69
            return $placeholder;
47
        }
48 3
        return $name;
49
    }
50
51 104
    public function all()
52
    {
53 104
        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 134
    public function reset()
62
    {
63 134
        $this->mapping = [];
64 134
        $this->nested = [];
65
66 134
        return $this;
67
    }
68
69 82
    private function isNested($name)
70
    {
71 82
        return strpos($name, '.') !== false || (strpos($name, '[') !== false && strpos($name, ']') !== false);
72
    }
73
}
74