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.
Completed
Push — master ( cfabb3...bd8b96 )
by Andreas
03:39
created

ExportCustomerCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 52
c 1
b 0
f 0
dl 0
loc 134
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A callbackExportCustomer() 0 12 1
A execute() 0 40 5
A __construct() 0 13 1
A configure() 0 10 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Console\Command;
7
8
use CommerceLeague\ActiveCampaign\Service\ExportCustomerService;
9
use Magento\Customer\Model\Customer;
10
use Magento\Customer\Model\MagentoCustomerFactory;
0 ignored issues
show
Bug introduced by
The type Magento\Customer\Model\MagentoCustomerFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as MagentoCustomerCollectionFactory;
0 ignored issues
show
Bug introduced by
The type Magento\Customer\Model\R...tomer\CollectionFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Magento\Customer\Model\ResourceModel\Customer\Collection as MagentoCustomerCollection;
13
use Magento\Framework\Console\Cli;
14
use Magento\Framework\Model\ResourceModel\Iterator as ResourceIterator;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Helper\ProgressBarFactory;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Consol...lper\ProgressBarFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Symfony\Component\Console\Helper\ProgressBar;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
/**
24
 * Class ExportContactCommand
25
 */
26
class ExportCustomerCommand extends Command
27
{
28
    private const NAME = 'activecampaign:export:customer';
29
    private const ARGUMENT_NAME_MAGENTO_CUSTOMER_ID = 'magento-customer-id';
30
    private const OPTION_NAME_ALL = 'all';
31
32
    /**
33
     * @var MagentoCustomerCollectionFactory
34
     */
35
    private $magentoCustomerCollectionFactory;
36
37
    /**
38
     * @var MagentoCustomerFactory
39
     */
40
    private $magentoCustomerFactory;
41
42
    /**
43
     * @var ProgressBarFactory
44
     */
45
    private $progressBarFactory;
46
47
    /**
48
     * @var ResourceIterator
49
     */
50
    private $resourceIterator;
51
52
    /**
53
     * @var ExportCustomerService
54
     */
55
    private $exportCustomerService;
56
57
    /**
58
     * @var int
59
     */
60
    private $exportMessages = 0;
61
62
    /**
63
     * @param MagentoCustomerCollectionFactory $magentoCustomerCollectionFactory
64
     * @param MagentoCustomerFactory $magentoCustomerFactory
65
     * @param ProgressBarFactory $progressBarFactory
66
     * @param ResourceIterator $resourceIterator
67
     * @param ExportCustomerService $exportCustomerService
68
     */
69
    public function __construct(
70
        MagentoCustomerCollectionFactory $magentoCustomerCollectionFactory,
71
        MagentoCustomerFactory $magentoCustomerFactory,
72
        ProgressBarFactory $progressBarFactory,
73
        ResourceIterator $resourceIterator,
74
        ExportCustomerService $exportCustomerService
75
    ) {
76
        $this->magentoCustomerCollectionFactory = $magentoCustomerCollectionFactory;
77
        $this->magentoCustomerFactory = $magentoCustomerFactory;
78
        $this->progressBarFactory = $progressBarFactory;
79
        $this->resourceIterator = $resourceIterator;
80
        $this->exportCustomerService = $exportCustomerService;
81
        parent::__construct();
82
    }
83
84
    /**
85
     * @inheritDoc
86
     */
87
    protected function configure()
88
    {
89
        $this->setName(self::NAME)
90
            ->addArgument(
91
                self::ARGUMENT_NAME_MAGENTO_CUSTOMER_ID,
92
                InputArgument::OPTIONAL
93
            )->addOption(
94
                self::OPTION_NAME_ALL,
95
                null,
96
                InputOption::VALUE_NONE
97
            );
98
    }
99
100
    /**
101
     * @inheritDoc
102
     */
103
    protected function execute(InputInterface $input, OutputInterface $output)
104
    {
105
        $magentoCustomerId = $input->getArgument(self::ARGUMENT_NAME_MAGENTO_CUSTOMER_ID);
106
        $allMagentoCustomers = $input->getOption(self::OPTION_NAME_ALL);
107
108
        if (!$magentoCustomerId && !$allMagentoCustomers) {
109
            $output->writeln('Either specify the magentoCustomerId or set the --all flag');
110
            return Cli::RETURN_FAILURE;
111
        }
112
113
        /** @var MagentoCustomerCollection $magentoCustomerCollection */
114
        $magentoCustomerCollection = $this->magentoCustomerCollectionFactory->create();
115
116
        if ($magentoCustomerId) {
117
            $magentoCustomerCollection->addFieldToFilter('entity_id', $magentoCustomerId);
118
        }
119
120
        if ($magentoCustomerCollection->getSize() === 0) {
121
            $output->writeln('<error>No valid magento customers found</error>');
122
            return Cli::RETURN_FAILURE;
123
        }
124
125
        /** @var ProgressBar $progressBar */
126
        $progressBar = $this->progressBarFactory->create(['output' => $output]);
127
        $progressBar->setFormat('<comment>%message%</comment> %current% [%bar%] %elapsed%');
128
        $progressBar->setMessage('Export Message(s)');
129
130
        $this->resourceIterator->walk(
131
            $magentoCustomerCollection->getSelect(),
132
            [[$this, 'callbackExportCustomer']],
133
            [
134
                'magentoCustomer' => $this->magentoCustomerFactory->create(),
135
                'progressBar' => $progressBar
136
            ]
137
        );
138
139
        $output->writeln('');
140
        $output->writeln('<info>Created ' . $this->exportMessages . ' export message(s)</info>');
141
142
        return Cli::RETURN_SUCCESS;
143
    }
144
145
    /**
146
     * @param array $args
147
     */
148
    public function callbackExportCustomer(array $args): void
149
    {
150
        /** @var Customer $magentoCustomer */
151
        $magentoCustomer = clone $args['magentoCustomer'];
152
        $magentoCustomer->setData($args['row']);
153
154
        /** @var ProgressBar $progressBar */
155
        $progressBar = $args['progressBar'];
156
        $progressBar->advance();
157
158
        $this->exportCustomerService->export($magentoCustomer);
159
        $this->exportMessages++;
160
    }
161
}
162