Completed
Push — develop ( 0ca1ab...29c245 )
by Nate
03:14
created

ConnectionTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 43
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A connection() 0 4 1
A setConnection() 0 5 1
A getConnection() 0 12 3
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\criteria\traits;
10
11
use flipbox\hubspot\connections\ConnectionInterface;
12
use flipbox\hubspot\HubSpot;
13
use flipbox\hubspot\services\Connections;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
trait ConnectionTrait
20
{
21
    /**
22
     * @var ConnectionInterface|string
23
     */
24
    protected $connection = Connections::DEFAULT_CONNECTION;
25
26
    /**
27
     * @param $value
28
     * @return $this
29
     */
30
    public function connection($value)
31
    {
32
        return $this->setConnection($value);
33
    }
34
35
    /**
36
     * @param $value
37
     * @return $this
38
     */
39
    public function setConnection($value)
40
    {
41
        $this->connection = $value;
42
        return $this;
43
    }
44
45
    /**
46
     * @return ConnectionInterface
47
     * @throws \yii\base\InvalidConfigException
48
     */
49
    public function getConnection(): ConnectionInterface
50
    {
51
        if ($this->connection instanceof ConnectionInterface) {
52
            return $this->connection;
53
        }
54
55
        if ($this->connection === null) {
56
            $this->connection = Connections::DEFAULT_CONNECTION;
57
        }
58
59
        return $this->connection = HubSpot::getInstance()->getConnections()->get($this->connection);
60
    }
61
}
62