DivideIQClientFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A create() 0 12 1
1
<?php
2
3
4
namespace Stockbase\Integration\StockbaseApi\Client\DivideIQ;
5
6
use DivideBV\PHPDivideIQ\DivideIQ;
7
use Magento\Framework\ObjectManagerInterface;
8
use Stockbase\Integration\Model\Config\StockbaseConfiguration;
9
10
/**
11
 * DivideIQ client factory.
12
 */
13
class DivideIQClientFactory
14
{
15
    /**
16
     * @var ObjectManagerInterface
17
     */
18
    protected $objectManager;
19
20
    /**
21
     * @var string
22
     */
23
    protected $instanceName;
24
25
    /**
26
     * @var StockbaseConfiguration
27
     */
28
    protected $config;
29
30
    /**
31
     * DivideIQClientFactory constructor.
32
     * @param ObjectManagerInterface $objectManager
33
     * @param StockbaseConfiguration $config
34
     * @param string                 $instanceName
35
     */
36
    public function __construct(
37
        ObjectManagerInterface $objectManager,
38
        StockbaseConfiguration $config,
39
        $instanceName = DivideIQ::class
40
    ) {
41
        $this->objectManager = $objectManager;
42
        $this->instanceName = $instanceName;
43
        $this->config = $config;
44
    }
45
46
    /**
47
     * Create class instance with specified parameters
48
     *
49
     * @param array $data
50
     * @return DivideIQ
51
     */
52
    public function create(array $data = [])
53
    {
54
        //TODO: Cache authentication state using DivideIQ::fromJson() and DivideIQ::toJson()
55
        
56
        $data = array_merge([
57
            'username' => $this->config->getUsername(),
58
            'password' => $this->config->getPassword(),
59
            'environment' => $this->config->getEnvironment(),
60
        ], $data);
61
        
62
        return $this->objectManager->create($this->instanceName, $data);
63
    }
64
}
65