Completed
Push — master ( 43ec3b...86cd9e )
by Lawrence
02:01
created

Cart   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 68.29 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 4
c 5
b 1
f 0
lcom 1
cbo 3
dl 28
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCartData() 10 10 1
A processFindCarts() 18 18 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace ABM\Wasabi;
4
5
use Analog\Analog;
6
use Ratchet\ConnectionInterface;
7
use Ratchet\MessageComponentInterface;
8
9
class Cart extends Prestashop 
10
{
11
12
	 /**
13
     * @param string $data
14
     */
15 View Code Duplication
    private function getCartData($data)
0 ignored issues
show
Bug introduced by
Consider using a different method name as you override a private method of the parent class.

Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.

Loading history...
Duplication introduced by
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...
16
    {
17
        $cart = substr($data, 0, strpos($data, ','));
18
        $cust = substr($data, strpos($data, ',') + 1);
19
20
        Analog::log("Cart & customer variables: $data");
21
        $otherCarts = $this->processFindCarts($cart, $cust);
22
23
        return $otherCarts;
24
    }
25
26
    /**
27
     * @param string $cart
28
     * @param string $cust
29
     */
30 View Code Duplication
    private function processFindCarts($cart, $cust)
0 ignored issues
show
Bug introduced by
Consider using a different method name as you override a private method of the parent class.

Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.

Loading history...
Duplication introduced by
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...
31
    {
32
        $sql = 'SELECT DISTINCT pc.id_cart as id, DATE_FORMAT(pc.date_upd,"%a %D %b %Y, %l:%i %p") as timer from '._DB_PREFIX_.'cart as pc
33
                LEFT JOIN  '._DB_PREFIX_.'cart_product as pcp on pcp.id_cart = pc.id_cart
34
                WHERE pc.id_cart NOT IN (SELECT po.id_cart FROM  '._DB_PREFIX_.'orders as po)
35
                AND pcp.id_product IS NOT NULL
36
                AND pc.id_customer = '.(int) $cust.'
37
                AND pc.id_cart != '.(int) $cart.'
38
                ORDER BY pc.date_upd DESC
39
                LIMIT 10';
40
        if ($results = $this->dbConn->fetchRowMany($sql)) {
41
            foreach ($results as &$row) {
42
                $row['token'] = md5(_COOKIE_KEY_.'recover_cart_'.$row['id']);
43
            }
44
45
            return $results;
46
        }
47
    }
48
49
}