Passed
Pull Request — master (#1257)
by
unknown
02:36
created

SkipWhenEmptyExclusionStrategy   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 23
rs 10
c 1
b 0
f 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B shouldSkipPropertyWithValue() 0 18 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\Exclusion;
6
7
use JMS\Serializer\Context;
8
use JMS\Serializer\Metadata\PropertyMetadata;
9
10
class SkipWhenEmptyExclusionStrategy implements ValueExclusionStrategyInterface
11
{
12
    /**
13
     * @inheritDoc
14
     */
15
    public function shouldSkipPropertyWithValue(PropertyMetadata $property, Context $context, $value): bool
16
    {
17
        if (
18
            $property->skipWhenEmpty
19
            || (
20
                $context->hasAttribute(Context::ATTR_SKIP_WHEN_EMPTY)
21
                && $context->getAttribute(Context::ATTR_SKIP_WHEN_EMPTY)
22
            )
23
        ) {
24
            if ($value instanceof \ArrayObject || \is_array($value) && 0 === count($value)) {
25
                return true;
26
            }
27
28
            // This would be used for T object types, later, in the visitor->visitProperty
29
            $property->skipWhenEmpty = true;
30
        }
31
32
        return false;
33
    }
34
}
35