GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f9a184...b81ec7 )
by Andreas
04:10
created

ExportContactConsumer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
namespace CommerceLeague\ActiveCampaign\MessageQueue;
6
7
use CommerceLeague\ActiveCampaign\Api\ContactRepositoryInterface;
8
use CommerceLeague\ActiveCampaign\Helper\Client as ClientHelper;
9
use CommerceLeague\ActiveCampaign\Logger\Logger;
10
use CommerceLeague\ActiveCampaignApi\Exception\HttpException;
11
use Magento\Framework\Exception\CouldNotSaveException;
12
13
/**
14
 * Class ExportContactConsumer
15
 */
16
class ExportContactConsumer
17
{
18
    /**
19
     * @var ContactRepositoryInterface
20
     */
21
    private $contactRepository;
22
23
    /**
24
     * @var Logger
25
     */
26
    private $logger;
27
28
    /**
29
     * @var ClientHelper
30
     */
31
    private $clientHelper;
32
33
    /**
34
     * @param ContactRepositoryInterface $contactRepository
35
     * @param Logger $logger
36
     * @param ClientHelper $clientHelper
37
     */
38
    public function __construct(
39
        ContactRepositoryInterface $contactRepository,
40
        Logger $logger,
41
        ClientHelper $clientHelper
42
    ) {
43
        $this->contactRepository = $contactRepository;
44
        $this->logger = $logger;
45
        $this->clientHelper = $clientHelper;
46
    }
47
48
    /**
49
     * @param string $message
50
     * @throws CouldNotSaveException
51
     */
52
    public function consume(string $message): void
53
    {
54
        $message = json_decode($message, true);
55
        $contact = $this->contactRepository->getOrCreateByEmail($message['email']);
56
57
        try {
58
            $apiResponse = $this->clientHelper->getContactApi()->upsert(['contact' => $message['request']]);
59
        } catch (HttpException $e) {
60
            $this->logger->error($e->getMessage());
61
            return;
62
        }
63
64
        $contact->setActiveCampaignId($apiResponse['contact']['id']);
65
66
        $this->contactRepository->save($contact);
67
    }
68
}
69