Complex classes like Cart often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Cart, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 44 | class Cart extends \Model { | 
            ||
| 45 | |||
| 46 | public static $objectName = 'Корзины';  | 
            ||
| 47 | |||
| 48 |     public static function indexes() { | 
            ||
| 71 | |||
| 72 |     public static function relations() { | 
            ||
| 133 | |||
| 134 |     public function beforeDelete() { | 
            ||
| 148 | |||
| 149 | public static $labels = [  | 
            ||
| 150 | 'user_id' => 'Пользователь',  | 
            ||
| 151 | 'cart_status_id' => 'Статус',  | 
            ||
| 152 | 'delivery_id' => 'Доставка',  | 
            ||
| 153 | 'comment' => 'Комментарий',  | 
            ||
| 154 | 'bonus_used' => 'Выгодные рубли',  | 
            ||
| 155 | 'complete_data' => 'Время заказа',  | 
            ||
| 156 | 'info' => 'Информация',  | 
            ||
| 157 | 'items' => 'Товары',  | 
            ||
| 158 | 'paytype_id' => 'Способ оплаты',  | 
            ||
| 159 | 'payed' => 'Оплачен',  | 
            ||
| 160 | 'exported' => 'Выгружено',  | 
            ||
| 161 | 'warehouse_block' => 'Блокировка товаров',  | 
            ||
| 162 | 'extra' => 'Доп.',  | 
            ||
| 163 | 'card_item_id' => 'Дисконтная карта',  | 
            ||
| 164 | 'info' => 'Информация',  | 
            ||
| 165 | 'contacts' => 'Информация',  | 
            ||
| 166 | 'pay' => 'Счета',  | 
            ||
| 167 | 'sums' => 'Суммы',  | 
            ||
| 168 | 'deliveryInfo' => 'Для доставки',  | 
            ||
| 169 | 'discount' => 'Скидки',  | 
            ||
| 170 | ];  | 
            ||
| 171 | public static $cols = [  | 
            ||
| 172 | //Основные параметры  | 
            ||
| 173 | 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'],  | 
            ||
| 174 | 'cart_status_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'status'],  | 
            ||
| 175 | 'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'],  | 
            ||
| 176 | 'paytype_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'payType'],  | 
            ||
| 177 | 'card_item_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'card'],  | 
            ||
| 178 | 'warehouse_block' => ['type' => 'bool'],  | 
            ||
| 179 | 'payed' => ['type' => 'bool'],  | 
            ||
| 180 | 'comment' => ['type' => 'textarea'],  | 
            ||
| 181 | //Системные  | 
            ||
| 182 | 'exported' => ['type' => 'bool'],  | 
            ||
| 183 | 'complete_data' => ['type' => 'dateTime', 'null' => true, 'emptyValue' => null],  | 
            ||
| 184 | 'date_status' => ['type' => 'dateTime', 'null' => true, 'emptyValue' => null],  | 
            ||
| 185 | 'date_last_activ' => ['type' => 'dateTime', 'null' => true, 'emptyValue' => null],  | 
            ||
| 186 | 'date_create' => ['type' => 'dateTime'],  | 
            ||
| 187 | //Виджеты  | 
            ||
| 188 | 'sums' => [  | 
            ||
| 189 | 'type' => 'void',  | 
            ||
| 190 | 'view' => [  | 
            ||
| 191 | 'type' => 'widget',  | 
            ||
| 192 | 'widget' => 'Ecommerce\adminSums',  | 
            ||
| 193 | ],  | 
            ||
| 194 | ],  | 
            ||
| 195 | 'contacts' => [  | 
            ||
| 196 | 'type' => 'void',  | 
            ||
| 197 | 'view' => [  | 
            ||
| 198 | 'type' => 'widget',  | 
            ||
| 199 | 'widget' => 'Ecommerce\admin/contacts',  | 
            ||
| 200 | ],  | 
            ||
| 201 | ],  | 
            ||
| 202 | //Менеджеры  | 
            ||
| 203 | 'extra' => ['type' => 'dataManager', 'relation' => 'extras'],  | 
            ||
| 204 | 'pay' => ['type' => 'dataManager', 'relation' => 'pays'],  | 
            ||
| 205 | 'items' => ['type' => 'dataManager', 'relation' => 'cartItems'],  | 
            ||
| 206 | 'info' => ['type' => 'dataManager', 'relation' => 'infos'],  | 
            ||
| 207 | 'deliveryInfo' => ['type' => 'dataManager', 'relation' => 'deliveryInfos'],  | 
            ||
| 208 | 'discount' => ['type' => 'dataManager', 'relation' => 'discounts'],  | 
            ||
| 209 | ];  | 
            ||
| 210 | public static $dataManagers = [  | 
            ||
| 211 | 'manager' => [  | 
            ||
| 212 | 'cols' => [  | 
            ||
| 213 | 'contacts',  | 
            ||
| 214 | 'items',  | 
            ||
| 215 | 'extra',  | 
            ||
| 216 | 'discount',  | 
            ||
| 217 | 'sums',  | 
            ||
| 218 | 'cart_status_id',  | 
            ||
| 219 | 'delivery_id',  | 
            ||
| 220 | 'deliveryInfo',  | 
            ||
| 221 | 'payed',  | 
            ||
| 222 | 'pay',  | 
            ||
| 223 | 'complete_data',  | 
            ||
| 224 | ],  | 
            ||
| 225 | 'sortable' => [  | 
            ||
| 226 | 'cart_status_id',  | 
            ||
| 227 | 'delivery_id',  | 
            ||
| 228 | 'payed',  | 
            ||
| 229 | 'complete_data',  | 
            ||
| 230 | ],  | 
            ||
| 231 | 'filters' => [  | 
            ||
| 232 | 'cart_status_id',  | 
            ||
| 233 | 'delivery_id',  | 
            ||
| 234 | 'payed',  | 
            ||
| 235 | 'complete_data',  | 
            ||
| 236 | ],  | 
            ||
| 237 | 'preSort' => [  | 
            ||
| 238 | 'complete_data' => 'desc'  | 
            ||
| 239 | ],  | 
            ||
| 240 | 'actions' => [  | 
            ||
| 241 | 'Ecommerce\CloseCartBtn', 'Open', 'Edit', 'Delete'  | 
            ||
| 242 | ]  | 
            ||
| 243 | ]  | 
            ||
| 244 | ];  | 
            ||
| 245 | |||
| 246 |     public static function itemName($item) { | 
            ||
| 249 | |||
| 250 | public static $forms = [  | 
            ||
| 251 | 'manager' => [  | 
            ||
| 252 | 'inputs' => [  | 
            ||
| 253 | 'userSearch' => [  | 
            ||
| 254 | 'type' => 'search',  | 
            ||
| 255 | 'source' => 'relation',  | 
            ||
| 256 | 'relation' => 'user',  | 
            ||
| 257 | 'label' => 'Покупатель',  | 
            ||
| 258 | 'cols' => [  | 
            ||
| 259 | 'info:first_name',  | 
            ||
| 260 | 'info:last_name',  | 
            ||
| 261 | 'info:middle_name',  | 
            ||
| 262 | 'mail'  | 
            ||
| 263 | ],  | 
            ||
| 264 | 'col' => 'user_id',  | 
            ||
| 265 | 'required' => true,  | 
            ||
| 266 | 'showCol' => [  | 
            ||
| 267 | 'type' => 'staticMethod',  | 
            ||
| 268 | 'class' => 'Ecommerce\Cart',  | 
            ||
| 269 | 'method' => 'itemName',  | 
            ||
| 270 | ],  | 
            ||
| 271 | ],  | 
            ||
| 272 | 'cardSearch' => [  | 
            ||
| 273 | 'type' => 'search',  | 
            ||
| 274 | 'source' => 'relation',  | 
            ||
| 275 | 'relation' => 'card',  | 
            ||
| 276 | 'label' => 'Дисконтная карта',  | 
            ||
| 277 | 'cols' => [  | 
            ||
| 278 | 'code',  | 
            ||
| 279 | 'user:info:first_name',  | 
            ||
| 280 | 'user:info:last_name',  | 
            ||
| 281 | 'user:info:middle_name',  | 
            ||
| 282 | 'user:mail'  | 
            ||
| 283 | ],  | 
            ||
| 284 | 'col' => 'card_item_id',  | 
            ||
| 285 | ],  | 
            ||
| 286 | ],  | 
            ||
| 287 | 'map' => [  | 
            ||
| 288 | ['userSearch', 'cart_status_id'],  | 
            ||
| 289 | ['paytype_id', 'delivery_id'],  | 
            ||
| 290 | ['cardSearch', 'comment'],  | 
            ||
| 291 | ['warehouse_block', 'complete_data'],  | 
            ||
| 292 | ['payed'],  | 
            ||
| 293 | ['items'],  | 
            ||
| 294 | ['extra'],  | 
            ||
| 295 | ['pay'],  | 
            ||
| 296 | ['info'],  | 
            ||
| 297 | ['deliveryInfo']  | 
            ||
| 298 | ]  | 
            ||
| 299 | ],  | 
            ||
| 300 | ];  | 
            ||
| 301 | |||
| 302 |     public function checkStage() { | 
            ||
| 331 | |||
| 332 |     public function needDelivery() { | 
            ||
| 340 | |||
| 341 |     public function deliverySum() { | 
            ||
| 369 | |||
| 370 |     public function hasDiscount() { | 
            ||
| 373 | |||
| 374 |     public function discountSum() { | 
            ||
| 381 | |||
| 382 |     public function finalSum() { | 
            ||
| 388 | |||
| 389 |     public function itemsSum() { | 
            ||
| 400 | |||
| 401 |     public function checkPrices() { | 
            ||
| 414 | |||
| 415 |     public function addItem($offer_price_id, $count = 1, $final_price = 0) { | 
            ||
| 435 | |||
| 436 |     public function calc($save = true) { | 
            ||
| 441 | |||
| 442 | }  | 
            ||
| 443 | 
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.