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

VisitorTrait::getVisitor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 21
cp 0
rs 9.584
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
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