CrudController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasAction() 0 9 3
A getRefs() 0 4 1
A getClassRefs() 0 4 1
A getBlockReasons() 0 4 1
A getCurrencyTypes() 0 4 1
1
<?php
2
/**
3
 * HiPanel core package
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\base;
12
13
use hipanel\models\Ref;
14
use yii\helpers\Inflector;
15
16
class CrudController extends Controller
17
{
18
    public function hasAction($id, $actions = null): bool
19
    {
20
        if ($actions === null) {
21
            $actions = $this->actions();
22
        }
23
        $method = 'action' . Inflector::id2camel($id);
24
25
        return isset($actions[$id]) || method_exists($this, $method);
26
    }
27
28
    public function getRefs($name, $translate = null, array $options = []): array
29
    {
30
        return Ref::getList($name, $translate, $options);
31
    }
32
33
    public function getClassRefs($type, $translate = null, array $options = []): array
34
    {
35
        return $this->getRefs($type . ',' . static::modelId('_'), $translate, $options);
36
    }
37
38
    public function getBlockReasons(): array
39
    {
40
        return $this->getRefs('type,block', 'hipanel');
41
    }
42
43
    public function getCurrencyTypes(): array
44
    {
45
        return $this->getRefs('type,currency', 'hipanel', ['orderby' => 'no_asc']);
46
    }
47
}
48