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 ( bd8b96...8bf920 )
by Andreas
03:51
created

ExportCustomerCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 36
c 1
b 0
f 0
dl 0
loc 112
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A callbackExportMagentoCustomer() 0 12 1
A execute() 0 28 2
A __construct() 0 13 1
A configure() 0 3 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\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * Class ExportContactCommand
23
 */
24
class ExportCustomerCommand extends Command
25
{
26
    private const NAME = 'activecampaign:export:customer';
27
28
    /**
29
     * @var MagentoCustomerCollectionFactory
30
     */
31
    private $magentoCustomerCollectionFactory;
32
33
    /**
34
     * @var MagentoCustomerFactory
35
     */
36
    private $magentoCustomerFactory;
37
38
    /**
39
     * @var ProgressBarFactory
40
     */
41
    private $progressBarFactory;
42
43
    /**
44
     * @var ResourceIterator
45
     */
46
    private $resourceIterator;
47
48
    /**
49
     * @var ExportCustomerService
50
     */
51
    private $exportCustomerService;
52
53
    /**
54
     * @var int
55
     */
56
    private $exportMessages = 0;
57
58
    /**
59
     * @param MagentoCustomerCollectionFactory $magentoCustomerCollectionFactory
60
     * @param MagentoCustomerFactory $magentoCustomerFactory
61
     * @param ProgressBarFactory $progressBarFactory
62
     * @param ResourceIterator $resourceIterator
63
     * @param ExportCustomerService $exportContactService
64
     */
65
    public function __construct(
66
        MagentoCustomerCollectionFactory $magentoCustomerCollectionFactory,
67
        MagentoCustomerFactory $magentoCustomerFactory,
68
        ProgressBarFactory $progressBarFactory,
69
        ResourceIterator $resourceIterator,
70
        ExportCustomerService $exportContactService
71
    ) {
72
        $this->magentoCustomerCollectionFactory = $magentoCustomerCollectionFactory;
73
        $this->magentoCustomerFactory = $magentoCustomerFactory;
74
        $this->progressBarFactory = $progressBarFactory;
75
        $this->resourceIterator = $resourceIterator;
76
        $this->exportCustomerService = $exportContactService;
77
        parent::__construct();
78
    }
79
80
    /**
81
     * @inheritDoc
82
     */
83
    protected function configure()
84
    {
85
        $this->setName(self::NAME);
86
    }
87
88
    /**
89
     * @inheritDoc
90
     */
91
    protected function execute(InputInterface $input, OutputInterface $output)
92
    {
93
        /** @var MagentoCustomerCollection $magentoCustomerCollection */
94
        $magentoCustomerCollection = $this->magentoCustomerCollectionFactory->create();
95
96
        if ($magentoCustomerCollection->getSize() === 0) {
97
            $output->writeln('<error>No valid magento customers found</error>');
98
            return Cli::RETURN_FAILURE;
99
        }
100
101
        /** @var ProgressBar $progressBar */
102
        $progressBar = $this->progressBarFactory->create(['output' => $output]);
103
        $progressBar->setFormat('<comment>%message%</comment> %current% [%bar%] %elapsed%');
104
        $progressBar->setMessage('Export Message(s)');
105
106
        $this->resourceIterator->walk(
107
            $magentoCustomerCollection->getSelect(),
108
            [[$this, 'callbackExportMagentoCustomer']],
109
            [
110
                'magentoCustomer' => $this->magentoCustomerFactory->create(),
111
                'progressBar' => $progressBar
112
            ]
113
        );
114
115
        $output->writeln('');
116
        $output->writeln('<info>Created ' . $this->exportMessages . ' export message(s)</info>');
117
118
        return Cli::RETURN_SUCCESS;
119
    }
120
121
    /**
122
     * @param array $args
123
     */
124
    public function callbackExportMagentoCustomer(array $args): void
125
    {
126
        /** @var Customer $magentoCustomer */
127
        $magentoCustomer = clone $args['magentoCustomer'];
128
        $magentoCustomer->setData($args['row']);
129
130
        /** @var ProgressBar $progressBar */
131
        $progressBar = $args['progressBar'];
132
        $progressBar->advance();
133
134
        $this->exportCustomerService->export($magentoCustomer);
135
        $this->exportMessages++;
136
    }
137
}
138