Completed
Push — develop ( 78dac2...5cd299 )
by Mohamed
06:27
created

Settings::fields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4286
cc 2
eloc 7
nc 2
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Form;
13
14
use Tinyissue\Model;
15
use Tinyissue\Services\SettingsManager;
16
17
/**
18
 * Settings is a class to defines fields & rules for editing system settings
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 */
22
class Settings extends FormAbstract
23
{
24
    /**
25
     * An instance of project model
26
     *
27
     * @var Model\Settings
28
     */
29
    protected $settings;
30
31
    /**
32
     * @return array
33
     */
34 1
    public function actions()
35
    {
36
        return [
37 1
            'submit' => 'save',
38
        ];
39
    }
40
41
    /**
42
     * @return array
43
     */
44 1
    public function fields()
45
    {
46 1
        $fields = [];
47
48 1
        $settingsManager = app('tinyissue.settings');
49 1
        foreach ($settingsManager as $setting) {
50 1
            $method = camel_case('field_' . $setting->key);
51 1
            $fields[$setting->key] = $this->{$method}($setting);
52
        }
53
54 1
        return $fields;
55
    }
56
57
    /**
58
     * Select enable/disable for public projects
59
     *
60
     * @param Model\Setting $setting
61
     * @return array
62
     */
63 1
    protected function fieldEnablePublicProjects(Model\Setting $setting)
64
    {
65
        return [
66 1
            'type'    => 'select',
67 1
            'label'   => $setting->name,
68 1
            'value'   => $setting->value,
69 1
            'options' => [Model\Setting::ENABLE => trans('tinyissue.enable'), Model\Setting::DISABLE => trans('tinyissue.disable')],
70
        ];
71
    }
72
73
    /**
74
     * @return array
75
     */
76 1
    public function rules()
77
    {
78
        $rules = [
79 1
        ];
80
81 1
        return $rules;
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    public function getRedirectUrl()
88
    {
89
        return 'administration/settings';
90
    }
91
}
92