Issues (18)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Console/Command/StartCliReportingService.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * File: StartCliReportingService.php
6
 *
7
 * @author      Maciej Sławik <[email protected]>
8
 * Github:      https://github.com/maciejslawik
9
 */
10
11
namespace MSlwk\ReactPhpPlayground\Console\Command;
12
13
use MSlwk\ReactPhpPlayground\Api\ChunkSizeCalculatorInterface;
14
use MSlwk\ReactPhpPlayground\Api\CustomerIdsProviderInterface;
15
use MSlwk\ReactPhpPlayground\Api\TimerInterface;
16
use MSlwk\ReactPhpPlayground\Model\Adapter\ReactPHP\ProcessFactory;
17
use Symfony\Component\Console\Command\Command;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
use Magento\Framework\Serialize\Serializer\Json;
22
use React\EventLoop\Factory;
23
24
/**
25
 * Class StartCliReportingService
26
 * @package MSlwk\ReactPhpPlayground\Console\Command
27
 */
28
class StartCliReportingService extends Command
29
{
30
    const COMMAND_NAME = 'mslwk:cli-reporting-start';
31
    const COMMAND_DESCRIPTION = 'Start asynchronous CLI reporting service';
32
    const ARGUMENT_NUMBER_OF_THREADS = 'threads';
33
34
    /**
35
     * @var TimerInterface
36
     */
37
    private $timer;
38
39
    /**
40
     * @var CustomerIdsProviderInterface
41
     */
42
    private $customerIdsProvider;
43
44
    /**
45
     * @var LoopInterface
46
     */
47
    private $loop;
48
49
    /**
50
     * @var ProcessFactory
51
     */
52
    private $processFactory;
53
54
    /**
55
     * @var Json
56
     */
57
    private $jsonHandler;
58
59
    /**
60
     * @var ChunkSizeCalculatorInterface
61
     */
62
    private $chunkSizeCalculator;
63
64
    /**
65
     * StartCliReportingService constructor.
66
     * @param TimerInterface $timer
67
     * @param CustomerIdsProviderInterface $customerIdsProvider
68
     * @param Factory $loopFactory
69
     * @param ProcessFactory $processFactory
70
     * @param Json $jsonHandler
71
     * @param ChunkSizeCalculatorInterface $chunkSizeCalculator
72
     * @param null $name
73
     */
74 View Code Duplication
    public function __construct(
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
        TimerInterface $timer,
76
        CustomerIdsProviderInterface $customerIdsProvider,
77
        Factory $loopFactory,
78
        ProcessFactory $processFactory,
79
        Json $jsonHandler,
80
        ChunkSizeCalculatorInterface $chunkSizeCalculator,
81
        $name = null
82
    ) {
83
        parent::__construct($name);
84
        $this->timer = $timer;
85
        $this->customerIdsProvider = $customerIdsProvider;
86
        $this->loop = $loopFactory::create();
0 ignored issues
show
Documentation Bug introduced by
It seems like $loopFactory::create() of type object<React\EventLoop\LoopInterface> is incompatible with the declared type object<MSlwk\ReactPhpPla...\Command\LoopInterface> of property $loop.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
87
        $this->processFactory = $processFactory;
88
        $this->jsonHandler = $jsonHandler;
89
        $this->chunkSizeCalculator = $chunkSizeCalculator;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    protected function configure()
96
    {
97
        $this->setName(self::COMMAND_NAME)
98
            ->setDescription(self::COMMAND_DESCRIPTION)
99
            ->addArgument(
100
                self::ARGUMENT_NUMBER_OF_THREADS,
101
                InputArgument::REQUIRED,
102
                'Number of threads for running the export process'
103
            );
104
    }
105
106
    /**
107
     * @param InputInterface $input
108
     * @param OutputInterface $output
109
     * @return void
110
     */
111 View Code Duplication
    protected function execute(InputInterface $input, OutputInterface $output)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
    {
113
        $numberOfThreads = (int)$input->getArgument(self::ARGUMENT_NUMBER_OF_THREADS);
114
        $customerIds = $this->customerIdsProvider->getCustomerIds();
115
116
        $this->timer->startTimer();
117
118
        $this->startProcesses($customerIds, $numberOfThreads);
119
120
        $this->timer->stopTimer();
121
122
        $output->writeln("<info>Process finished after {$this->timer->getExecutionTimeInSeconds()} seconds</info>");
123
    }
124
125
    /**
126
     * @param int[] $customerIds
127
     * @param int $numberOfThreads
128
     */
129 View Code Duplication
    protected function startProcesses(array $customerIds, int $numberOfThreads): void
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
130
    {
131
        $chunkSize = $this->chunkSizeCalculator->calculateChunkSize($customerIds, $numberOfThreads);
132
        $threadedCustomerIds = array_chunk($customerIds, $chunkSize);
133
        foreach ($threadedCustomerIds as $customerIdsForSingleThread) {
134
            $this->createProcessDefinition($this->getFullCommand($customerIdsForSingleThread));
135
        }
136
        $this->loop->run();
137
    }
138
139
    /**
140
     * @param string $command
141
     */
142
    protected function createProcessDefinition(string $command): void
143
    {
144
        $reactProcess = $this->processFactory->create($command);
145
        $reactProcess->start($this->loop);
146
147
        $reactProcess->stdout->on('data', function ($chunk) {
148
            echo $chunk;
149
        });
150
    }
151
152
    /**
153
     * @param int[] $customerIds
154
     * @return string
155
     */
156
    protected function getFullCommand(array $customerIds): string
157
    {
158
        return sprintf(
159
            ' %s/bin/magento %s %s',
160
            BP,
161
            GenerateReports::COMMAND_NAME,
162
            $this->jsonHandler->serialize($customerIds)
163
        );
164
    }
165
}
166