DissociateUserFromOrganization::performAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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 flipbox\craft\ember\actions\records\DeleteRecordTrait;
12
use flipbox\organizations\records\UserAssociation;
13
use yii\base\Action;
14
use yii\web\HttpException;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 3.0.0
19
 */
20
class DissociateUserFromOrganization extends Action
21
{
22
    use DeleteRecordTrait, LookupAssociationTrait;
23
24
    /**
25
     * @param string $user
26
     * @param string $organization
27
     * @return null|\yii\base\Model|\yii\web\Response
28
     * @throws HttpException
29
     */
30
    public function run(
31
        string $user,
32
        string $organization
33
    ) {
34
        if (null === ($user = $this->findUser($user))) {
35
            return $this->handleNotFoundResponse();
36
        }
37
38
        if (null === ($organization = $this->findOrganization($organization))) {
39
            return $this->handleNotFoundResponse();
40
        }
41
42
        return $this->runInternal(
43
            $organization->getUsers()->findOrCreate($user)
44
        );
45
    }
46
47
    /**
48
     * @param UserAssociation $association
49
     * @return bool
50
     * @throws \Throwable
51
     * @throws \yii\db\StaleObjectException
52
     */
53
    protected function performAction(UserAssociation $association): bool
54
    {
55
        return (bool) $association->delete();
56
    }
57
}
58