Completed
Push — develop ( 404ef8...8e1225 )
by Nate
02:57
created

AssociateUserToOrganization::populate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 11
cp 0
rs 9.8333
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/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organizations\actions\organizations;
10
11
use Craft;
12
use flipbox\craft\ember\actions\records\SaveRecordTrait;
13
use flipbox\organizations\records\UserAssociation;
14
use yii\base\Action;
15
use yii\db\ActiveRecord;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 3.0.0
20
 */
21
class AssociateUserToOrganization extends Action
22
{
23
    use SaveRecordTrait, LookupAssociationTrait;
24
25
    /**
26
     * @var array
27
     */
28
    public $validBodyParams = [
29
        'sortOrder' => 'userOrder',
30
        'state'
31
    ];
32
33
    /**
34
     * @inheritdoc
35
     * @param UserAssociation $record
0 ignored issues
show
Bug introduced by
There is no parameter named $record. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
36
     * @return bool
37
     */
38
    protected function performAction(UserAssociation $association): bool
39
    {
40
        return $association->save();
41
    }
42
43
    /**
44
     * Body params that should be set on the record.
45
     *
46
     * @return array
47
     */
48
    protected function validBodyParams(): array
49
    {
50
        return $this->validBodyParams;
51
    }
52
53
    /**
54
     * @param UserAssociation $record
55
     * @inheritDoc
56
     */
57
    protected function populate(UserAssociation $record): ActiveRecord
58
    {
59
        $record->setAttributes(
60
            $this->attributeValuesFromBody()
61
        );
62
63
        $types = Craft::$app->getRequest()->getBodyParam('types', []);
64
        if (!empty($types)) {
65
            $record->getTypes()->clear()->add($types);
66
        }
67
68
        return $record;
69
    }
70
}
71