Process::performAction()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 15
cp 0
rs 9.7
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 12
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/force/license
6
 * @link       https://www.flipboxfactory.com/software/force/
7
 */
8
9
namespace flipbox\craft\salesforce\actions\webhooks;
10
11
use Craft;
12
use flipbox\craft\ember\actions\ManageTrait;
13
use flipbox\craft\salesforce\events\ReceiveWebhookEvent;
14
use yii\base\Action;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class Process extends Action
21
{
22
    use ManageTrait;
23
24
    const EVENT_RECEIVE_WEBHOOK = 'receiveWebhook';
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public $statusCodeSuccess = 201;
30
31
    /**
32
     * @return mixed
33
     * @throws \yii\base\InvalidConfigException
34
     * @throws \yii\web\HttpException
35
     */
36
    public function run()
37
    {
38
        return $this->runInternal(
39
            Craft::$app->getRequest()->getBodyParams()
40
        );
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    protected function performAction(array $data = []): bool
47
    {
48
        if (!$data) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
49
            $this->handleFailResponse("No data.");
50
        }
51
52
        if ($this->hasEventHandlers(self::EVENT_RECEIVE_WEBHOOK)) {
53
            $this->trigger(
54
                self::EVENT_RECEIVE_WEBHOOK,
55
                new ReceiveWebhookEvent([
56
                    'data' => $data
57
                ])
58
            );
59
        }
60
61
        $this->handleSuccessResponse(null);
62
    }
63
}
64