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.

SyncCartsCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 8
rs 10
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\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Style\SymfonyStyle;
14
15
final class SyncCartsCommand extends BaseSyncCommand
16
{
17
    /** @var EntityRepository */
18
    private $orderRepository;
19
20
    /** @var CartRegisterHandlerInterface */
21
    private $cartRegisterHandler;
22
23
    public function __construct(
24
        EntityRepository $orderRepository,
25
        CartRegisterHandlerInterface $cartRegisterHandler
26
    ) {
27
        parent::__construct();
28
29
        $this->orderRepository = $orderRepository;
30
        $this->cartRegisterHandler = $cartRegisterHandler;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function configure(): void
37
    {
38
        $this
39
            ->setName('odiseo:mailchimp:sync-carts')
40
            ->setDescription('Synchronize the carts to Mailchimp.')
41
            ->addOption('create-only', 'c', InputOption::VALUE_NONE, 'With this option the existing carts will be not updated.')
42
        ;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function execute(InputInterface $input, OutputInterface $output): int
49
    {
50
        $this->io = new SymfonyStyle($input, $output);
51
52
        $this->io->title('Synchronizing the carts to Mailchimp');
53
54
        $this->registerCarts($input);
55
56
        return 0;
57
    }
58
59
    /**
60
     * @param InputInterface $input
61
     */
62
    protected function registerCarts(InputInterface $input): void
63
    {
64
        $createOnly = $input->getOption('create-only');
65
66
        $orders = $this->orderRepository->createQueryBuilder('o')
67
            ->where('o.customer IS NOT NULL')
68
            ->getQuery()
69
            ->getResult()
70
        ;
71
72
        $this->io->text('Connecting ' . count($orders) . ' carts.');
0 ignored issues
show
Bug introduced by
It seems like $orders can also be of type integer; however, parameter $value of count() does only seem to accept Countable|array, 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

72
        $this->io->text('Connecting ' . count(/** @scrutinizer ignore-type */ $orders) . ' carts.');
Loading history...
73
        $this->io->progressStart(count($orders));
74
75
        /** @var OrderInterface $order */
76
        foreach ($orders as $order) {
77
            try {
78
                $response = $this->cartRegisterHandler->register($order, $createOnly);
79
80
                if (!isset($response['id']) && $response !== false) {
81
                    $this->showError($response);
82
                }
83
            } catch (\Exception $e) {
84
                $this->io->error($e->getMessage());
85
            }
86
87
            $this->io->progressAdvance(1);
88
        }
89
90
        $this->io->progressFinish();
91
        $this->io->success('The carts has been synchronized successfully.');
92
    }
93
}
94