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.
Passed
Push — master ( f51f95...468920 )
by Andreas
03:39
created

AbandonedCartBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 26
c 1
b 0
f 1
dl 0
loc 58
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 29 2
A __construct() 0 6 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Gateway\Request;
7
8
use CommerceLeague\ActiveCampaign\Api\CustomerRepositoryInterface;
9
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper;
10
use Magento\Quote\Model\Quote;
11
12
/**
13
 * Class AbandonedCartRequestBuilder
14
 */
15
class AbandonedCartBuilder extends AbstractBuilder
16
{
17
    /**
18
     * @var ConfigHelper
19
     */
20
    private $configHelper;
21
22
    /**
23
     * @var CustomerRepositoryInterface
24
     */
25
    private $customerRepository;
26
27
    /**
28
     * @param ConfigHelper $configHelper
29
     * @param CustomerRepositoryInterface $customerRepository
30
     */
31
    public function __construct(
32
        ConfigHelper $configHelper,
33
        CustomerRepositoryInterface $customerRepository
34
    ) {
35
        $this->configHelper = $configHelper;
36
        $this->customerRepository = $customerRepository;
37
    }
38
39
    /**
40
     * @param Quote $quote
41
     * @return array
42
     * @throws \Exception
43
     */
44
    public function build(Quote $quote): array
45
    {
46
        $customer = $this->customerRepository->getByMagentoCustomerId($quote->getData('customer_id'));
47
48
        $request = [
49
            'externalcheckoutid' => $quote->getId(),
50
            'source' => 1,
51
            'email' => $quote->getData('customer_email'),
52
            'externalCreatedDate' => $this->formatDateTime($quote->getCreatedAt()),
0 ignored issues
show
Bug introduced by
It seems like $quote->getCreatedAt() can also be of type null; however, parameter $date of CommerceLeague\ActiveCam...ilder::formatDateTime() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

52
            'externalCreatedDate' => $this->formatDateTime(/** @scrutinizer ignore-type */ $quote->getCreatedAt()),
Loading history...
53
            'externalUpdatedDate' => $this->formatDateTime($quote->getUpdatedAt()),
54
            'abandonedDate' => $this->formatDateTime($quote->getUpdatedAt()),
55
            'totalPrice' => $this->convertToCent((float)$quote->getData('grand_total')),
56
            'currency' => $quote->getData('base_currency_code'),
57
            'connectionid' => $this->configHelper->getConnectionId(),
58
            'customerid' => $customer->getActiveCampaignId(),
59
            'orderProducts' => []
60
        ];
61
62
        foreach ($quote->getAllVisibleItems() as $quoteItem) {
63
            $request['orderProducts'][] = [
64
                'externalid' => $quoteItem->getSku(),
65
                'name' => $quoteItem->getName(),
66
                'price' => $this->convertToCent((float)$quoteItem->getPriceInclTax()),
67
                'quantity' => (int)$quoteItem->getQty(),
68
                'productUrl' => $quoteItem->getProduct()->getProductUrl(),
69
            ];
70
        }
71
72
        return $request;
73
    }
74
}
75