AbstractController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 32
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A requirePostPutPatchRequest() 0 9 4
A requirePostDeleteRequest() 0 6 3
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