ConnectionTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 47
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A connection() 0 4 1
A setConnection() 0 5 1
A getConnection() 0 4 1
A resolveConnection() 0 8 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/salesforce/blob/master/LICENSE.md
6
 * @link       https://github.com/flipbox/salesforce
7
 */
8
9
namespace Flipbox\Salesforce\Criteria;
10
11
use Flipbox\Salesforce\Connections\ConnectionInterface;
12
use Flipbox\Salesforce\Salesforce;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 3.3.0
17
 */
18
trait ConnectionTrait
19
{
20
    /**
21
     * @var ConnectionInterface|null
22
     */
23
    protected $connection;
24
25
    /**
26
     * @param $value
27
     * @return $this
28
     */
29
    public function connection($value)
30
    {
31
        return $this->setConnection($value);
32
    }
33
34
    /**
35
     * @param $value
36
     * @return $this
37
     */
38
    public function setConnection($value)
39
    {
40
        $this->connection = $value;
41
        return $this;
42
    }
43
44
    /**
45
     * @return ConnectionInterface
46
     */
47
    public function getConnection(): ConnectionInterface
48
    {
49
        return $this->connection = $this->resolveConnection($this->connection);
50
    }
51
52
    /**
53
     * @param $connection
54
     * @return ConnectionInterface
55
     */
56
    protected function resolveConnection($connection)
57
    {
58
        if ($connection instanceof ConnectionInterface) {
59
            return $connection;
60
        }
61
62
        return Salesforce::getConnection();
63
    }
64
}
65