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

shouldSkipPropertyWithValue()   B

Complexity

Conditions 7
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 9
nc 3
nop 3
dl 0
loc 18
rs 8.8333
c 0
b 0
f 0
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