FinishSetupController::getConfigurationPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ExpressApi\V1\Rpc\FinishSetup;
4
5
use Zend\Mvc\Controller\AbstractActionController;
6
7
class FinishSetupController extends AbstractActionController {
8
9
    const CLIENT_ID = 'express';
10
11
    public function finishSetupAction() {
12
        $params = $this->bodyParams();
0 ignored issues
show
Bug introduced by
The method bodyParams() does not exist on ExpressApi\V1\Rpc\Finish...p\FinishSetupController. Did you maybe mean params()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
13
        $configDir = $this->getConfigurationPath();
14
        $configFile = $configDir.'local.php';
15
        $response = array(
16
            'success' => false
17
        );
18
        $user = $this->getParam($params, 'user');
19
        $pass = $this->getParam($params, 'pass');
20
        $dbName = $this->getParam($params, 'dbname');
21
        $dbUser = $this->getParam($params, 'dbuser');
22
        $dbPassword = $this->getParam($params, 'dbpassword');
23
        $clientCode = $this->getParam($params, 'client_number');
24
        $apiBaseUrl = $this->getParam($params, 'api_base_url');
25
        $apiVersion = $this->getParam($params, 'api_version');
26
        if(!file_exists($configFile)) {
27
            $replaces = array(
28
                '<%client_number%>' => $clientCode,
29
                '<%api_base_url%>' => $apiBaseUrl,
30
                '<%api_version%>' => $apiVersion,
31
                '<%db_name%>' => $dbName,
32
                '<%user%>' => $user,
33
                '<%pass%>' => $pass,
34
                '<%db_user%>' => $dbUser,
35
                '<%db_password%>' => $dbPassword
36
            );
37
            $generateConfig = new GenerateConfig($configFile, $replaces);
38
            $successGenerateConfig = $generateConfig->generate();
39
            $response['success'] = $successGenerateConfig;
40
        }
41
        return $response;
42
    }
43
44
    private function getConfigurationPath() {
45
        return __DIR__.'/../../../../../../../config/autoload/';
46
    }
47
48
    private function getParam(Array $params, $key) {
49
        if(array_key_exists($key, $params)) {
50
            return $params[$key];
51
        }
52
        return '';
53
    }
54
}
55