ModelOption::has()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php namespace Mascame\Artificer\Options;
2
3
use Mascame\Artificer\Model\Model;
4
5
class ModelOption extends Option
6
{
7
8
    public static $key = 'models.';
9
    public static $default_model = 'models.default_model';
10
11
    /**
12
     * @param string $key
13
     * @param null $model
14
     * @return mixed
15
     */
16
    public static function get($key = '', $model = null)
17
    {
18
        return AdminOption::get(self::getPrefix($model) . '.' . $key);
19
    }
20
21
    /**
22
     * @param null $model
23
     * @return mixed
24
     */
25
    public static function all($model = null)
26
    {
27
        return AdminOption::get(self::getPrefix($model));
28
    }
29
30
    /**
31
     * @param string $key
32
     * @param null $model
33
     * @return bool
34
     */
35
    public static function has($key = '', $model = null)
36
    {
37
        return AdminOption::has(self::getPrefix($model) . '.' . $key);
38
    }
39
40
    /**
41
     * @param null $model
42
     * @return mixed
43
     */
44
    public static function model($model = null)
45
    {
46
        return AdminOption::get(self::getPrefix($model));
47
    }
48
49
    /**
50
     * @param $model
51
     * @return null
52
     */
53
    public static function getModel($model)
54
    {
55
        return ($model) ? $model : Model::getCurrent();
56
    }
57
58
    /**
59
     * @param string $key
60
     * @return mixed
61
     */
62
    public static function getDefault($key = '')
63
    {
64
        $key = (isset($key) && !empty($key)) ? '.' . $key : null;
65
66
        return AdminOption::get(self::$default_model . $key);
67
    }
68
69
    /**
70
     * @param null $model
71
     * @return string
72
     */
73
    protected static function getPrefix($model = null)
74
    {
75
        return self::$key . self::getModel($model);
76
    }
77
}