This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of gpupo/netshoes-sdk |
||
5 | * Created by Gilmar Pupo <[email protected]> |
||
6 | * For the information of copyright and license you should read the file |
||
7 | * LICENSE which is distributed with this source code. |
||
8 | * Para a informação dos direitos autorais e de licença você deve ler o arquivo |
||
9 | * LICENSE que é distribuído com este código-fonte. |
||
10 | * Para obtener la información de los derechos de autor y la licencia debe leer |
||
11 | * el archivo LICENSE que se distribuye con el código fuente. |
||
12 | * For more information, see <https://www.gpupo.com/>. |
||
13 | */ |
||
14 | |||
15 | namespace Gpupo\NetshoesSdk\Entity\Order; |
||
16 | |||
17 | use Gpupo\CommonSdk\Entity\EntityInterface; |
||
18 | use Gpupo\CommonSdk\Response; |
||
19 | use Gpupo\CommonSdk\Traits\LoadTrait; |
||
20 | use Gpupo\CommonSdk\Traits\TranslatorManagerTrait; |
||
21 | use Gpupo\NetshoesSdk\Entity\AbstractManager; |
||
22 | use Gpupo\NetshoesSdk\Traits\DateTimeTrait; |
||
23 | |||
24 | final class Manager extends AbstractManager |
||
25 | { |
||
26 | use TranslatorManagerTrait; |
||
27 | use LoadTrait; |
||
28 | use DateTimeTrait; |
||
29 | |||
30 | protected $entity = 'Order'; |
||
31 | |||
32 | /** |
||
33 | * @codeCoverageIgnore |
||
34 | */ |
||
35 | protected function setUp() |
||
36 | { |
||
37 | $this->maps = $this->loadArrayFromFile(__DIR__.'/map/restful.map.php'); |
||
38 | } |
||
39 | |||
40 | 1 | public function factoryDecorator(Order $order, $decoratorName) |
|
41 | { |
||
42 | 1 | $className = __NAMESPACE__.'\\Decorator\\'.$decoratorName; |
|
43 | 1 | $instance = new $className(); |
|
44 | 1 | $instance->setOrder($order); |
|
45 | |||
46 | 1 | return $instance; |
|
47 | } |
||
48 | |||
49 | 1 | protected function resolvePrevious(Order $entity) |
|
50 | { |
||
51 | try { |
||
52 | 1 | $o = $this->findById($entity->getId()); |
|
53 | 1 | if ($o instanceof Order) { |
|
54 | 1 | return $o; |
|
55 | } |
||
56 | } catch (\Exception $o) { |
||
57 | throw new \Exception('Order #'.$entity->getId().' not found on marketplace!'); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | 1 | protected function normalizeShipping(Order $entity, Order $existent) |
|
62 | { |
||
63 | 1 | if (1000 > intval($entity->getShipping()->getShippingCode())) { |
|
64 | 1 | $code = $existent->getShipping()->getShippingCode(); |
|
65 | 1 | $entity->getShipping()->setShippingCode($code); |
|
66 | } |
||
67 | |||
68 | 1 | return $entity; |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 7 | public function update(EntityInterface $entity, EntityInterface $existent = null) |
|
75 | { |
||
76 | 7 | parent::update($entity, $existent); |
|
77 | |||
78 | 7 | $factory204 = function ($message) { |
|
79 | return new Response([ |
||
80 | 'raw' => '{"message":"'.$message.'"}', |
||
81 | 'httpStatusCode' => 204, |
||
82 | ]); |
||
83 | 7 | }; |
|
84 | |||
85 | 7 | if (empty($existent)) { |
|
86 | 7 | $existent = $this->resolvePrevious($entity); |
|
0 ignored issues
–
show
|
|||
87 | } |
||
88 | |||
89 | 7 | if ($entity->getOrderStatus() === $existent->getOrderStatus()) { |
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Gpupo\CommonSdk\Entity\EntityInterface as the method getOrderStatus() does only exist in the following implementations of said interface: Gpupo\NetshoesSdk\Entity\Order\Order .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
90 | $this->log('info', 'Order sem atualização'); |
||
91 | |||
92 | return $factory204('Order status not changed!'); |
||
93 | } |
||
94 | |||
95 | 7 | if ('processing' === $entity->getOrderStatus()) { |
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Gpupo\CommonSdk\Entity\EntityInterface as the method getOrderStatus() does only exist in the following implementations of said interface: Gpupo\NetshoesSdk\Entity\Order\Order .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
96 | return $factory204('Order status not used!'); |
||
97 | } |
||
98 | |||
99 | 7 | $entity = $this->normalizeShipping($entity, $existent); |
|
0 ignored issues
–
show
$entity of type object<Gpupo\CommonSdk\Entity\EntityInterface> is not a sub-type of object<Gpupo\NetshoesSdk\Entity\Order\Order> . It seems like you assume a concrete implementation of the interface Gpupo\CommonSdk\Entity\EntityInterface to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type. ![]() $existent is of type null|object<Gpupo\Common...Entity\EntityInterface> , but the function expects a object<Gpupo\NetshoesSdk\Entity\Order\Order> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
100 | |||
101 | 7 | if (in_array($entity->getOrderStatus(), ['approved', 'canceled', |
|
102 | 7 | 'delivered', 'invoiced', 'shipped', ], true)) { |
|
103 | 6 | $decorator = $this->factoryDecorator($entity, 'Status\\'.ucfirst($entity->getOrderStatus())); |
|
104 | 6 | $json = $decorator->toJson(); |
|
105 | 6 | $mapKey = 'to'.ucfirst($entity->getOrderStatus()); |
|
106 | 6 | $shipping = $entity->getShipping(); |
|
107 | 6 | $code = $shipping->getShippingCode(); |
|
108 | 6 | $shipping->toJson(); |
|
109 | 5 | $map = $this->factoryMap($mapKey, [ |
|
110 | 5 | 'orderNumber' => $entity->getOrderNumber(), |
|
111 | 5 | 'itemId' => $entity->getOrderNumber(), |
|
112 | 5 | 'shippingCode' => $code, |
|
113 | ]); |
||
114 | |||
115 | 5 | return $this->execute($map, $json); |
|
116 | } |
||
117 | |||
118 | 1 | throw new \InvalidArgumentException('Order Status ['.$entity->getOrderStatus().'] não suportado', 1); |
|
119 | } |
||
120 | |||
121 | public function factoryTranslator(array $data = []) |
||
122 | { |
||
123 | $translator = new Translator($data); |
||
124 | |||
125 | return $translator; |
||
126 | } |
||
127 | |||
128 | 1 | public function fetchQueue($offset = 0, $limit = 50, array $parameters = []) |
|
129 | { |
||
130 | 1 | return $this->translatorFetch($offset, $limit, array_merge([ |
|
131 | 1 | 'orderStatus' => 'approved', |
|
132 | 1 | 'orderStartDate' => $this->dateMove('P4D'), |
|
133 | 1 | ], $parameters)); |
|
134 | } |
||
135 | } |
||
136 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.