GroupsExclusionStrategy   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2
ccs 7
cts 10
cp 0.7
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A skipProperty() 0 14 4
1
<?php
2
3
/*
4
 * This file is part of the Ivory Serializer package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\Serializer\Exclusion;
13
14
use Ivory\Serializer\Context\ContextInterface;
15
use Ivory\Serializer\Mapping\PropertyMetadataInterface;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class GroupsExclusionStrategy extends ExclusionStrategy
21
{
22
    const GROUP_DEFAULT = 'Default';
23
24
    /**
25
     * @var string[]
26
     */
27
    private $groups;
28
29
    /**
30
     * @param string[] $groups
31
     */
32
    public function __construct(array $groups)
33
    {
34
        $this->groups = $groups;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 48
    public function skipProperty(PropertyMetadataInterface $property, ContextInterface $context)
41
    {
42 48
        if (!$property->hasGroups()) {
43 48
            return !in_array(self::GROUP_DEFAULT, $this->groups, true);
44
        }
45
46 48
        foreach ($this->groups as $group) {
47 48
            if ($property->hasGroup($group)) {
48 48
                return false;
49
            }
50
        }
51
52 32
        return true;
53
    }
54
}
55