Issues (12)

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.

Command/ReportCommand.php (2 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
3
declare(strict_types=1);
4
5
namespace Loevgaard\DandomainConsignmentBundle\Command;
6
7
use Loevgaard\DandomainConsignmentBundle\ConsignmentService\ConsignmentServiceCollection;
8
use Loevgaard\DandomainConsignmentBundle\Exception\ConsignmentNotEnabledException;
9
use Loevgaard\DandomainConsignmentBundle\Exception\InvalidDateFormatException;
10
use Loevgaard\DandomainConsignmentBundle\Exception\NonExistentConsignmentServiceException;
11
use Loevgaard\DandomainConsignmentBundle\Exception\NonExistentManufacturerException;
12
use Loevgaard\DandomainFoundation\Repository\ManufacturerRepository;
13
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
14
use Symfony\Component\Console\Helper\Table;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Logger\ConsoleLogger;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use Symfony\Component\Console\Question\ConfirmationQuestion;
21
22
class ReportCommand extends ContainerAwareCommand
23
{
24
    /**
25
     * @var ManufacturerRepository
26
     */
27
    protected $manufacturerRepository;
28
29
    /**
30
     * @var ConsignmentServiceCollection
31
     */
32
    protected $consignmentServiceCollection;
33
34 3
    public function __construct(ManufacturerRepository $manufacturerRepository, ConsignmentServiceCollection $consignmentServiceCollection)
35
    {
36 3
        $this->manufacturerRepository = $manufacturerRepository;
37 3
        $this->consignmentServiceCollection = $consignmentServiceCollection;
38
39 3
        parent::__construct();
40 3
    }
41
42 3
    protected function configure()
43
    {
44
        $this
45 3
            ->setName('loevgaard:dandomain-consignment:report')
46 3
            ->setDescription('Generates a report and optionally delivers it to the given manufacturer')
47 3
            ->addArgument('manufacturer', InputArgument::REQUIRED, 'The manufacturer to generate a report for. Use the id from Dandomain')
48 3
            ->addOption('start', null, InputOption::VALUE_REQUIRED, 'The start date in the format `YYYY-MM-DD`')
49 3
            ->addOption('end', null, InputOption::VALUE_REQUIRED, 'The end date in the format `YYYY-MM-DD`')
50 3
            ->addOption('do-not-deliver', null, InputOption::VALUE_NONE, 'If set the command will NOT deliver the report')
51 3
            ->addOption('do-not-update-last-stock-movement', null, InputOption::VALUE_NONE, 'If set, the command will NOT update the last stock movement property for the manufacturer')
52 3
            ->addOption('do-not-use-last-stock-movement', null, InputOption::VALUE_NONE, 'If set, the command will NOT use the last stock movement as the starting point when generating the report')
53
        ;
54 3
    }
55
56
    /**
57
     * @param InputInterface  $input
58
     * @param OutputInterface $output
59
     *
60
     * @return int|null|void
61
     *
62
     * @throws ConsignmentNotEnabledException
63
     * @throws InvalidDateFormatException
64
     * @throws NonExistentConsignmentServiceException
65
     * @throws NonExistentManufacturerException
66
     */
67 3
    protected function execute(InputInterface $input, OutputInterface $output)
68
    {
69
        // fetch arguments and options
70 3
        $manufacturer = $input->getArgument('manufacturer');
71 3
        $start = $input->getOption('start');
72 3
        $end = $input->getOption('end');
73 3
        $doNotDeliver = boolval($input->getOption('do-not-deliver'));
74 3
        $doNotUpdateLastStockMovement = boolval($input->getOption('do-not-update-last-stock-movement'));
75 3
        $doNotUseLastStockMovement = boolval($input->getOption('do-not-use-last-stock-movement'));
76
77
        // validate dates
78 3 View Code Duplication
        if ($start) {
0 ignored issues
show
This code seems to be duplicated across 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...
79 1
            $start = \DateTime::createFromFormat('Y-m-d', $start);
80 1
            if (false === $start) {
81 1
                throw new InvalidDateFormatException('The format for start is invalid');
82
            }
83
        }
84
85 2 View Code Duplication
        if ($end) {
0 ignored issues
show
This code seems to be duplicated across 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...
86 1
            $end = \DateTime::createFromFormat('Y-m-d', $end);
87 1
            if (false === $end) {
88 1
                throw new InvalidDateFormatException('The format for end is invalid');
89
            }
90
        }
91
92
        // find manufacturer
93 1
        $manufacturer = $this->manufacturerRepository->findOneByExternalId($manufacturer);
94
95 1
        if (!$manufacturer) {
96 1
            throw new NonExistentManufacturerException('The manufacturer does not exist');
97
        }
98
99
        // check if the manufacturer is enabled for consignment
100
        if (!$manufacturer->isConsignment()) {
101
            throw new ConsignmentNotEnabledException('Consignment is not enabled for the manufacturer');
102
        }
103
104
        if ($input->isInteractive()) {
105
            // output config
106
            $table = new Table($output);
107
            $table
108
                ->setHeaders(['Option', 'Value'])
109
                ->setRows([
110
                    ['Manufacturer', $manufacturer->getName()],
111
                    ['Start date', $start ? $start->format('Y-m-d') : 'None'],
112
                    ['End date', $end ? $end->format('Y-m-d') : 'None'],
113
                    ['Deliver?', $doNotDeliver ? 'No' : 'Yes'],
114
                    ['Update last stock movement?', $doNotUpdateLastStockMovement ? 'No' : 'Yes'],
115
                    ['Use last stock movement?', $doNotUseLastStockMovement ? 'No' : 'Yes'],
116
                ]);
117
            $table->render();
118
119
            // confirm config
120
            $helper = $this->getHelper('question');
121
            $question = new ConfirmationQuestion('Continue with this config? ', false);
122
123
            if (!$helper->ask($input, $output, $question)) {
124
                return;
125
            }
126
        }
127
128
        // find the consignment service
129
        $consignmentService = $this->consignmentServiceCollection->findConsignmentService($manufacturer);
130
        $consignmentService->setLogger(new ConsoleLogger($output));
131
132
        $options = [
133
            'update_last_stock_movement' => !$doNotUpdateLastStockMovement,
134
            'use_last_stock_movement' => !$doNotUseLastStockMovement,
135
        ];
136
137
        if ($start) {
138
            $options['start_date'] = $start;
139
        }
140
141
        if ($end) {
142
            $options['end_date'] = $end;
143
        }
144
145
        // generate the report
146
        $report = $consignmentService->generateReport($options);
147
148
        // generate report file because we want to generate the file no matter if the $deliver option is set
149
        $consignmentService->generateReportFile($report);
150
151
        // deliver report
152
        if (!$doNotDeliver) {
153
            $consignmentService->deliverReport($report);
154
        }
155
    }
156
}
157