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

SyncStoresCommand::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\StoreRegisterHandlerInterface;
8
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
9
use Sylius\Component\Core\Model\ChannelInterface;
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
class SyncStoresCommand extends BaseSyncCommand
16
{
17
    /**
18
     * @var ChannelRepositoryInterface
19
     */
20
    protected $channelRepository;
21
22
    /**
23
     * @var StoreRegisterHandlerInterface
24
     */
25
    protected $storeRegisterHandler;
26
27
    /**
28
     * @param ChannelRepositoryInterface $channelRepository
29
     * @param StoreRegisterHandlerInterface $storeRegisterHandler
30
     */
31
    public function __construct(
32
        ChannelRepositoryInterface $channelRepository,
33
        StoreRegisterHandlerInterface $storeRegisterHandler
34
    ) {
35
        parent::__construct();
36
37
        $this->channelRepository = $channelRepository;
38
        $this->storeRegisterHandler = $storeRegisterHandler;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function configure()
45
    {
46
        $this
47
            ->setName('odiseo:mailchimp:sync-stores')
48
            ->setDescription('Synchronize the Sylius stores (channels) to Mailchimp.')
49
            ->addOption('purge', 'p', InputOption::VALUE_NONE, 'Remove all stores before create the new ones.')
50
            ->addOption('isSyncing', 's', InputOption::VALUE_NONE, 'Mark the stores with "is_syncing" field like true.')
51
        ;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    protected function execute(InputInterface $input, OutputInterface $output)
58
    {
59
        $this->io = new SymfonyStyle($input, $output);
60
61
        $this->io->title('Synchronizing the stores to Mailchimp');
62
63
        $this->registerStores($input);
64
    }
65
66
    /**
67
     * @param InputInterface $input
68
     */
69
    protected function registerStores(InputInterface $input)
70
    {
71
        $withPurge = $input->getOption('purge');
72
        $isSyncing = $input->getOption('isSyncing');
73
74
        $channels = $this->channelRepository->findBy([
75
            'enabled' => true,
76
        ]);
77
78
        /** @var ChannelInterface $channel */
79
        foreach ($channels as $channel) {
80
            if ($withPurge) {
81
                $this->io->write('Removing the "' . $channel->getName() . '" store...');
82
83
                try {
84
                    $this->storeRegisterHandler->unregister($channel);
85
                    $this->io->writeln('Done.');
86
                } catch (\Exception $e) {
87
                    $this->io->writeln('Error.');
88
                    $this->io->error($e->getMessage());
89
                }
90
            }
91
92
            $this->io->write('Connecting the "' . $channel->getName() . '" store with is_syncing = '.($isSyncing?'true':'false').'...');
93
94
            try {
95
                $response = $this->storeRegisterHandler->register($channel, $isSyncing);
96
97
                if (isset($response['id'])) {
98
                    $this->io->writeln('Done.');
99
                } else {
100
                    $this->io->writeln('Error.');
101
                    if ($response !== false) {
102
                        $this->showError($response);
103
                    }
104
                }
105
            } catch (\Exception $e) {
106
                $this->io->writeln('Error.');
107
                $this->io->error($e->getMessage());
108
            }
109
        }
110
111
        $this->io->success('The stores has been synchronized successfully.');
112
    }
113
}
114