Failed Conditions
Pull Request — master (#284)
by Maximo
03:05
created

UserWebhooksController::onConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 12
ccs 0
cts 0
cp 0
crap 2
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Api\Controllers;
6
7
use Canvas\Models\UserWebhooks;
8
use Canvas\Validation;
9
use Exception;
10
use Phalcon\Http\Response;
11
use GuzzleHttp\Client;
12
use Canvas\Webhooks;
13
use Phalcon\Validation\Validator\PresenceOf;
14
15
/**
16
 * Class LanguagesController.
17
 *
18
 * @package Canvas\Api\Controllers
19
 *
20
 * @property Users $userData
21
 * @property Request $request
22
 * @property Config $config
23
 * @property Apps $app
24
 *
25
 */
26
class UserWebhooksController extends BaseController
27
{
28
    /*
29
     * fields we accept to create
30
     *
31
     * @var array
32
     */
33
    protected $createFields = [
34
        'webhooks_id',
35
        'url',
36
        'method',
37
        'format'
38
    ];
39
40
    /*
41
     * fields we accept to create
42
     *
43
     * @var array
44
     */
45
    protected $updateFields = [
46
        'webhooks_id',
47
        'url',
48
        'method',
49
        'format'
50
    ];
51
52
    /**
53
     * set objects.
54
     *
55
     * @return void
56
     */
57
    public function onConstruct()
58
    {
59
        $this->model = new UserWebhooks();
60
        $this->model->users_id = $this->userData->getId();
61
        $this->model->companies_id = $this->userData->currentCompanyId();
62
        $this->model->apps_id = $this->app->getId();
63
        $this->additionalSearchFields = [
64
            ['is_deleted', ':', '0'],
65
            ['apps_id', ':', $this->app->getId()],
66
            ['companies_id', ':', '0|' . $this->userData->currentCompanyId()],
67
        ];
68
    }
69
70
    /**
71
    * Given the weebhook id, we run a test for it.
72
    *
73
    * @param integer $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
74
    * @return Response
75
    */
76
    public function execute(string $name): Response
77
    {
78
        $request = $this->request->getPostData();
79
80
        $validation = new Validation();
81
        $validation->add('module', new PresenceOf(['message' => 'module is required to know what webhook to run']));
82
        $validation->add('data', new PresenceOf(['message' => 'data is required']));
83
        $validation->add('action', new PresenceOf(['message' => 'action is required']));
84
        $validation->validate($request);
85
86
        $systemModule = $request['module'];
87
        $data = $request['data'];
88
        $action = $request['action'];
89
90
        return $this->response(Webhooks::process(
91
            $systemModule,
92
            $data,
93
            $action
94
        ));
95
    }
96
}
97