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 ( d8327a...c6d836 )
by Andreas
03:23
created

CreateUpdateCustomerObserver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 12
rs 10
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Observer\Customer;
7
8
use CommerceLeague\ActiveCampaign\Api\ContactRepositoryInterface;
9
use CommerceLeague\ActiveCampaign\Api\CustomerRepositoryInterface;
10
use CommerceLeague\ActiveCampaign\Logger\Logger;
11
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper;
12
use CommerceLeague\ActiveCampaign\MessageQueue\Customer\CreateMessageBuilder;
13
use CommerceLeague\ActiveCampaign\MessageQueue\Topics;
14
use Magento\Customer\Model\Customer;
15
use Magento\Framework\Event\Observer;
16
use Magento\Framework\Event\ObserverInterface;
17
use Magento\Framework\Exception\CouldNotSaveException;
18
use Magento\Framework\MessageQueue\PublisherInterface;
19
20
/**
21
 * Class CreateUpdateCustomerObserver
22
 */
23
class CreateUpdateCustomerObserver implements ObserverInterface
24
{
25
    /**
26
     * @var ConfigHelper
27
     */
28
    private $configHelper;
29
30
    /**
31
     * @var ContactRepositoryInterface
32
     */
33
    private $customerRepository;
34
35
    /**
36
     * @var Logger
37
     */
38
    private $logger;
39
40
    /**
41
     * @var CreateMessageBuilder
42
     */
43
    private $createMessageBuilder;
44
45
    /**
46
     * @var PublisherInterface
47
     */
48
    private $publisher;
49
50
    /**
51
     * @param ConfigHelper $configHelper
52
     * @param CustomerRepositoryInterface $customerRepository
53
     * @param Logger $logger
54
     * @param CreateMessageBuilder $createMessageBuilder
55
     * @param PublisherInterface $publisher
56
     */
57
    public function __construct(
58
        ConfigHelper $configHelper,
59
        CustomerRepositoryInterface $customerRepository,
60
        Logger $logger,
61
        CreateMessageBuilder $createMessageBuilder,
62
        PublisherInterface $publisher
63
    ) {
64
        $this->configHelper = $configHelper;
65
        $this->customerRepository = $customerRepository;
0 ignored issues
show
Documentation Bug introduced by
It seems like $customerRepository of type CommerceLeague\ActiveCam...omerRepositoryInterface is incompatible with the declared type CommerceLeague\ActiveCam...tactRepositoryInterface of property $customerRepository.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
66
        $this->logger = $logger;
67
        $this->createMessageBuilder = $createMessageBuilder;
68
        $this->publisher = $publisher;
69
    }
70
71
    /**
72
     * @inheritDoc
73
     */
74
    public function execute(Observer $observer)
75
    {
76
        if (!$this->configHelper->isApiEnabled()) {
77
            return;
78
        }
79
80
        /** @var Customer $magentoCustomer */
81
        $magentoCustomer = $observer->getEvent()->getData('customer');
82
83
        try {
84
            $customer = $this->customerRepository->getOrCreateByMagentoCustomer($magentoCustomer);
0 ignored issues
show
Bug introduced by
The method getOrCreateByMagentoCustomer() does not exist on CommerceLeague\ActiveCam...tactRepositoryInterface. Did you maybe mean getOrCreateByCustomer()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
            /** @scrutinizer ignore-call */ 
85
            $customer = $this->customerRepository->getOrCreateByMagentoCustomer($magentoCustomer);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
85
        } catch (CouldNotSaveException $e) {
86
            $this->logger->critical($e);
87
            return;
88
        }
89
90
        if ($customer->getActiveCampaignId()) {
91
            // TODO::publish update message
92
        } else {
93
            $this->publisher->publish(
94
                Topics::CUSTOMER_CREATE,
95
                $this->createMessageBuilder->build($customer, $magentoCustomer)
96
            );
97
        }
98
    }
99
}
100