Completed
Push — master ( 0b0948...d09d59 )
by Nate
11:01 queued 09:52
created

VisitorTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 30
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getVisitor() 0 21 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\craft\hubspot\web\twig\variables;
10
11
use flipbox\craft\hubspot\HubSpot as HubSpotPlugin;
12
use yii\helpers\Json;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 1.0.0
17
 */
18
trait VisitorTrait
19
{
20
    /**
21
     * @noinspection PhpDocMissingThrowsInspection
22
     * @param bool $toQueue
23
     * @param string $connection
24
     * @return array|null
25
     */
26
    public function getVisitor(bool $toQueue = true, string $connection = null)
27
    {
28
        try {
29
            return HubSpotPlugin::getInstance()->getVisitor()->findContact($toQueue, $connection);
30
        } catch (\Exception $e) {
31
            HubSpotPlugin::warning(
32
                sprintf(
33
                    "Exception caught while trying to get HubSpot Visitor. Exception: [%s].",
34
                    (string)Json::encode([
35
                        'Trace' => $e->getTraceAsString(),
36
                        'File' => $e->getFile(),
37
                        'Line' => $e->getLine(),
38
                        'Code' => $e->getCode(),
39
                        'Message' => $e->getMessage()
40
                    ])
41
                ),
42
                __METHOD__
43
            );
44
            return null;
45
        }
46
    }
47
}
48