AbstractController::requirePostDeleteRequest()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 2
nop 0
crap 12
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organization\controllers;
10
11
use Craft;
12
use craft\web\Controller;
13
use flipbox\organization\Organization;
14
use yii\web\HttpException;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 *
20
 * @property Organization $module
21
 */
22
abstract class AbstractController extends Controller
23
{
24
25
    /**
26
     * Throws a 400 error if this isn’t a POST, PUT, or PATCH request
27
     *
28
     * @throws HttpException
29
     * @return void
30
     */
31
    public function requirePostPutPatchRequest()
32
    {
33
        if (!(Craft::$app->getRequest()->getIsPost() ||
34
            !Craft::$app->getRequest()->getIsPatch() ||
35
            !Craft::$app->getRequest()->getIsPut())
36
        ) {
37
            throw new HttpException(400);
38
        }
39
    }
40
41
    /**
42
     * Throws a 400 error if this isn’t a POST or DELETE request
43
     *
44
     * @throws HttpException
45
     * @return void
46
     */
47
    public function requirePostDeleteRequest()
48
    {
49
        if (!(Craft::$app->getRequest()->getIsPost() || !Craft::$app->getRequest()->getIsDelete())) {
50
            throw new HttpException(400);
51
        }
52
    }
53
}
54