DissociateDomain   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 52
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 22 3
A performAction() 0 4 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/domains/license
6
 * @link       https://www.flipboxfactory.com/software/domains/
7
 */
8
9
namespace flipbox\craft\domains\actions;
10
11
use flipbox\craft\ember\actions\ManageTrait;
12
use flipbox\craft\ember\helpers\SiteHelper;
13
use flipbox\craft\domains\records\Domain;
14
use yii\base\Action;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since  1.0.0
19
 */
20
class DissociateDomain extends Action
21
{
22
    use ManageTrait,
23
        ResolverTrait;
24
25
    /**
26
     * @var int
27
     */
28
    public $statusCodeSuccess = 201;
29
30
    /**
31
     * @param string $field
32
     * @param string $element
33
     * @param string $domain
34
     * @param int|null $siteId
35
     * @return mixed
36
     * @throws \yii\web\HttpException
37
     */
38
    public function run(
39
        string $field,
40
        string $element,
41
        string $domain,
42
        int $siteId = null
43
    ) {
44
45
        $field = $this->resolveField($field);
46
        $element = $this->resolveElement($element);
47
48
        $query = Domain::find();
49
        $query->setElement($element)
50
            ->setField($field)
51
            ->setDomain($domain)
52
            ->setSiteId(SiteHelper::ensureSiteId($siteId ?: $element->siteId));
53
54
        if (null === ($association = $query->one())) {
55
            return $this->handleSuccessResponse(true);
56
        }
57
58
        return $this->runInternal($association);
59
    }
60
61
    /**
62
     * @param Domain $record
63
     * @return bool
64
     * @throws \Throwable
65
     * @throws \yii\db\StaleObjectException
66
     */
67
    protected function performAction(Domain $record): bool
68
    {
69
        return $record->delete();
70
    }
71
}
72