StockbaseClientFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 10
ccs 0
cts 5
cp 0
crap 2
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
4
namespace Stockbase\Integration\StockbaseApi\Client;
5
6
use Stockbase\Integration\StockbaseApi\Client\DivideIQ\DivideIQClientFactory;
7
use Stockbase\Integration\Model\Config\StockbaseConfiguration;
8
use Magento\Framework\ObjectManagerInterface;
9
use Psr\Log\LoggerInterface;
10
11
/**
12
 * StockbaseClient Factory
13
 */
14
class StockbaseClientFactory
15
{
16
    
17
    /**
18
     * @var ObjectManagerInterface
19
     */
20
    protected $objectManager;
21
22
    /**
23
     * @var string
24
     */
25
    protected $instanceName;
26
    
27
    /**
28
     * @var DivideIQClientFactory
29
     */
30
    private $divideIQClientFactory;
31
32
    /**
33
     * StockbaseClientFactory constructor.
34
     * @param ObjectManagerInterface $objectManager
35
     * @param DivideIQClientFactory  $divideIQClientFactory
36
     * @param string                 $instanceName
37
     */
38
    public function __construct(
39
        ObjectManagerInterface $objectManager,
40
        DivideIQClientFactory $divideIQClientFactory,
41
        $instanceName = StockbaseClient::class
42
    ) {
43
    
44
        $this->objectManager = $objectManager;
45
        $this->instanceName = $instanceName;
46
        $this->divideIQClientFactory = $divideIQClientFactory;
47
    }
48
49
    /**
50
     * Create class instance with specified parameters
51
     *
52
     * @param array $data
53
     * @return StockbaseClient
54
     */
55
    public function create(array $data = [])
56
    {
57
        if (!isset($data['divideIqClient'])) {
58
            $data['divideIqClient'] = $this->divideIQClientFactory->create();
59
        }
60
        
61
        return $this->objectManager->create($this->instanceName, $data);
62
    }
63
}
64