Passed
Push — master ( c8021a...6e47b6 )
by Nicolaas
03:33
created

CheckConfigsController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 81
c 2
b 0
f 0
dl 0
loc 119
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Title() 0 3 1
A Data() 0 24 5
A index() 0 72 2
1
<?php
2
3
namespace Sunnysideup\ConfigManager\Control;
4
5
use SilverStripe\Dev\BuildTask;
6
use SilverStripe\ORM\DB;
7
use SilverStripe\ORM\ArrayList;
8
use SilverStripe\Control\Controller;
9
use SilverStripe\View\ArrayData;
10
use SilverStripe\View\Requirements;
11
use SilverStripe\Core\Config\Config;
12
use Sunnysideup\ConfigManager\Api\ConfigList;
13
14
use Sunnysideup\TableFilterSort\Api\TableFilterSortAPI;
0 ignored issues
show
Bug introduced by
The type Sunnysideup\TableFilterSort\Api\TableFilterSortAPI was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
class CheckConfigsController extends Controller
17
{
18
    protected $title = 'Check configs';
19
20
    protected $description = 'Runs through all classes and looks for private statics';
21
22
    protected $url_segment = 'checkconfigs';
23
24
    /**
25
     * Defines methods that can be called directly
26
     * @var array
27
     */
28
    private static $allowed_actions = [
1 ignored issue
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
29
        'index' => 'ADMIN'
30
    ];
31
32
    public function Title()
33
    {
34
        return $this->title;
35
    }
36
37
    public function index($request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

37
    public function index(/** @scrutinizer ignore-unused */ $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        if(class_exists(\Sunnysideup\WebpackRequirementsBackend\View\RequirementsBackendForWebpack::class, true)) {
0 ignored issues
show
Bug introduced by
The type Sunnysideup\WebpackRequi...ementsBackendForWebpack was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
            Config::modify()->set(
41
                \Sunnysideup\WebpackRequirementsBackend\View\RequirementsBackendForWebpack::class,
42
                'enabled',
43
                false
44
            );
45
        }
46
        TableFilterSortAPI::include_requirements(
47
            $tableSelector = '.tfs-holder',
48
            $blockArray = [],
49
            $jqueryLocation = 'https://code.jquery.com/jquery-3.4.1.min.js',
50
            $includeInPage = true,
51
            $jsSettings = [
52
                'rowRawData' => $this->Data(),
53
                'scrollToTopAtPageOpening' => true,
54
                'sizeOfFixedHeader' => 0,
55
                'maximumNumberOfFilterOptions' => 20,
56
                'filtersParentPageID' => '',
57
                'favouritesParentPageID' => '',
58
                'visibleRowCount' => 20,
59
                'startWithOpenFilter' => true,
60
                'dataDictionary' => [
61
                    'Type' => [
62
                        'Label' => 'Type',
63
                        'CanFilter' => true,
64
                    ],
65
                    'Vendor' => [
66
                        'Label' => 'Vendor',
67
                        'CanFilter' => true,
68
                    ],
69
                    'Package' => [
70
                        'Label' => 'Package',
71
                        'CanFilter' => true,
72
                    ],
73
                    'ShorterClassName' => [
74
                        'Label' => 'Class',
75
                        'CanFilter' => true,
76
                    ],
77
                    'Property' => [
78
                        'Label' => 'Property',
79
                        'CanFilter' => true,
80
                    ],
81
                    'IsDefault' => [
82
                        'Label' => 'Is Default',
83
                        'CanFilter' => true,
84
                    ],
85
                    'HasDefault' => [
86
                        'Label' => 'Has Default',
87
                        'CanFilter' => false,
88
                    ],
89
                    'HasDefault' => [
90
                        'Label' => 'Has Default',
91
                        'CanFilter' => false,
92
                    ],
93
                    'HasValue' => [
94
                        'Label' => 'Has Value',
95
                        'CanFilter' => true,
96
                    ],
97
                    'Value' => [
98
                        'Label' => 'Value',
99
                        'CanFilter' => false,
100
                    ],
101
                    'Default' => [
102
                        'Label' => 'Default Value',
103
                        'CanFilter' => false,
104
                    ],
105
                ],
106
            ]
107
        );
108
        return $this->renderWith('Includes/CheckConfigsTable');
109
    }
110
111
    public function Data()
112
    {
113
        $list = new ConfigList();
114
        $list = $list->getListOfConfigs();
115
        ksort($list);
116
        $finalArray = [];
117
        $count = 0;
118
        foreach ($list as $values) {
119
            $count++;
120
            $id = 'row'.$count;
121
            $finalArray[$id] = [];
122
            $finalArray[$id]['Vendor'] = $values['Vendor'];
123
            $finalArray[$id]['Package'] = $values['Package'];
124
            $finalArray[$id]['ShorterClassName'] = $values['ShorterClassName'];
125
            $finalArray[$id]['Property'] = $values['Property'];
126
            $finalArray[$id]['Type'] = $values['Type'];
127
            $finalArray[$id]['IsDefault'] = $values['IsDefault'] ? 'yes' : 'no';
128
            $finalArray[$id]['HasDefault'] = $values['HasDefault'] ? 'yes' : 'no';
129
            $finalArray[$id]['HasValue'] = $values['HasValue'] ? 'yes' : 'no';
130
            $finalArray[$id]['Value'] = '<pre>'.print_r($values['Value'], 1).'</pre>';
131
            $finalArray[$id]['Default'] = '<pre>'.print_r($values['Default'], 1).'</pre>';
132
        }
133
134
        return $finalArray;
135
    }
136
137
}
138