gabrielbull /
php-waredesk-api
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 | namespace Waredesk\Models\Inventory; |
||
| 4 | |||
| 5 | use DateTime; |
||
| 6 | use JsonSerializable; |
||
| 7 | use Waredesk\Collections\Inventory\Items\Activities; |
||
| 8 | use Waredesk\Collections\Inventory\Items\Attributes; |
||
| 9 | use Waredesk\Collections\Inventory\Items\Codes; |
||
| 10 | use Waredesk\Entity; |
||
| 11 | use Waredesk\ReplaceableEntity; |
||
| 12 | |||
| 13 | class Item implements Entity, ReplaceableEntity, JsonSerializable |
||
| 14 | { |
||
| 15 | private $id; |
||
| 16 | private $warehouse; |
||
| 17 | private $product; |
||
| 18 | private $variant; |
||
| 19 | private $activities; |
||
| 20 | private $attributes; |
||
| 21 | private $in_stock = true; |
||
| 22 | private $note; |
||
| 23 | private $creation; |
||
| 24 | private $modification; |
||
| 25 | |||
| 26 | 3 | public function __construct(array $data = null) |
|
| 27 | { |
||
| 28 | 3 | $this->activities = new Activities(); |
|
| 29 | 3 | $this->attributes = new Attributes(); |
|
| 30 | 3 | $this->reset($data); |
|
| 31 | 3 | } |
|
| 32 | |||
| 33 | public function __clone() |
||
| 34 | { |
||
| 35 | $this->activities = clone $this->activities; |
||
| 36 | $this->attributes = clone $this->attributes; |
||
| 37 | } |
||
| 38 | |||
| 39 | 2 | public function getId(): ? string |
|
| 40 | { |
||
| 41 | 2 | return $this->id; |
|
| 42 | } |
||
| 43 | |||
| 44 | 2 | public function getWarehouse(): ? string |
|
| 45 | { |
||
| 46 | 2 | return $this->warehouse; |
|
| 47 | } |
||
| 48 | |||
| 49 | public function getProduct(): ? string |
||
| 50 | { |
||
| 51 | return $this->product; |
||
| 52 | } |
||
| 53 | |||
| 54 | 2 | public function getVariant(): ? string |
|
| 55 | { |
||
| 56 | 2 | return $this->variant; |
|
| 57 | } |
||
| 58 | |||
| 59 | 2 | public function getActivities(): Activities |
|
| 60 | { |
||
| 61 | 2 | return $this->activities; |
|
| 62 | } |
||
| 63 | |||
| 64 | 2 | public function getAttributes(): Attributes |
|
| 65 | { |
||
| 66 | 2 | return $this->attributes; |
|
| 67 | } |
||
| 68 | |||
| 69 | 2 | public function isInStock(): ? bool |
|
| 70 | { |
||
| 71 | 2 | return $this->in_stock; |
|
| 72 | } |
||
| 73 | |||
| 74 | 2 | public function getNote(): ? string |
|
| 75 | { |
||
| 76 | 2 | return $this->note; |
|
| 77 | } |
||
| 78 | |||
| 79 | public function getCreation(): ? DateTime |
||
| 80 | { |
||
| 81 | return $this->creation; |
||
| 82 | } |
||
| 83 | |||
| 84 | public function getModification(): ? DateTime |
||
| 85 | { |
||
| 86 | return $this->modification; |
||
| 87 | } |
||
| 88 | |||
| 89 | 3 | public function reset(array $data = null) |
|
| 90 | { |
||
| 91 | 3 | if ($data) { |
|
| 92 | 3 | foreach ($data as $key => $value) { |
|
| 93 | switch ($key) { |
||
| 94 | 3 | case 'id': |
|
|
0 ignored issues
–
show
|
|||
| 95 | 3 | $this->id = $value; |
|
| 96 | 3 | break; |
|
| 97 | 3 | case 'warehouse': |
|
| 98 | 3 | $this->warehouse = $value; |
|
| 99 | 3 | break; |
|
| 100 | 3 | case 'product': |
|
| 101 | 3 | $this->product = $value; |
|
| 102 | 3 | break; |
|
| 103 | 3 | case 'variant': |
|
| 104 | 3 | $this->variant = $value; |
|
| 105 | 3 | break; |
|
| 106 | 3 | case 'activities': |
|
| 107 | 3 | $this->activities = $value; |
|
| 108 | 3 | break; |
|
| 109 | 3 | case 'attributes': |
|
| 110 | 3 | $this->attributes = $value; |
|
| 111 | 3 | break; |
|
| 112 | 3 | case 'in_stock': |
|
| 113 | $this->in_stock = $value; |
||
| 114 | break; |
||
| 115 | 3 | case 'note': |
|
| 116 | 3 | $this->note = $value; |
|
| 117 | 3 | break; |
|
| 118 | 3 | case 'creation': |
|
| 119 | 3 | $this->creation = $value; |
|
| 120 | 3 | break; |
|
| 121 | 3 | case 'modification': |
|
| 122 | 3 | $this->modification = $value; |
|
| 123 | 3 | break; |
|
| 124 | } |
||
| 125 | } |
||
| 126 | } |
||
| 127 | 3 | } |
|
| 128 | |||
| 129 | public function setWarehouse(string $warehouse = null) |
||
| 130 | { |
||
| 131 | $this->warehouse = $warehouse; |
||
| 132 | } |
||
| 133 | |||
| 134 | 2 | public function setVariant(string $variant) |
|
| 135 | { |
||
| 136 | 2 | $this->variant = $variant; |
|
| 137 | 2 | } |
|
| 138 | |||
| 139 | public function setIsInStock(string $in_stock) |
||
| 140 | { |
||
| 141 | $this->in_stock = $in_stock; |
||
|
0 ignored issues
–
show
The property
$in_stock was declared of type boolean, but $in_stock is of type string. Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
| 142 | } |
||
| 143 | |||
| 144 | public function setNote(string $note = null) |
||
| 145 | { |
||
| 146 | $this->note = $note; |
||
| 147 | } |
||
| 148 | |||
| 149 | 2 | public function jsonSerialize(): array |
|
| 150 | { |
||
| 151 | $returnValue = [ |
||
| 152 | 2 | 'warehouse' => $this->getWarehouse(), |
|
| 153 | 2 | 'variant' => $this->getVariant(), |
|
| 154 | 2 | 'activities' => $this->getActivities()->jsonSerialize(), |
|
| 155 | 2 | 'attributes' => $this->getAttributes()->jsonSerialize(), |
|
| 156 | 2 | 'in_stock' => $this->isInStock(), |
|
| 157 | 2 | 'note' => $this->getNote(), |
|
| 158 | ]; |
||
| 159 | 2 | if ($this->getId()) { |
|
| 160 | $returnValue = array_merge(['id' => $this->getId()], $returnValue); |
||
| 161 | } |
||
| 162 | 2 | return $returnValue; |
|
| 163 | } |
||
| 164 | } |
||
| 165 |
As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next
break.There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.