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.

ExportAbandonedCartConsumer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 30
dl 0
loc 82
rs 10
c 1
b 0
f 1
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A consume() 0 29 4
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\MessageQueue\Quote;
7
8
use CommerceLeague\ActiveCampaign\Api\OrderRepositoryInterface;
9
use CommerceLeague\ActiveCampaign\Gateway\Client;
10
use CommerceLeague\ActiveCampaign\Logger\Logger;
11
use CommerceLeague\ActiveCampaign\MessageQueue\ConsumerInterface;
12
use CommerceLeague\ActiveCampaign\Gateway\Request\AbandonedCartBuilder;
13
use CommerceLeague\ActiveCampaignApi\Exception\HttpException;
14
use CommerceLeague\ActiveCampaignApi\Exception\UnprocessableEntityHttpException;
15
use Magento\Framework\Exception\CouldNotSaveException;
16
use Magento\Quote\Model\Quote;
17
use Magento\Quote\Model\QuoteFactory;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Model\QuoteFactory 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...
18
19
/**
20
 * Class ExportAbandonedCartConsumer
21
 */
22
class ExportAbandonedCartConsumer implements ConsumerInterface
23
{
24
    /**
25
     * @var QuoteFactory
26
     */
27
    private $quoteFactory;
28
29
    /**
30
     * @var Logger
31
     */
32
    private $logger;
33
34
    /**
35
     * @var OrderRepositoryInterface
36
     */
37
    private $orderRepository;
38
39
    /**
40
     * @var AbandonedCartBuilder
41
     */
42
    private $abandonedCartRequestBuilder;
43
44
    /**
45
     * @var Client
46
     */
47
    private $client;
48
49
    /**
50
     * @param QuoteFactory $quoteFactory
51
     * @param Logger $logger
52
     * @param OrderRepositoryInterface $orderRepository
53
     * @param AbandonedCartBuilder $abandonedCartRequestBuilder
54
     * @param Client $client
55
     */
56
    public function __construct(
57
        QuoteFactory $quoteFactory,
58
        Logger $logger,
59
        OrderRepositoryInterface $orderRepository,
60
        AbandonedCartBuilder $abandonedCartRequestBuilder,
61
        Client $client
62
    ) {
63
        $this->quoteFactory = $quoteFactory;
64
        $this->logger = $logger;
65
        $this->orderRepository = $orderRepository;
66
        $this->abandonedCartRequestBuilder = $abandonedCartRequestBuilder;
67
        $this->client = $client;
68
    }
69
70
    /**
71
     * @param string $message
72
     * @throws CouldNotSaveException
73
     * @throws \Exception
74
     */
75
    public function consume(string $message): void
76
    {
77
        $message = json_decode($message, true);
78
79
        /** @var Quote $quote */
80
        $quote = $this->quoteFactory->create();
81
        $quote->loadByIdWithoutStore($message['quote_id']);
82
83
        if (!$quote->getId()) {
84
            $this->logger->error(__('The Quote with the "%1" ID doesn\'t exist', $message['quote_id']));
85
            return;
86
        }
87
88
        $order = $this->orderRepository->getOrCreateByMagentoQuoteId($quote->getId());
89
        $request = $this->abandonedCartRequestBuilder->build($quote);
90
91
        try {
92
            $apiResponse = $this->client->getOrderApi()->create(['ecomOrder' => $request]);
93
        } catch (UnprocessableEntityHttpException $e) {
94
            $this->logger->error($e->getMessage());
95
            $this->logger->error(print_r($e->getResponseErrors(), true));
96
            return;
97
        } catch (HttpException $e) {
98
            $this->logger->error($e->getMessage());
99
            return;
100
        }
101
102
        $order->setActiveCampaignId($apiResponse['ecomOrder']['id']);
103
        $this->orderRepository->save($order);
104
    }
105
}
106