SettingsController::updateSettingsProcess()   A
last analyzed

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;
9
use Flextype\Component\Filesystem\Filesystem;
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
16
class SettingsController
17
{
18
    /**
19
     * Index page
20
     *
21
     * @param Request  $request  PSR7 request
22
     * @param Response $response PSR7 response
23
     */
24
    public function index(/** @scrutinizer ignore-unused */ Request $request, Response $response) : Response
25
    {
26
        return flextype('twig')->render(
0 ignored issues
show
Bug introduced by
The function flextype 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

26
        return /** @scrutinizer ignore-call */ flextype('twig')->render(
Loading history...
27
            $response,
28
            'plugins/admin/templates/system/settings/index.html',
29
            [
30
                '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...
31
                'menu_item' => 'settings',
32
                'links' => [
33
                    'settings' => [
34
                        'link' => flextype('router')->pathFor('admin.settings.index'),
35
                        '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

35
                        'title' => /** @scrutinizer ignore-call */ __('admin_settings'),
Loading history...
36
                        'active' => true
37
                    ],
38
                ],
39
                'buttons'  => [
40
                    'save' => [
41
                        'link'       => 'javascript:;',
42
                        'title'      => __('admin_save'),
43
                        'type' => 'action'
44
                    ],
45
                ],
46
            ]
47
        );
48
    }
49
50
    /**
51
     * Update settings process
52
     *
53
     * @param Request  $request  PSR7 request
54
     * @param Response $response PSR7 response
55
     */
56
    public function updateSettingsProcess(Request $request, Response $response) : Response
57
    {
58
        $post_data = $request->getParsedBody();
59
60
        if (Filesystem::write(PATH['project'] . '/config/flextype/' . '/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...
61
            flextype('flash')->addMessage('success', __('admin_message_settings_saved'));
0 ignored issues
show
Bug introduced by
The function flextype 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

61
            /** @scrutinizer ignore-call */ 
62
            flextype('flash')->addMessage('success', __('admin_message_settings_saved'));
Loading history...
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

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