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

ExportOrderCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 15
nc 2
nop 2
dl 0
loc 26
rs 9.7666
c 1
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\Framework\Console\Cli;
10
use Magento\Framework\MessageQueue\PublisherInterface;
11
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...
12
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory as MagentoOrderCollectionFactory;
13
use Magento\Sales\Model\ResourceModel\Order\Collection as MagentoOrderCollection;
14
use Magento\Sales\Model\Order as MagentoOrder;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
19
/**
20
 * Class ExportOrderCommand
21
 */
22
class ExportOrderCommand extends AbstractExportCommand
23
{
24
    private const NAME = 'activecampaign:export:order';
25
26
    /**
27
     * @var MagentoOrderCollectionFactory
28
     */
29
    private $magentoOrderCollectionFactory;
30
31
    /**
32
     * @param MagentoOrderCollectionFactory $magentoOrderCollectionFactory
33
     * @param PublisherInterface $publisher
34
     * @param ProgressBarFactory $progressBarFactory
35
     */
36
    public function __construct(
37
        MagentoOrderCollectionFactory $magentoOrderCollectionFactory,
38
        PublisherInterface $publisher,
39
        ProgressBarFactory $progressBarFactory
40
    ) {
41
        $this->magentoOrderCollectionFactory = $magentoOrderCollectionFactory;
42
        parent::__construct($progressBarFactory, $publisher);
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    protected function configure()
49
    {
50
        $this->setName(self::NAME);
51
    }
52
53
    /**
54
     * @inheritDoc
55
     */
56
    protected function execute(InputInterface $input, OutputInterface $output)
57
    {
58
        $magentoOrderIds = $this->getMagentoOrderIds();
59
60
        $progressBar = $this->createProgressBar(
61
            $output,
62
            count($magentoOrderIds),
63
            'Export Magento Order(s)'
64
        );
65
66
        foreach ($magentoOrderIds as $magentoOrderId) {
67
            $this->publisher->publish(
68
                Topics::SALES_ORDER_EXPORT,
69
                json_encode(['magento_order_id' => $magentoOrderId])
0 ignored issues
show
Bug introduced by
json_encode(array('magen...d' => $magentoOrderId)) 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

69
                /** @scrutinizer ignore-type */ json_encode(['magento_order_id' => $magentoOrderId])
Loading history...
70
            );
71
72
            $progressBar->advance();
73
        }
74
75
        $output->writeln('');
76
        $output->writeln(sprintf(
77
                '<info>Exported %s order(s)</info>',
78
                (count($magentoOrderIds)))
79
        );
80
81
        return Cli::RETURN_SUCCESS;
82
    }
83
84
    /**
85
     * @return array
86
     */
87
    private function getMagentoOrderIds(): array
88
    {
89
        /** @var MagentoOrderCollection $magentoOrderCollection */
90
        $magentoOrderCollection = $this->magentoOrderCollectionFactory->create();
91
        $magentoOrderCollection->addFieldToFilter(MagentoOrder::STATUS, MagentoOrder::STATE_COMPLETE);
92
        $magentoOrderCollection->addFieldToFilter(MagentoOrder::CUSTOMER_IS_GUEST, false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type array|null|string expected by parameter $condition of Magento\Framework\Data\C...tDb::addFieldToFilter(). ( Ignorable by Annotation )

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

92
        $magentoOrderCollection->addFieldToFilter(MagentoOrder::CUSTOMER_IS_GUEST, /** @scrutinizer ignore-type */ false);
Loading history...
93
94
        return $magentoOrderCollection->getAllIds();
95
    }
96
97
98
99
}
100