Test Failed
Push — main ( a8a1f8...d105a1 )
by Rafael
11:47
created

EditConfig::setView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (C) 2022-2023  Rafael San José Tovar   <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace Alxarafe\Controllers;
20
21
use Alxarafe\Core\Base\BasicController;
22
use Alxarafe\Core\Base\View;
23
use Alxarafe\Core\Singletons\Config;
24
use Alxarafe\Views\ConfigView;
25
use DebugBar\DebugBarException;
26
27
/**
28
 * Controller for editing database and skin settings
29
 *
30
 * @package Alxarafe\Controllers
31
 */
32
class EditConfig extends BasicController
33
{
34
    /**
35
     * Save the form changes in the configuration file
36
     *
37
     * @return bool
38
     */
39
    public function doSave(): bool
40
    {
41
        $config = Config::getInstance();
0 ignored issues
show
Bug introduced by
The method getInstance() does not exist on Alxarafe\Core\Singletons\Config. ( Ignorable by Annotation )

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

41
        /** @scrutinizer ignore-call */ 
42
        $config = Config::getInstance();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
        $config->setVar('constants', 'boolean', 'DEBUG', isset($_POST['debug']));
43
        $config->setVar('translator', 'main', 'language', $_POST['language'] ?? 'en');
44
        $config->setVar('templaterender', 'main', 'skin', $_POST['skin'] ?? 'default');
45
        $config->setVar('database', 'main', 'dbEngineName', $_POST['dbEngineName'] ?? '');
46
        $config->setVar('database', 'main', 'dbUser', $_POST['dbUser'] ?? '');
47
        $config->setVar('database', 'main', 'dbPass', $_POST['dbPass'] ?? '');
48
        $config->setVar('database', 'main', 'dbName', $_POST['dbName'] ?? '');
49
        $config->setVar('database', 'main', 'dbHost', $_POST['dbHost'] ?? '');
50
        $config->setVar('database', 'main', 'dbPort', $_POST['dbPort'] ?? '');
51
        $config->setVar('database', 'main', 'dbPrefix', $_POST['dbPrefix'] ?? '');
52
53
        $result = $config->connectToDatabase();
54
        if (!$result) {
55
            $this->flashMessages->setError('database_not_found', 'next');
0 ignored issues
show
Bug Best Practice introduced by
The property flashMessages does not exist on Alxarafe\Controllers\EditConfig. Did you maybe forget to declare it?
Loading history...
56
        }
57
58
        $result = $config->saveConfigFile();
59
        if ($result) {
60
            $this->flashMessages->setSuccess('saved', 'next');
61
            header('location: ' . self::url('Main', 'EditConfig'));
62
            die();
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
63
        }
64
65
        return $result;
66
    }
67
68
    /**
69
     * @throws DebugBarException
70
     */
71
    public function setView(): View
72
    {
73
        return new ConfigView($this);
74
    }
75
}
76