ProductView   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 53
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A processViews() 0 15 3
1
<?php
2
3
namespace Richdynamix\PersonalisedProducts\Model;
4
5
use \Richdynamix\PersonalisedProducts\Helper\Config;
6
use \Magento\Customer\Model\Session as CustomerSession;
7
use \Richdynamix\PersonalisedProducts\Model\PredictionIO\EventClient\Client;
8
9
/**
10
 * Class ProductView
11
 *
12
 * @category  Richdynamix
13
 * @package   PersonalisedProducts
14
 * @author    Steven Richardson ([email protected]) @mage_gizmo
15
 */
16
class ProductView
17
{
18
    /**
19
     * @var Config
20
     */
21
    private $_config;
22
23
    /**
24
     * @var CustomerSession
25
     */
26
    private $_customerSession;
27
28
    /**
29
     * @var Client
30
     */
31
    private $_eventClient;
32
33
    /**
34
     * ProductView constructor.
35
     * @param Config $config
36
     * @param CustomerSession $customerSession
37
     * @param Client $eventClient
38
     */
39
    public function __construct(
40
        Config $config,
41
        CustomerSession $customerSession,
42
        Client $eventClient
43
    ) {
44
        $this->_config = $config;
45
        $this->_customerSession = $customerSession;
46
        $this->_eventClient = $eventClient;
47
    }
48
49
    /**
50
     * @param $productId
51
     * @return bool|void
52
     */
53
    public function processViews($productId)
54
    {
55
        if (!$this->_config->isEnabled()) {
56
            return false;
57
        }
58
59
        if ($this->_customerSession->isLoggedIn()) {
60
            return $this->_eventClient->saveCustomerViewProduct(
61
                $this->_customerSession->getCustomerId(),
62
                $productId
63
            );
64
        }
65
66
        return false;
67
    }
68
}
69