1 | <?php |
||
17 | class Cart extends Component |
||
18 | { |
||
19 | /** |
||
20 | * @var string CartItemInterface class name |
||
21 | */ |
||
22 | const ITEM_PRODUCT = '\yii2mod\cart\models\CartItemInterface'; |
||
23 | |||
24 | /** |
||
25 | * Override this to provide custom (e.g. database) storage for cart data |
||
26 | * |
||
27 | * @var string|\yii2mod\cart\storage\StorageInterface |
||
28 | */ |
||
29 | public $storageClass = '\yii2mod\cart\storage\SessionStorage'; |
||
30 | |||
31 | /** |
||
32 | * @var array cart items |
||
33 | */ |
||
34 | protected $items; |
||
35 | |||
36 | /** |
||
37 | * @var StorageInterface |
||
38 | */ |
||
39 | private $_storage; |
||
40 | |||
41 | /** |
||
42 | * @inheritdoc |
||
43 | */ |
||
44 | public function init() |
||
50 | |||
51 | /** |
||
52 | * Assigns cart to logged in user |
||
53 | * |
||
54 | * @param string |
||
55 | * @param string |
||
56 | */ |
||
57 | public function reassign($sessionId, $userId) |
||
67 | |||
68 | /** |
||
69 | * Delete all items from the cart |
||
70 | * |
||
71 | * @param bool $save |
||
72 | * |
||
73 | * @return $this |
||
74 | */ |
||
75 | public function clear($save = true): self |
||
82 | |||
83 | /** |
||
84 | * @return StorageInterface |
||
85 | */ |
||
86 | public function getStorage(): StorageInterface |
||
90 | |||
91 | /** |
||
92 | * @param mixed $storage |
||
93 | */ |
||
94 | public function setStorage($storage) |
||
98 | |||
99 | /** |
||
100 | * Add an item to the cart |
||
101 | * |
||
102 | * @param models\CartItemInterface $element |
||
103 | * @param bool $save |
||
104 | * |
||
105 | * @return $this |
||
106 | */ |
||
107 | public function add(CartItemInterface $element, $save = true): self |
||
114 | |||
115 | /** |
||
116 | * @param \yii2mod\cart\models\CartItemInterface $item |
||
117 | */ |
||
118 | protected function addItem(CartItemInterface $item) |
||
123 | |||
124 | /** |
||
125 | * Removes an item from the cart |
||
126 | * |
||
127 | * @param string $uniqueId |
||
128 | * @param bool $save |
||
129 | * |
||
130 | * @throws \yii\base\InvalidParamException |
||
131 | * |
||
132 | * @return $this |
||
133 | */ |
||
134 | public function remove($uniqueId, $save = true): self |
||
146 | |||
147 | /** |
||
148 | * @param string $itemType If specified, only items of that type will be counted |
||
149 | * |
||
150 | * @return int |
||
151 | */ |
||
152 | public function getCount($itemType = null): int |
||
156 | |||
157 | /** |
||
158 | * Returns all items of a given type from the cart |
||
159 | * |
||
160 | * @param string $itemType One of self::ITEM_ constants |
||
161 | * |
||
162 | * @return CartItemInterface[] |
||
163 | */ |
||
164 | public function getItems($itemType = null): array |
||
180 | |||
181 | /** |
||
182 | * Finds all items of type $itemType, sums the values of $attribute of all models and returns the sum. |
||
183 | * |
||
184 | * @param string $attribute |
||
185 | * @param string|null $itemType |
||
186 | * |
||
187 | * @return int |
||
188 | */ |
||
189 | public function getAttributeTotal($attribute, $itemType = null): int |
||
198 | } |
||
199 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.