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 ( 02a544...21c789 )
by Odiseo
03:34
created

SyncOrdersCommand::showError()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 4
nc 3
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusMailchimpPlugin\Command;
6
7
use Odiseo\SyliusMailchimpPlugin\Handler\OrderRegisterHandlerInterface;
8
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
9
use Sylius\Component\Core\Model\OrderInterface;
10
use Sylius\Component\Core\OrderPaymentStates;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Style\SymfonyStyle;
14
15
class SyncOrdersCommand extends BaseSyncCommand
16
{
17
    /**
18
     * @var EntityRepository
19
     */
20
    protected $orderRepository;
21
22
    /**
23
     * @var OrderRegisterHandlerInterface
24
     */
25
    protected $orderRegisterHandler;
26
27
    /**
28
     * @param EntityRepository $orderRepository
29
     * @param OrderRegisterHandlerInterface $orderRegisterHandler
30
     */
31
    public function __construct(
32
        EntityRepository $orderRepository,
33
        OrderRegisterHandlerInterface $orderRegisterHandler
34
    ) {
35
        parent::__construct();
36
37
        $this->orderRepository = $orderRepository;
38
        $this->orderRegisterHandler = $orderRegisterHandler;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function configure()
45
    {
46
        $this
47
            ->setName('odiseo:mailchimp:sync-orders')
48
            ->setDescription('Synchronize the orders to Mailchimp.')
49
        ;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        $this->io = new SymfonyStyle($input, $output);
58
59
        $this->io->title('Synchronizing the orders to Mailchimp');
60
61
        $this->registerOrders();
62
    }
63
64
    protected function registerOrders()
65
    {
66
        $orders = $this->orderRepository->createQueryBuilder('o')
67
            ->andWhere('o.paymentState = :paymentState')
68
            ->setParameter('paymentState', OrderPaymentStates::STATE_PAID)
69
            ->getQuery()
70
            ->getResult()
71
        ;
72
73
        $this->io->text('Connecting ' . count($orders) . ' carts.');
74
        $this->io->progressStart(count($orders));
75
76
        /** @var OrderInterface $order */
77
        foreach ($orders as $order) {
78
            try {
79
                $response = $this->orderRegisterHandler->register($order);
80
81
                if (!isset($response['id']) && $response !== false) {
82
                    $this->showError($response);
0 ignored issues
show
Bug introduced by
$response of type void is incompatible with the type array expected by parameter $response of Odiseo\SyliusMailchimpPl...yncCommand::showError(). ( Ignorable by Annotation )

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

82
                    $this->showError(/** @scrutinizer ignore-type */ $response);
Loading history...
83
                }
84
            } catch (\Exception $e) {
85
                $this->io->error($e->getMessage());
86
            }
87
88
            $this->io->progressAdvance(1);
89
        }
90
91
        $this->io->progressFinish();
92
        $this->io->success('The orders has been synchronized successfully.');
93
    }
94
}
95