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.

Issues (203)

MessageQueue/Newsletter/ExportContactConsumer.php (1 issue)

Labels
Severity
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\MessageQueue\Newsletter;
7
8
use CommerceLeague\ActiveCampaign\Api\ContactRepositoryInterface;
9
use CommerceLeague\ActiveCampaign\Gateway\Client;
10
use CommerceLeague\ActiveCampaign\Gateway\Request\ContactBuilder as ContactRequestBuilder;
11
use CommerceLeague\ActiveCampaign\Logger\Logger;
12
use CommerceLeague\ActiveCampaign\MessageQueue\ConsumerInterface;
13
use CommerceLeague\ActiveCampaignApi\Exception\HttpException;
14
use CommerceLeague\ActiveCampaignApi\Exception\UnprocessableEntityHttpException;
15
use Magento\Framework\Exception\CouldNotSaveException;
16
use Magento\Newsletter\Model\SubscriberFactory;
0 ignored issues
show
The type Magento\Newsletter\Model\SubscriberFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Magento\Newsletter\Model\Subscriber;
18
19
/**
20
 * Class ExportContactConsumer
21
 */
22
class ExportContactConsumer implements ConsumerInterface
23
{
24
    /**
25
     * @var SubscriberFactory
26
     */
27
    private $subscriberFactory;
28
29
    /**
30
     * @var Logger
31
     */
32
    private $logger;
33
34
    /**
35
     * @var ContactRepositoryInterface
36
     */
37
    private $contactRepository;
38
39
    /**
40
     * @var ContactRequestBuilder
41
     */
42
    private $contactRequestBuilder;
43
44
    /**
45
     * @var Client
46
     */
47
    private $client;
48
49
    /**
50
     * @param SubscriberFactory $subscriberFactory
51
     * @param Logger $logger
52
     * @param ContactRepositoryInterface $contactRepository
53
     * @param ContactRequestBuilder $contactRequestBuilder
54
     * @param Client $client
55
     */
56
    public function __construct(
57
        SubscriberFactory $subscriberFactory,
58
        Logger $logger,
59
        ContactRepositoryInterface $contactRepository,
60
        ContactRequestBuilder $contactRequestBuilder,
61
        Client $client
62
    ) {
63
        $this->subscriberFactory = $subscriberFactory;
64
        $this->logger = $logger;
65
        $this->contactRepository = $contactRepository;
66
        $this->contactRequestBuilder = $contactRequestBuilder;
67
        $this->client = $client;
68
    }
69
70
    /**
71
     * @param string $message
72
     * @throws CouldNotSaveException
73
     */
74
    public function consume(string $message): void
75
    {
76
        $message = json_decode($message, true);
77
78
        /** @var Subscriber $subscriber */
79
        $subscriber = $this->subscriberFactory->create();
80
        $subscriber = $subscriber->loadByEmail($message['email']);
81
82
        if (!$subscriber->getId()) {
83
            $this->logger->error(__('The Subscriber with the "%1" email doesn\'t exist', $message['email']));
84
            return;
85
        }
86
87
        $contact = $this->contactRepository->getOrCreateByEmail($subscriber->getEmail());
88
        $request = $this->contactRequestBuilder->buildWithSubscriber($subscriber);
89
90
        try {
91
            $apiResponse = $this->client->getContactApi()->upsert(['contact' => $request]);
92
        } catch (UnprocessableEntityHttpException $e) {
93
            $this->logger->error($e->getMessage());
94
            $this->logger->error(print_r($e->getResponseErrors(), true));
95
            return;
96
        } catch (HttpException $e) {
97
            $this->logger->error($e->getMessage());
98
            return;
99
        }
100
101
        $contact->setActiveCampaignId($apiResponse['contact']['id']);
102
        $this->contactRepository->save($contact);
103
    }
104
}
105