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

OrderBuilder::convertToCent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
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\Sales\Api\Data\OrderInterface as MagentoOrderInterface;
11
use Magento\Sales\Model\Order as MagentoOrder;
12
13
/**
14
 * Class OrderBuilder
15
 */
16
class OrderBuilder extends AbstractBuilder
17
{
18
    /**
19
     * @var ConfigHelper
20
     */
21
    private $configHelper;
22
23
    /**
24
     * @var CustomerRepositoryInterface
25
     */
26
    private $customerRepository;
27
28
    /**
29
     * @param ConfigHelper $configHelper
30
     * @param CustomerRepositoryInterface $customerRepository
31
     */
32
    public function __construct(
33
        ConfigHelper $configHelper,
34
        CustomerRepositoryInterface $customerRepository
35
    ) {
36
        $this->configHelper = $configHelper;
37
        $this->customerRepository = $customerRepository;
38
    }
39
40
    /**
41
     * @param MagentoOrderInterface|MagentoOrder $magentoOrder
42
     * @return array
43
     * @throws \Exception
44
     */
45
    public function build(MagentoOrderInterface $magentoOrder): array
46
    {
47
        $customer = $this->customerRepository->getByMagentoCustomerId($magentoOrder->getCustomerId());
48
49
        $request = [
50
            'externalid' => $magentoOrder->getId(),
51
            'source' => 1,
52
            'email' => $magentoOrder->getCustomerEmail(),
53
            'orderNumber' => $magentoOrder->getIncrementId(),
54
            'orderDate' => $this->formatDateTime($magentoOrder->getCreatedAt()),
0 ignored issues
show
Bug introduced by
It seems like $magentoOrder->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

54
            'orderDate' => $this->formatDateTime(/** @scrutinizer ignore-type */ $magentoOrder->getCreatedAt()),
Loading history...
55
            'shippingMethod' => $magentoOrder->getShippingMethod(),
0 ignored issues
show
Bug introduced by
The method getShippingMethod() does not exist on Magento\Sales\Api\Data\OrderInterface. Did you maybe mean getShippingAmount()? ( Ignorable by Annotation )

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

55
            'shippingMethod' => $magentoOrder->/** @scrutinizer ignore-call */ getShippingMethod(),

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...
56
            'totalPrice' => $this->convertToCent((float)$magentoOrder->getGrandTotal()),
57
            'currency' => $magentoOrder->getBaseCurrencyCode(),
58
            'connectionid' => $this->configHelper->getConnectionId(),
59
            'customerid' => $customer->getActiveCampaignId(),
60
            'orderProducts' => []
61
        ];
62
63
        /** @var MagentoOrder\Item $magentoOrderItem */
64
        foreach ($magentoOrder->getAllVisibleItems() as $magentoOrderItem) {
65
            $request['orderProducts'][] = [
66
                'externalid' => $magentoOrderItem->getSku(),
67
                'name' => $magentoOrderItem->getName(),
68
                'price' => $this->convertToCent((float)$magentoOrderItem->getPriceInclTax()),
69
                'quantity' => (int)$magentoOrderItem->getQtyOrdered(),
70
                'productUrl' => $magentoOrderItem->getProduct()->getProductUrl(),
71
            ];
72
        }
73
74
        return $request;
75
    }
76
}
77