Completed
Push — master ( 87f5f3...5d6f7d )
by Nate
03:14
created

PopulateSettingsTrait::populateSettings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/patron/license
6
 * @link       https://www.flipboxfactory.com/software/patron/
7
 */
8
9
namespace flipbox\patron\actions\provider;
10
11
use Craft;
12
use flipbox\patron\records\Provider;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 2.1.0
17
 */
18
trait PopulateSettingsTrait
19
{
20
    /**
21
     * @param Provider $record
22
     * @return Provider
23
     */
24
    protected function populateSettings(Provider $record): Provider
25
    {
26
        $allSettings = Craft::$app->getRequest()->getBodyParam('settings');
27
28
        if (!is_array($allSettings)) {
29
            $allSettings = [$allSettings];
30
        }
31
32
        $record->settings = $allSettings[$record->class] ?? null;
33
        ;
34
35
        return $record;
36
    }
37
}
38