Completed
Push — master ( a6a629...1492ab )
by Oleksandr
10s
created

CustomerSecureFieldFilterPlugin::filterData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 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
     * @param array $data
32
     *
33
     * @return array
34
     */
35
    public function filterData(array $data): array
36
    {
37
        $secureFields = $this->getFilterFields();
38
        foreach ($data as $key => $value) {
39
            if (in_array($key, $secureFields)) {
40
                unset($data[$key]);
41
            }
42
        }
43
44
        return $data;
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    protected function getFilterFields()
51
    {
52
        $configFields = $this->getConfig()
53
            ->getCustomerSecureFields();
54
55
        return array_merge($configFields, $this->defaultFilterFields);
56
    }
57
}
58