EmptyAttributeFilter   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
eloc 12
c 2
b 0
f 0
dl 0
loc 26
ccs 12
cts 13
cp 0.9231
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
B filter() 0 16 11
1
<?php
2
3
namespace BaoPham\DynamoDb;
4
5
class EmptyAttributeFilter
6
{
7 146
    public function __construct()
8
    {
9
        //
10 146
    }
11
12
    /**
13
     * Set empty values to NULL since DynamoDB does not like empty values.
14
     */
15 1
    public function filter(&$store)
16
    {
17 1
        foreach ($store as $key => &$value) {
18 1
            $value = is_string($value) ? trim($value) : $value;
19 1
            $empty = $value === null || (is_array($value) && empty($value));
20
21 1
            $empty = $empty || (is_scalar($value) && $value !== false && (string) $value === '');
22
23 1
            if ($empty) {
24 1
                $store[$key] = null;
25
            } else {
26 1
                if (is_object($value)) {
27
                    $value = (array) $value;
28
                }
29 1
                if (is_array($value)) {
30 1
                    $this->filter($value);
31
                }
32
            }
33
        }
34 1
    }
35
}
36