EmptyAttributeFilter::filter()   B
last analyzed

Complexity

Conditions 11
Paths 121

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 11.0908

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 16
ccs 10
cts 11
cp 0.9091
rs 7.1416
cc 11
nc 121
nop 1
crap 11.0908

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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