Passed
Push — master ( c9364f...8e14d3 )
by Sergey
16:34 queued 12s
created

ThemesController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 166
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 70
dl 0
loc 166
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A activateProcess() 0 17 1
A index() 0 20 1
A settingsProcess() 0 16 2
A information() 0 27 1
A settings() 0 34 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Flextype\Plugin\ThemesAdmin\Controllers;
6
7
use Flextype\Component\Arrays\Arrays;
0 ignored issues
show
Bug introduced by
The type Flextype\Component\Arrays\Arrays 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...
8
use Flextype\Component\Filesystem\Filesystem;
0 ignored issues
show
Bug introduced by
The type Flextype\Component\Filesystem\Filesystem 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...
9
use Psr\Http\Message\ResponseInterface as Response;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ResponseInterface 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...
10
use Psr\Http\Message\ServerRequestInterface as Request;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ServerRequestInterface 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...
11
use function array_merge;
12
use function array_replace_recursive;
13
use function count;
14
use function Flextype\Component\I18n\__;
0 ignored issues
show
introduced by
The function Flextype\Component\I18n\__ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
15
use function is_array;
16
use function trim;
17
18
use Flextype\App\Foundation\Container;
0 ignored issues
show
Bug introduced by
The type Flextype\App\Foundation\Container 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...
19
20
/**
21
 * @property twig $twig
22
 * @property Router $router
23
 * @property Cache $cache
24
 * @property Themes $themes
25
 */
26
class ThemesController extends Container
27
{
28
    /**
29
     * Index page
30
     *
31
     * @param Request  $request  PSR7 request
32
     * @param Response $response PSR7 response
33
     */
34
    public function index(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response
35
    {
36
        return $this->twig->render(
37
            $response,
38
            'plugins/themes-admin/templates/extends/themes/index.html',
39
            [
40
                'menu_item' => 'themes',
41
                'themes_list' => $this->registry->get('themes'),
42
                'links' =>  [
43
                    'themes' => [
44
                        'link' => $this->router->pathFor('admin.themes.index'),
45
                        'title' => __('themes_admin_themes'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

45
                        'title' => /** @scrutinizer ignore-call */ __('themes_admin_themes'),
Loading history...
46
                        'active' => true
47
                    ],
48
                ],
49
                'buttons' => [
50
                    'themes_get_more' => [
51
                        'link' => 'https://github.com/flextype/themes',
52
                        'title' => __('themes_admin_get_more_themes'),
53
                        'target' => '_blank',
54
                    ],
55
                ],
56
            ]
57
        );
58
    }
59
60
    /**
61
     * Сhange theme status process
62
     *
63
     * @param Request  $request  PSR7 request
64
     * @param Response $response PSR7 response
65
     */
66
    public function activateProcess(Request $request, Response $response) : Response
67
    {
68
        // Get data from the request
69
        $post_data = $request->getParsedBody();
70
71
        $custom_settings_file = PATH['project'] . '/config/plugins/site/settings.yaml';
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\ThemesAdmin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
72
        $custom_settings_file_data = $this->yaml->decode(Filesystem::read($custom_settings_file));
73
74
        Arrays::set($custom_settings_file_data, 'theme', $post_data['theme-id']);
75
76
        Filesystem::write($custom_settings_file, $this->yaml->encode($custom_settings_file_data));
77
78
        // clear cache
79
        $this->cache->purge('doctrine');
80
81
        // Redirect to themes index page
82
        return $response->withRedirect($this->router->pathFor('admin.themes.index'));
83
    }
84
85
    /**
86
     * Theme information
87
     *
88
     * @param Request  $request  PSR7 request
89
     * @param Response $response PSR7 response
90
     */
91
    public function information(Request $request, Response $response) : Response
92
    {
93
        // Get Theme ID
94
        $id = $request->getQueryParams()['id'];
95
96
        // Set theme custom manifest content
97
        $custom_theme_manifest_file = PATH['project'] . '/themes/' . $id . '/theme.yaml';
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\ThemesAdmin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
98
99
        // Get theme custom manifest content
100
        $custom_theme_manifest_file_content = Filesystem::read($custom_theme_manifest_file);
101
102
        return $this->twig->render(
103
            $response,
104
            'plugins/themes-admin/templates/extends/themes/information.html',
105
            [
106
                'menu_item' => 'themes',
107
                'id' => $id,
108
                'theme_manifest' => $this->yaml->decode($custom_theme_manifest_file_content),
109
                'links' =>  [
110
                    'themes' => [
111
                        'link' => $this->router->pathFor('admin.themes.index'),
112
                        'title' => __('themes_admin_themes'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

112
                        'title' => /** @scrutinizer ignore-call */ __('themes_admin_themes'),
Loading history...
113
                    ],
114
                    'themes_information' => [
115
                        'link' => $this->router->pathFor('admin.themes.information') . '?id=' . $request->getQueryParams()['id'],
116
                        'title' => __('admin_information'),
117
                        'active' => true
118
                    ],
119
                ],
120
            ]
121
        );
122
    }
123
124
    /**
125
     * Theme settings
126
     *
127
     * @param Request  $request  PSR7 request
128
     * @param Response $response PSR7 response
129
     */
130
    public function settings(Request $request, Response $response) : Response
131
    {
132
        // Get Theme ID
133
        $id = $request->getQueryParams()['id'];
134
135
        // Set theme config
136
        $custom_theme_settings_file = PATH['project'] . '/config/themes/' . $id . '/settings.yaml';
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\ThemesAdmin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
137
138
        // Get theme settings content
139
        $custom_theme_settings_file_content = Filesystem::read($custom_theme_settings_file);
140
141
        return $this->twig->render(
142
            $response,
143
            'plugins/themes-admin/templates/extends/themes/settings.html',
144
            [
145
                'menu_item' => 'themes',
146
                'id' => $id,
147
                'theme_settings' => $custom_theme_settings_file_content,
148
                'links' =>  [
149
                    'themes' => [
150
                        'link' => $this->router->pathFor('admin.themes.index'),
151
                        'title' => __('themes_admin_themes'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

151
                        'title' => /** @scrutinizer ignore-call */ __('themes_admin_themes'),
Loading history...
152
                    ],
153
                    'themes_settings' => [
154
                        'link' => $this->router->pathFor('admin.themes.settings') . '?id=' . $request->getQueryParams()['id'],
155
                        'title' => __('admin_settings'),
156
                        'active' => true
157
                    ],
158
                ],
159
                'buttons' => [
160
                    'save_theme_settings' => [
161
                        'link' => 'javascript:;',
162
                        'title' => __('admin_save'),
163
                        'type' => 'action',
164
                    ],
165
                ],
166
            ]
167
        );
168
    }
169
170
    /**
171
     * Theme settings process
172
     *
173
     * @param Request  $request  PSR7 request
174
     * @param Response $response PSR7 response
175
     */
176
    public function settingsProcess(Request $request, Response $response) : Response
177
    {
178
        $post_data = $request->getParsedBody();
179
180
        $id   = $post_data['id'];
181
        $data = $post_data['data'];
182
183
        $custom_theme_settings_file = PATH['project'] . '/config/themes/' . $id . '/settings.yaml';
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\ThemesAdmin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
184
185
        if (Filesystem::write($custom_theme_settings_file, $data)) {
186
            $this->flash->addMessage('success', __('themes_admin_message_theme_settings_saved'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

186
            $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('themes_admin_message_theme_settings_saved'));
Loading history...
187
        } else {
188
            $this->flash->addMessage('error', __('themes_admin_message_theme_settings_not_saved'));
189
        }
190
191
        return $response->withRedirect($this->router->pathFor('admin.themes.settings') . '?id=' . $id);
192
    }
193
}
194