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

AbstractWebhookCreator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 34
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A listWebhooks() 0 5 1
A __construct() 0 3 1
A deleteAllWebhooks() 0 6 2
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
 * Base class for webhook creators.
12
 */
13
abstract class AbstractWebhookCreator implements WebhookCreatorInterface
14
{
15
    /**
16
     * @var ShopifyApiFactory
17
     */
18
    protected $apis;
19
20
    /**
21
     * @param ShopifyApiFactory $apis
22
     */
23
    public function __construct(ShopifyApiFactory $apis)
24
    {
25
        $this->apis = $apis;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function listWebhooks(string $storeName)
32
    {
33
        $api = $this->apis->getForStore($storeName);
34
35
        return $api->Webhook->findAll();
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function deleteAllWebhooks(string $storeName)
42
    {
43
        $api = $this->apis->getForStore($storeName);
44
45
        foreach ($api->Webhook->findAll() as $webhook) {
46
            $api->Webhook->delete($webhook['id']);
47
        }
48
    }
49
}
50