| Total Complexity | 12 |
| Total Lines | 67 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 | public function __construct($prefix = '#') |
||
| 23 | { |
||
| 24 | $this->reset(); |
||
| 25 | $this->prefix = $prefix; |
||
| 26 | } |
||
| 27 | |||
| 28 | public function set($name) |
||
| 29 | { |
||
| 30 | if ($this->isNested($name)) { |
||
| 31 | $this->nested[] = $name; |
||
| 32 | return; |
||
| 33 | } |
||
| 34 | $this->mapping["{$this->prefix}{$name}"] = $name; |
||
| 35 | } |
||
| 36 | |||
| 37 | public function get($placeholder) |
||
| 40 | } |
||
| 41 | |||
| 42 | public function placeholder($name) |
||
| 43 | { |
||
| 44 | $placeholder = "{$this->prefix}{$name}"; |
||
| 45 | if (isset($this->mapping[$placeholder])) { |
||
| 46 | return $placeholder; |
||
| 47 | } |
||
| 48 | return $name; |
||
| 49 | } |
||
| 50 | |||
| 51 | public function all() |
||
| 52 | { |
||
| 53 | return $this->mapping; |
||
| 54 | } |
||
| 55 | |||
| 56 | public function placeholders() |
||
| 57 | { |
||
| 58 | return array_merge(array_keys($this->mapping), $this->nested); |
||
| 59 | } |
||
| 60 | |||
| 61 | public function reset() |
||
| 62 | { |
||
| 63 | $this->mapping = []; |
||
| 64 | $this->nested = []; |
||
| 65 | |||
| 66 | return $this; |
||
| 67 | } |
||
| 68 | |||
| 69 | private function isNested($name) |
||
| 72 | } |
||
| 73 | } |
||
| 74 |