Issues (188)

Security Analysis    not enabled

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/CreateOrderCommandHandler.php (1 issue)

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
require_once __DIR__ . '/CommandHandlerInterface.php';
4
require_once __DIR__ . '/CommandInterface.php';
5
require_once __DIR__ . '/CreateOrderCommand.php';
6
require_once __DIR__ . '/../../societe/class/societe.class.php';
7
require_once __DIR__ . '/../../commande/class/commande.class.php';
8
require_once __DIR__ . '/../../product/class/product.class.php';
9
10
/**
11
 * CreateOrderCommandHandler class
12
 *
13
 * @author Laurent De Coninck <[email protected]>
14
 */
15
class CreateOrderCommandHandler implements CommandHandlerInterface
16
{
17
    /**
18
     * @var DoliDB
19
     */
20
    private $db;
21
22
    /**
23
     * @var stdClass
24
     */
25
    private $conf;
26
27
    /**
28
     * @var User
29
     */
30
    private $user;
31
32
    /**
33
     * @var Translate
34
     */
35
    private $langs;
36
37
    /**
38
     * @var ModeleThirdPartyCode
39
     */
40
    private $codeFournisseurGenerator;
41
42
    /**
43
     * @var ModeleThirdPartyCode
44
     */
45
    private $codeClientGenerator;
46
47
    /**
48
     * @var Societe
49
     */
50
    private $societe;
51
52
    /**
53
     * @var Commande
54
     */
55
    private $order;
56
57
    /**
58
     * @param DoliDB               $db
59
     * @param stdClass             $conf
60
     * @param User                 $user
61
     * @param Translate            $langs
62
     * @param ModeleThirdPartyCode $codeClientGenerator
63
     * @param ModeleThirdPartyCode $codeFounrisseurGenerator
64
     */
65
    public function __construct(
66
        $db,
67
        $conf,
68
        $user,
69
        $langs,
70
        ModeleThirdPartyCode $codeClientGenerator,
71
        ModeleThirdPartyCode $codeFounrisseurGenerator
72
    ) {
73
        $this->db = $db;
74
        $this->conf = $conf->global;
75
        $this->user = $user;
76
        $this->langs = $langs;
77
        $this->codeClientGenerator = $codeClientGenerator;
78
        $this->codeFournisseurGenerator = $codeFounrisseurGenerator;
79
    }
80
81
    /**
82
     * @param CreateOrderCommand|CommandInterface $command
83
     *
84
     * @throws Exception
85
     */
86
    public function handle(CommandInterface $command)
87
    {
88
        $customerId = $this->createCustomer($command)->id;
89
90
        $this->createOrder($command, $customerId)
91
            ->addLine($command)
92
            ->addContacts()
93
            ->validateOrder();
94
95
        $this->order->generateDocument('einstein', $this->langs);
96
    }
97
98
    /**
99
     * @return Product
100
     */
101 View Code Duplication
    private function getProduct()
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...
102
    {
103
        $flightProduct = new Product($this->db);
104
105
        if ($flightProduct->fetch($this->conf->BBC_FLIGHT_TYPE_CUSTOMER) <= 0) {
106
            throw new \InvalidArgumentException('Default product not configured');
107
        }
108
109
        return $flightProduct;
110
    }
111
112
    /**
113
     * @param Product   $flightProduct
114
     * @param float|int $pricePerPax
115
     *
116
     * @return float|int
117
     */
118
    private function computeDiscounts($flightProduct, $pricePerPax = 0)
119
    {
120
        return ($flightProduct->price_ttc - ($pricePerPax)) * 100 / $flightProduct->price_ttc;
121
    }
122
123
    /**
124
     * @param CommandInterface|CreateOrderCommand $command
125
     *
126
     * @return Societe
127
     * @throws Exception
128
     */
129
    private function createCustomer(CommandInterface $command)
130
    {
131
        $this->societe = new Societe($this->db);
132
        $name = $command->getName() . ' ' . $command->getFirstname();
133
134
        $existingCustomers = $this->societe->searchByName($name);
135
        if(count($existingCustomers) > 0){
136
            $this->societe = $existingCustomers[0];
137
            return $this->societe;
138
        }
139
140
        $this->societe->particulier = 1;
141
        $this->societe->name = $name;
142
        $this->societe->civility_id = $command->getCivilityId();
143
        $this->societe->name_bis = $command->getName();
144
        $this->societe->firstname = $command->getFirstname();
145
        $this->societe->entity = $this->conf->entity;
146
        $this->societe->name_alias = '';
147
        $this->societe->address = GETPOST('address');
148
        $this->societe->zip = $command->getZip();
149
        $this->societe->town = $command->getTown();
150
        $this->societe->country_id = 2;
151
        $this->societe->state_id = $command->getState();
152
        $this->societe->phone = $command->getPhone();
153
        $this->societe->email = $command->getEmail();
154
        $this->societe->code_client = $this->codeClientGenerator->getNextValue($this->societe, 0);
155
        $this->societe->code_fournisseur = $this->codeFournisseurGenerator->getNextValue($this->societe, 1);
156
        $this->societe->tva_intra = $command->getTva();
157
        $this->societe->tva_assuj = empty($command->getTva()) ? 0 : 1;
158
        $this->societe->status = 1;
159
        $this->societe->client = 3; //prospect + customer
160
        $this->societe->fournisseur = 0;
161
        $this->societe->commercial_id = $this->user->id;
162
        $this->societe->default_lang = $command->getLanguage();
163
164
        $customerId = $this->societe->create($this->user);
165
        if ($customerId < 0) {
166
            throw new Exception($this->societe->errorsToString(), $customerId);
167
        }
168
169
        return $this->societe;
170
    }
171
172
    /**
173
     * @param CommandInterface|CreateOrderCommand $command
174
     *
175
     * @return CreateOrderCommandHandler
176
     */
177
    private function addLine(CommandInterface $command)
178
    {
179
        $product = $this->getProduct();
180
        $pu_ht = price2num($product->price, 'MU');
181
182
        $this->order->addline(
183
            '',
184
            $pu_ht,
185
            $command->getNbrPax(),
186
            $product->tva_tx,
187
            0,
188
            0,
189
            $product->id,
190
            $this->computeDiscounts($product, ($command->getCost() / $command->getNbrPax()))
191
        );
192
193
        return $this;
194
    }
195
196
    /**
197
     * @param CommandInterface|CreateOrderCommand $command
198
     * @param int                                 $customerId
199
     *
200
     * @return $this
201
     * @throws Exception
202
     */
203
    private function createOrder(CommandInterface $command, $customerId)
204
    {
205
        $this->order = new Commande($this->db);
206
        $this->order->note_public = $command->isCommentPublic() ? $command->getComment() : '';
207
        $this->order->note_private = $command->isCommentPublic() ? $command->getComment() : '';
208
        $this->order->socid = $customerId;
209
        $this->order->cond_reglement_id = 1; // reception
210
        $this->order->mode_reglement_id = 2; //virement
211
        $this->order->demand_reason_id = $command->getOrigine();
212
        $this->order->date = time();
213
214
        $orderId = $this->order->create($this->user);
215
        if ($orderId <= 0) {
216
            throw new Exception('Exception during the order creation');
217
        }
218
219
        return $this;
220
    }
221
222
    /**
223
     * Validate the order
224
     *
225
     * @throws Exception
226
     */
227
    private function validateOrder()
228
    {
229
        if ($this->order->valid($this->user) < 0) {
230
            throw new Exception('Validation of order failed');
231
        }
232
233
        return $this;
234
    }
235
236
    /**
237
     * Add sales contact
238
     */
239
    private function addContacts()
240
    {
241
        $this->order->add_contact($this->user->id, 91, 'internal');
242
        return $this;
243
    }
244
245
    /**
246
     * @return Societe
247
     */
248
    public function getCustomer()
249
    {
250
        return $this->societe;
251
    }
252
253
    /**
254
     * @return Commande
255
     */
256
    public function getOrder()
257
    {
258
        return $this->order;
259
    }
260
261
}