Completed
Push — 6.13 ( fb0043...d86c76 )
by André
18:03
created

AbstractPropertyWhitelistNormalizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 11 3
getAllowedProperties() 0 1 ?
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\MVC\Symfony\Component\Serializer;
10
11
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
12
13
abstract class AbstractPropertyWhitelistNormalizer extends PropertyNormalizer
14
{
15
    public function normalize($object, $format = null, array $context = [])
16
    {
17
        $data = parent::normalize($object, $format, $context);
18
        foreach (array_keys($data) as $property) {
19
            if (!in_array($property, $this->getAllowedProperties())) {
20
                unset($data[$property]);
21
            }
22
        }
23
24
        return $data;
25
    }
26
27
    /**
28
     * @return string[]
29
     */
30
    abstract protected function getAllowedProperties(): array;
31
}
32