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

SyncCartsCommand::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\CartRegisterHandlerInterface;
8
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
9
use Sylius\Component\Core\Model\OrderInterface;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Style\SymfonyStyle;
13
14
class SyncCartsCommand extends BaseSyncCommand
15
{
16
    /**
17
     * @var EntityRepository
18
     */
19
    protected $orderRepository;
20
21
    /**
22
     * @var CartRegisterHandlerInterface
23
     */
24
    protected $cartRegisterHandler;
25
26
    /**
27
     * @param EntityRepository $orderRepository
28
     * @param CartRegisterHandlerInterface $cartRegisterHandler
29
     */
30
    public function __construct(
31
        EntityRepository $orderRepository,
32
        CartRegisterHandlerInterface $cartRegisterHandler
33
    ) {
34
        parent::__construct();
35
36
        $this->orderRepository = $orderRepository;
37
        $this->cartRegisterHandler = $cartRegisterHandler;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function configure()
44
    {
45
        $this
46
            ->setName('odiseo:mailchimp:sync-carts')
47
            ->setDescription('Synchronize the carts to Mailchimp.')
48
        ;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        $this->io = new SymfonyStyle($input, $output);
57
58
        $this->io->title('Synchronizing the carts to Mailchimp');
59
60
        $this->registerCarts();
61
    }
62
63
    protected function registerCarts()
64
    {
65
        $orders = $this->orderRepository->createQueryBuilder('o')
66
            ->where('o.customer IS NOT NULL')
67
            ->getQuery()
68
            ->getResult()
69
        ;
70
71
        $this->io->text('Connecting ' . count($orders) . ' carts.');
72
        $this->io->progressStart(count($orders));
73
74
        /** @var OrderInterface $order */
75
        foreach ($orders as $order) {
76
            try {
77
                $response = $this->cartRegisterHandler->register($order);
78
79
                if (!isset($response['id']) && $response !== false) {
80
                    $this->showError($response);
81
                }
82
            } catch (\Exception $e) {
83
                $this->io->error($e->getMessage());
84
            }
85
86
            $this->io->progressAdvance(1);
87
        }
88
89
        $this->io->progressFinish();
90
        $this->io->success('The carts has been synchronized successfully.');
91
    }
92
}
93