CustomerSecureFieldFilterPlugin   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
eloc 14
c 2
b 0
f 1
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A filterData() 0 10 3
A getFilterFields() 0 6 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Minubo\Communication\Plugin\Filter;
9
10
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
11
use SprykerEco\Zed\Minubo\Dependency\Plugin\MinuboDataFilterInterface;
12
13
/**
14
 * @method \SprykerEco\Zed\Minubo\MinuboConfig getConfig()
15
 * @method \SprykerEco\Zed\Minubo\Communication\MinuboCommunicationFactory getFactory()
16
 * @method \SprykerEco\Zed\Minubo\Business\MinuboFacadeInterface getFacade()
17
 */
18
class CustomerSecureFieldFilterPlugin extends AbstractPlugin implements MinuboDataFilterInterface
19
{
20
    /**
21
     * @var array
22
     */
23
    protected $defaultFilterFields = [
24
        'password',
25
        'restore_password_date',
26
        'restore_password_key',
27
        'registration_key',
28
    ];
29
30
    /**
31
     * {@inheritDoc}
32
     *
33
     * @api
34
     *
35
     * @param array $data
36
     *
37
     * @return array
38
     */
39
    public function filterData(array $data): array
40
    {
41
        $secureFields = $this->getFilterFields();
42
        foreach ($data as $key => $value) {
43
            if (in_array($key, $secureFields)) {
44
                unset($data[$key]);
45
            }
46
        }
47
48
        return $data;
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    protected function getFilterFields()
55
    {
56
        $configFields = $this->getConfig()
57
            ->getCustomerSecureFields();
58
59
        return array_merge($configFields, $this->defaultFilterFields);
60
    }
61
}
62