ShopifyApiFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getForStore() 0 6 1
1
<?php
2
3
namespace CodeCloud\Bundle\ShopifyBundle\Api;
4
5
use CodeCloud\Bundle\ShopifyBundle\Model\ShopifyStoreManagerInterface;
6
7
/**
8
 * Creates ShopifyApi instances.
9
 */
10
class ShopifyApiFactory
11
{
12
    /**
13
     * @var ShopifyStoreManagerInterface
14
     */
15
    private $storeManager;
16
17
    /**
18
     * @var HttpClientFactoryInterface
19
     */
20
    private $httpClientFactory;
21
22
    /**
23
     * @var string
24
     */
25
    private $apiVersion;
26
27
    /**
28
     * @param ShopifyStoreManagerInterface $storeManager
29
     * @param HttpClientFactoryInterface $httpClientFactory
30
     * @param string $apiVersion
31
     */
32
    public function __construct(
33
        ShopifyStoreManagerInterface $storeManager,
34
        HttpClientFactoryInterface $httpClientFactory,
35
        $apiVersion = null
36
    ) {
37
        $this->storeManager = $storeManager;
38
        $this->httpClientFactory = $httpClientFactory;
39
        $this->apiVersion = $apiVersion;
40
    }
41
42
    /**
43
     * @param string $storeName
44
     * @return ShopifyApi
45
     */
46
    public function getForStore($storeName)
47
    {
48
        $accessToken = $this->storeManager->getAccessToken($storeName);
49
        $client = $this->httpClientFactory->createHttpClient($storeName, new PublicAppCredentials($accessToken));
50
51
        return new ShopifyApi($client, $this->apiVersion);
52
    }
53
}
54