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 ( c8c4e6...db9143 )
by Andreas
03:30
created

ExportContactCommand::getSubscriberEmails()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaign\Console\Command;
7
8
use CommerceLeague\ActiveCampaign\MessageQueue\Topics;
9
use Magento\Customer\Model\ResourceModel\Customer\Collection as MagentoCustomerCollection;
10
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...
11
use Magento\Framework\Console\Cli;
12
use Magento\Framework\MessageQueue\PublisherInterface;
13
use Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory as SubscriberCollectionFactory;
0 ignored issues
show
Bug introduced by
The type Magento\Newsletter\Model...riber\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...
14
use Magento\Newsletter\Model\ResourceModel\Subscriber\Collection as SubscriberCollection;
15
use Magento\Newsletter\Model\Subscriber;
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\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * Class ExportContactCommand
22
 */
23
class ExportContactCommand extends AbstractExportCommand
24
{
25
    private const NAME = 'activecampaign:export:contact';
26
27
    /**
28
     * @var MagentoCustomerCollectionFactory
29
     */
30
    private $magentoCustomerCollectionFactory;
31
32
    /**
33
     * @var SubscriberCollectionFactory
34
     */
35
    private $subscriberCollectionFactory;
36
37
    /**
38
     * @param MagentoCustomerCollectionFactory $magentoCustomerCollectionFactory
39
     * @param SubscriberCollectionFactory $subscriberCollectionFactory
40
     * @param PublisherInterface $publisher
41
     * @param ProgressBarFactory $progressBarFactory
42
     */
43
    public function __construct(
44
        MagentoCustomerCollectionFactory $magentoCustomerCollectionFactory,
45
        SubscriberCollectionFactory $subscriberCollectionFactory,
46
        PublisherInterface $publisher,
47
        ProgressBarFactory $progressBarFactory
48
    ) {
49
        $this->magentoCustomerCollectionFactory = $magentoCustomerCollectionFactory;
50
        $this->subscriberCollectionFactory = $subscriberCollectionFactory;
51
        parent::__construct($progressBarFactory, $publisher);
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57
    protected function configure()
58
    {
59
        $this->setName(self::NAME);
60
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65
    protected function execute(InputInterface $input, OutputInterface $output)
66
    {
67
        $magentoCustomerIds = $this->getMagentoCustomerIds();
68
69
        $progressBar = $this->createProgressBar(
70
            $output,
71
            count($magentoCustomerIds),
72
            'Export Magento Customer(s)'
73
        );
74
75
        foreach ($magentoCustomerIds as $magentoCustomerId) {
76
            $this->publisher->publish(
77
                Topics::CUSTOMER_CONTACT_EXPORT,
78
                json_encode(['magento_customer_id' => $magentoCustomerId])
0 ignored issues
show
Bug introduced by
json_encode(array('magen...=> $magentoCustomerId)) of type string is incompatible with the type array|object expected by parameter $data of Magento\Framework\Messag...herInterface::publish(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

78
                /** @scrutinizer ignore-type */ json_encode(['magento_customer_id' => $magentoCustomerId])
Loading history...
79
            );
80
81
            $progressBar->advance();
82
        }
83
84
        $output->writeln('');
85
86
        $subscriberEmails = $this->getSubscriberEmails();
87
88
        $progressBar = $this->createProgressBar(
89
            $output,
90
            count($subscriberEmails),
91
            'Export Newsletter Subscriber(s)'
92
        );
93
94
        foreach ($subscriberEmails as $subscriberEmail) {
95
            $this->publisher->publish(
96
                Topics::NEWSLETTER_CONTACT_EXPORT,
97
                json_encode(['email' => $subscriberEmail])
98
            );
99
100
            $progressBar->advance();
101
        }
102
103
        $output->writeln('');
104
        $output->writeln(sprintf(
105
            '<info>Exported %s contact(s)</info>',
106
            (count($magentoCustomerIds) + count($subscriberEmails)))
107
        );
108
109
        return Cli::RETURN_SUCCESS;
110
    }
111
112
    /**
113
     * @return array
114
     */
115
    private function getMagentoCustomerIds(): array
116
    {
117
        /** @var MagentoCustomerCollection $magentoCustomerCollection */
118
        $magentoCustomerCollection = $this->magentoCustomerCollectionFactory->create();
119
        return $magentoCustomerCollection->getAllIds();
120
    }
121
122
    /**
123
     * @return array
124
     */
125
    private function getSubscriberEmails(): array
126
    {
127
        /** @var SubscriberCollection $subscriberCollection */
128
        $subscriberCollection = $this->subscriberCollectionFactory->create();
129
        $subscriberCollection->addFieldToFilter('customer_id', 0);
130
131
        $subscriberEmails = [];
132
133
        /** @var Subscriber $subscriber */
134
        foreach ($subscriberCollection as $subscriber) {
135
            $subscriberEmails[] = $subscriber->getEmail();
136
        }
137
138
        return $subscriberEmails;
139
    }
140
}
141