Completed
Push — master ( 50f309...1f3d4e )
by Mohamed
06:23
created

Settings   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 7
c 5
b 1
f 0
lcom 1
cbo 2
dl 0
loc 89
ccs 23
cts 23
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRedirectUrl() 0 4 1
A actions() 0 6 1
A fields() 0 12 2
A rules() 0 7 1
A fieldEnablePublicProjects() 0 9 1
A fieldDateFormat() 0 10 1
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
16
/**
17
 * Settings is a class to defines fields & rules for editing system settings.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 */
21
class Settings extends FormAbstract
22
{
23
    /**
24
     * An instance of project model.
25
     *
26
     * @var Model\Settings
27
     */
28
    protected $settings;
29
30
    /**
31
     * @return array
32
     */
33 1
    public function actions()
34
    {
35
        return [
36 1
            'submit' => 'save',
37
        ];
38
    }
39
40
    /**
41
     * @return array
42
     */
43 1
    public function fields()
44
    {
45 1
        $fields = [];
46
47 1
        $settingsManager = app('tinyissue.settings');
48 1
        foreach ($settingsManager as $setting) {
49 1
            $method                = camel_case('field_' . $setting->key);
50 1
            $fields[$setting->key] = $this->{$method}($setting);
51
        }
52
53 1
        return $fields;
54
    }
55
56
    /**
57
     * Select enable/disable for public projects.
58
     *
59
     * @param Model\Setting $setting
60
     *
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
     * Select enable/disable for public projects.
75
     *
76
     * @param Model\Setting $setting
77
     *
78
     * @return array
79
     */
80 1
    protected function fieldDateFormat(Model\Setting $setting)
81
    {
82
        return [
83 1
            'type'        => 'text',
84 1
            'label'       => 'date_format',
85 1
            'value'       => $setting->value,
86 1
            'placeholder' => 'F jS \a\t g:i A',
87 1
            'help'        => 'Format characters can be found --> <a href="http://php.net/manual/en/function.date.php" target="_blank">PHP date</a>',
88
        ];
89
    }
90
91
    /**
92
     * @return array
93
     */
94 1
    public function rules()
95
    {
96
        $rules = [
97 1
        ];
98
99 1
        return $rules;
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function getRedirectUrl()
106
    {
107
        return 'administration/settings';
108
    }
109
}
110