Passed
Push — master ( ca7167...276d5c )
by Fabian
06:10
created

SaveConfig::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Firegento\DevDashboard\Plugin;
4
5
6
class SaveConfig
7
{
8
9
    protected $_whitelist =[
10
       'user_id',
11
       'configuration',
12
       'use_devdashboard'
13
    ];
14
15
    protected $_configRepository;
16
17
    protected $_messageManager;
18
19
    /**
20
     * SaveConfig constructor.
21
     * @param \Firegento\DevDashboard\Model\ConfigFactory $configRepository
0 ignored issues
show
Bug introduced by
The type Firegento\DevDashboard\Model\ConfigFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
     * @param \Magento\Framework\Message\ManagerInterface $messageManager
23
     */
24
    public function __construct(
25
        \Firegento\DevDashboard\Model\ConfigRepository $configRepository,
26
        \Magento\Framework\Message\ManagerInterface $messageManager
27
    ) {
28
        $this->_configRepository = $configRepository;
29
        $this->_messageManager = $messageManager;
30
    }
31
32
33
    /**
34
     * @param \Magento\User\Controller\Adminhtml\User\Save $subject
35
     * @return array|void
36
     * @throws \Exception
37
     */
38
    public function afterExecute(\Magento\User\Controller\Adminhtml\User\Save $subject)
0 ignored issues
show
Bug introduced by
The type Magento\User\Controller\Adminhtml\User\Save was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
    {
40
        $userId = (int)$subject->getRequest()->getParam('user_id');
41
        $data = $subject->getRequest()->getPostValue();
42
        $data = $this->_filterData($data);
43
44
        try {
45
46
            /** @var \Firegento\DevDashboard\Model\Config $model */
47
            $model = $this->_configRepository->getByUserId($userId);
48
            $model->setData($data);
49
            $this->_configRepository->save($model);
50
51
        } catch (\Exception $e) {
52
            $this->_messageManager->addErrorMessage($e->getMessage());
53
        }
54
        return [];
55
    }
56
57
    /**
58
     * @param $data
59
     * @return array
60
     */
61
    protected function _filterData($data)
62
    {
63
        $filtered = [];
64
65
        foreach($this->_whitelist as $key) {
66
            $filtered[$key] = $data[$key];
67
        }
68
        return $filtered;
69
    }
70
}