CreateProvider::newRecord()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 0
cp 0
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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 flipbox\craft\ember\actions\records\CreateRecord;
12
use flipbox\patron\records\Provider;
13
use yii\db\ActiveRecord;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class CreateProvider extends CreateRecord
20
{
21
    use PopulateSettingsTrait;
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public $validBodyParams = [
27
        'handle',
28
        'clientId',
29
        'clientSecret',
30
        'scopes',
31
        'class',
32
        'enabled'
33
    ];
34
35
    /**
36
     * @param ActiveRecord|Provider $record
37
     * @return ActiveRecord
38
     */
39
    protected function populate(ActiveRecord $record): ActiveRecord
40
    {
41
        parent::populate($record);
42
        $this->populateSettings($record);
43
44
        return $record;
45
    }
46
47
    /**
48
     * @inheritdoc
49
     * @return Provider
50
     */
51
    protected function newRecord(array $config = []): ActiveRecord
52
    {
53
        /** @var Provider $record */
54
        $record = new Provider();
55
56
        // Do we need to set properties too
57
        if (!empty($config)) {
58
            $record->setAttributes($config);
59
        }
60
61
        return $record;
62
    }
63
}
64