CreatePayloadFromElementEvent::eventName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 13
cp 0
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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\events;
10
11
use craft\base\ElementInterface;
12
use craft\helpers\StringHelper;
13
use yii\base\Event;
14
15
/**
16
 * @param ElementInterface $sender
17
 */
18
class CreatePayloadFromElementEvent extends Event
19
{
20
    /**
21
     * @var array
22
     */
23
    private $payload = [];
24
25
    /**
26
     * @param array $payload
27
     * @return $this
28
     */
29
    public function setPayload(array $payload)
30
    {
31
        $this->payload = $payload;
32
        return $this;
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function getPayload(): array
39
    {
40
        return $this->payload;
41
    }
42
43
    /**
44
     * @param string $object
45
     * @param string|null $action
46
     * @return string
47
     */
48
    public static function eventName(
49
        string $object,
50
        string $action = null
51
    ): string {
52
        $name = array_filter([
53
            'payload',
54
            $object,
55
            $action
56
        ]);
57
58
        return StringHelper::toLowerCase(
59
            StringHelper::toString($name, ':')
60
        );
61
    }
62
}
63