Passed
Pull Request — master (#9)
by Daniel
03:01
created

WebhookCreatorRemote   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 33
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createWebhooks() 0 12 2
A __construct() 0 5 1
1
<?php
2
3
namespace CodeCloud\Bundle\ShopifyBundle\Service;
4
5
use CodeCloud\Bundle\ShopifyBundle\Api\GenericResource;
6
use CodeCloud\Bundle\ShopifyBundle\Api\ShopifyApiFactory;
7
use GuzzleHttp\Exception\ClientException;
8
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
9
10
/**
11
 * Creates Webhooks to be received by a remote endpoint.
12
 */
13
class WebhookCreatorRemote extends AbstractWebhookCreator
14
{
15
    /**
16
     * @var string
17
     */
18
    private $webhookUrl;
19
20
    /**
21
     * @param ShopifyApiFactory $apis
22
     * @param string $webhookUrl
23
     */
24
    public function __construct(ShopifyApiFactory $apis, $webhookUrl)
25
    {
26
        $this->webhookUrl = $webhookUrl;
27
28
        parent::__construct($apis);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function createWebhooks(string $storeName, array $topics)
35
    {
36
        $api = $this->apis->getForStore($storeName);
37
38
        foreach ($topics as $topic) {
39
            $webhook = GenericResource::create([
40
                'topic' => $topic,
41
                'address' => $this->webhookUrl,
42
                'format' => 'json',
43
            ]);
44
45
            $api->Webhook->create($webhook);
46
        }
47
    }
48
}
49