FinishSetupController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A finishSetupAction() 0 32 2
A getConfigurationPath() 0 3 1
A getParam() 0 6 2
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