Test Failed
Push — develop ( 9e3f9b...05a047 )
by Edwin
02:28
created

Client::getResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace ShopifyClient;
4
5
use ShopifyClient\Resource\Customer;
6
use ShopifyClient\Resource\Order;
7
use ShopifyClient\Resource\Product;
8
use ShopifyClient\Resource\Resource;
9
use ShopifyClient\Resource\Shop;
10
11
/**
12
 * @property Order $orders
13
 * @property Product $products
14
 * @property Customer $customer
15
 * @property Shop $shop
16
 */
17
class Client
18
{
19
    const API_URL = 'https://%s:%s@%s';
20
21
    /**
22
     * @var Config
23
     */
24
    private $config;
25
26
    /**
27
     * @var ResourceCollection
28
     */
29
    private $resources;
30
31
    /**
32
     * Client constructor.
33
     * @param Config $config
34
     */
35 3
    public function __construct(Config $config)
36
    {
37 3
        $this->config = $config;
38
39 3
        $this->initializeHttpClient();
40 1
    }
41
42 3
    private function initializeHttpClient()
43
    {
44 3
        $httpClient = new \GuzzleHttp\Client([
45 3
            'base_uri' => sprintf(
46 3
                self::API_URL,
47 3
                $this->config->getKey(),
48 3
                $this->config->getSecret(),
49 3
                $this->config->getDomain()
50
            ),
51
        ]);
52
53 3
        $this->resources = new ResourceCollection($httpClient, $this->config->getResources());
54 1
    }
55
56
    /**
57
     * @param $name
58
     * @return Resource
59
     */
60 2
    public function getResource(string $name): Resource
61
    {
62 2
        return $this->resources->getResource($name);
63
    }
64
65
    /**
66
     * @param $name
67
     * @return Resource
68
     */
69 42
    public function __get(string $name): Resource
70
    {
71 42
        return $this->resources->getResource($name);
72
    }
73
}
74