Completed
Push — master ( 8ae47d...5423c6 )
by Nate
17:42 queued 15:46
created

AbstractAssociationAction::resolveField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
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/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\hubspot\actions\objects;
10
11
use flipbox\ember\actions\model\traits\Manage;
12
use flipbox\ember\exceptions\RecordNotFoundException;
13
use flipbox\hubspot\actions\traits\ElementResolverTrait;
14
use flipbox\hubspot\actions\traits\FieldResolverTrait;
15
use flipbox\hubspot\records\ObjectAssociation;
16
use yii\base\Action;
17
use yii\base\Model;
18
19
/**
20
 * @author Flipbox Factory <[email protected]>
21
 * @since  1.0.0
22
 */
23
abstract class AbstractAssociationAction extends Action
24
{
25
    use Manage,
26
        FieldResolverTrait,
27
        ElementResolverTrait;
28
29
    /**
30
     * @param Model $model
31
     * @return bool
32
     * @throws RecordNotFoundException
33
     */
34
    protected function ensureAssociation(Model $model): bool
35
    {
36
        if (!$model instanceof ObjectAssociation) {
37
            throw new RecordNotFoundException(sprintf(
38
                "HubSpot Resource Association must be an instance of '%s', '%s' given.",
39
                ObjectAssociation::class,
40
                get_class($model)
41
            ));
42
        }
43
44
        return true;
45
    }
46
}
47