Completed
Push — master ( 80d79a...85157a )
by Lawrence
01:54
created

Cart   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCartData() 0 8 1
A processFindCarts() 0 20 3
1
<?php
2
3
namespace ABM\Wasabi;
4
5
use Ratchet\MessageComponentInterface;
6
use Ratchet\ConnectionInterface;
7
use Analog\Analog;
8
9
class Cart 
10
{
11
12
    /**
13
     * @param string $data
14
     */
15
    public function getCartData($data) {
16
        $cart = substr($data, 0, strpos($data, ','));
17
        $cust = substr($data, strpos($data, ',') + 1);
18
19
        Analog::log("Cart & customer variables: $data");
20
        $otherCarts = $this->processFindCarts($cart, $cust);
21
        return $otherCarts;
22
    }
23
24
/**
25
 * @param string $cart
26
 * @param string $cust
27
 */
28
    private function processFindCarts($cart, $cust)
29
    {
30
        $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
31
                LEFT JOIN  '._DB_PREFIX_.'cart_product as pcp on pcp.id_cart = pc.id_cart
32
                WHERE pc.id_cart NOT IN (SELECT po.id_cart FROM  '._DB_PREFIX_.'orders as po)
33
                AND pcp.id_product IS NOT NULL
34
                AND pc.id_customer = '.(int) $cust.'
35
                AND pc.id_cart != '.(int) $cart.'
36
                ORDER BY pc.date_upd DESC
37
                LIMIT 10';
38
        if ($results = $this->dbConn->fetchRowMany($sql)) {
0 ignored issues
show
Bug introduced by
The property dbConn does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
39
            foreach ($results as &$row) {
40
                $row['token'] = md5(_COOKIE_KEY_.'recover_cart_'.$row['id']);
41
            }
42
43
            return $results;
44
        } else {
45
            return;
46
        }
47
    }
48
49
}