EmptyAttributeFilter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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