Passed
Push — dev ( e66ec2...f81248 )
by Sergey
12:00 queued 11s
created

SettingsController::updateSettingsProcess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Flextype\Plugin\Admin\Controllers;
6
7
use DateTime;
8
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...
9
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...
10
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...
11
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...
12
use function array_merge;
13
use function explode;
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 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...
16
17
/**
18
 * @property View $view
19
 * @property Router $router
20
 * @property Cache $cache
21
 * @property Entries $entries
22
 * @property Plugins $plugins
23
 * @property Registry $registry
24
 * @property Flash $flash
25
 */
26
class SettingsController 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/admin/templates/system/settings/index.html',
39
            [
40
                'data' => Filesystem::read(PATH['project'] . '/config/flextype/settings.yaml'),
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\Admin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
41
                'menu_item' => 'settings',
42
                'links' => [
43
                    'settings' => [
44
                        'link' => $this->router->pathFor('admin.settings.index'),
45
                        'title' => __('admin_settings'),
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 */ __('admin_settings'),
Loading history...
46
                        'active' => true
47
                    ],
48
                ],
49
                'buttons'  => [
50
                    'save' => [
51
                        'link'       => 'javascript:;',
52
                        'title'      => __('admin_save'),
53
                        'type' => 'action'
54
                    ],
55
                ],
56
            ]
57
        );
58
    }
59
60
    /**
61
     * Update settings process
62
     *
63
     * @param Request  $request  PSR7 request
64
     * @param Response $response PSR7 response
65
     */
66
    public function updateSettingsProcess(Request $request, Response $response) : Response
67
    {
68
        $post_data = $request->getParsedBody();
69
70
        if (Filesystem::write(PATH['project'] . '/config/' . '/settings.yaml', $post_data['data'])) {
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\Admin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
71
            $this->flash->addMessage('success', __('admin_message_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

71
            $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('admin_message_settings_saved'));
Loading history...
72
        } else {
73
            $this->flash->addMessage('error', __('admin_message_settings_was_not_saved'));
74
        }
75
76
        return $response->withRedirect($this->router->pathFor('admin.settings.index'));
77
    }
78
79
    /**
80
     * Return date formats allowed
81
     *
82
     * @return array
83
     */
84
    public function dateFormats() : array
85
    {
86
        $now = new DateTime();
87
88
        return [
89
            'd-m-Y H:i' => $now->format('d-m-Y H:i'),
90
            'Y-m-d H:i' => $now->format('Y-m-d H:i'),
91
            'm/d/Y h:i a' => $now->format('m/d/Y h:i a'),
92
            'H:i d-m-Y' => $now->format('H:i d-m-Y'),
93
            'h:i a m/d/Y' => $now->format('h:i a m/d/Y'),
94
        ];
95
    }
96
97
    /**
98
     * Return display date formats allowed
99
     *
100
     * @return array
101
     */
102
    public function displayDateFormats() : array
103
    {
104
        $now = new DateTime();
105
106
        return [
107
            'F jS \\a\\t g:ia' => $now->format('F jS \\a\\t g:ia'),
108
            'l jS \\of F g:i A' => $now->format('l jS \\of F g:i A'),
109
            'D, d M Y G:i:s' => $now->format('m/d/Y h:i a'),
110
            'd-m-y G:i' => $now->format('d-m-y G:i'),
111
            'jS M Y' => $now->format('jS M Y'),
112
        ];
113
    }
114
}
115